Kaynağa Gözat

[PROMOTE] Zend_Serializer

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20225 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 16 yıl önce
ebeveyn
işleme
5c801df055
29 değiştirilmiş dosya ile 4716 ekleme ve 0 silme
  1. 17 0
      documentation/manual/en/manual.xml.in
  2. 446 0
      documentation/manual/en/module_specs/Zend_Serializer-Adapter.xml
  3. 101 0
      documentation/manual/en/module_specs/Zend_Serializer-Introduction.xml
  4. 164 0
      library/Zend/Serializer.php
  5. 112 0
      library/Zend/Serializer/Adapter/AdapterAbstract.php
  6. 92 0
      library/Zend/Serializer/Adapter/AdapterInterface.php
  7. 88 0
      library/Zend/Serializer/Adapter/Amf0.php
  8. 87 0
      library/Zend/Serializer/Adapter/Amf3.php
  9. 98 0
      library/Zend/Serializer/Adapter/Igbinary.php
  10. 93 0
      library/Zend/Serializer/Adapter/Json.php
  11. 67 0
      library/Zend/Serializer/Adapter/PhpCode.php
  12. 94 0
      library/Zend/Serializer/Adapter/PhpSerialize.php
  13. 1494 0
      library/Zend/Serializer/Adapter/PythonPickle.php
  14. 118 0
      library/Zend/Serializer/Adapter/Wddx.php
  15. 33 0
      library/Zend/Serializer/Exception.php
  16. 2 0
      tests/Zend/AllTests.php
  17. 77 0
      tests/Zend/Serializer/Adapter/AllTests.php
  18. 58 0
      tests/Zend/Serializer/Adapter/Amf0Test.php
  19. 58 0
      tests/Zend/Serializer/Adapter/Amf3Test.php
  20. 120 0
      tests/Zend/Serializer/Adapter/IgbinaryTest.php
  21. 130 0
      tests/Zend/Serializer/Adapter/JsonTest.php
  22. 122 0
      tests/Zend/Serializer/Adapter/PhpCodeTest.php
  23. 120 0
      tests/Zend/Serializer/Adapter/PhpSerializeTest.php
  24. 146 0
      tests/Zend/Serializer/Adapter/PythonPickleSerializeProtocol0Test.php
  25. 113 0
      tests/Zend/Serializer/Adapter/PythonPickleSerializeProtocol1Test.php
  26. 334 0
      tests/Zend/Serializer/Adapter/PythonPickleUnserializeTest.php
  27. 179 0
      tests/Zend/Serializer/Adapter/WddxTest.php
  28. 45 0
      tests/Zend/Serializer/AllTests.php
  29. 108 0
      tests/Zend/Serializer/SerializerTest.php

+ 17 - 0
documentation/manual/en/manual.xml.in

@@ -1686,6 +1686,23 @@
             </xi:include>
         </chapter>
 
+        <chapter id="zend.serializer">
+            <title>Zend_Serializer</title>
+            <xi:include href="module_specs/Zend_Serializer-Introduction.xml">
+                <xi:fallback>
+                    <xi:include
+                        href="../en/module_specs/Zend_Serializer-Introduction.xml" />
+                </xi:fallback>
+            </xi:include>
+
+            <xi:include href="module_specs/Zend_Serializer-Adapter.xml">
+                <xi:fallback>
+                    <xi:include
+                        href="../en/module_specs/Zend_Serializer-Adapter.xml" />
+                </xi:fallback>
+            </xi:include>
+        </chapter>
+
         <chapter id="zend.server">
             <title>Zend_Server</title>
             <xi:include href="module_specs/Zend_Server.xml">

+ 446 - 0
documentation/manual/en/module_specs/Zend_Serializer-Adapter.xml

@@ -0,0 +1,446 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Reviewed: no -->
+<sect1 id="zend.serializer.adapter">
+    <title>Zend_Serializer_Adapter</title>
+    
+    <para>
+        <classname>Zend_Serializer</classname> adapters create a bridge for different methods of
+        serializing with very little effort.
+    </para>
+
+    <para>
+        Every adapter has different pros and cons. In some cases, not every PHP datatype (e.g.,
+        objects) can be converted to a string representation. In most such cases, the type will be
+        converted to a similar type that is serializable -- as an example, PHP objects will often be
+        cast to arrays.  If this fails, a <classname>Zend_Serializer_Exception</classname> will be
+        thrown.
+    </para>
+
+    <para>
+        Below is a list of available adapters.
+    </para>
+
+    <sect2 id="zend.serializer.adapter.phpserialize">
+        <title>Zend_Serializer_Adapter_PhpSerialize</title>
+
+        <para>
+            This adapter uses the built-in <methodname>un/serialize</methodname> PHP functions, and
+            is a good default adapter choice.
+        </para>
+
+        <para>
+            There are no configurable options for this adapter.
+        </para>
+    </sect2>
+
+    <sect2 id="zend.serializer.adapter.igbinary">
+        <title>Zend_Serializer_Adapter_Igbinary</title>
+
+        <para>
+            <ulink url="http://opensource.dynamoid.com">Igbinary</ulink> is Open Source Software
+            released by Sulake Dynamoid Oy. It's a drop-in replacement for the standard PHP
+            serializer. Instead of time and space consuming textual representation, igbinary stores
+            PHP data structures in a compact binary form. Savings are significant when using
+            memcached or similar memory based storages for serialized data.
+        </para>
+
+        <para>
+            You need the igbinary PHP extension installed on your system in order to use this
+            adapter.
+        </para>
+
+        <para>
+            There adapter takes no configuration options.
+        </para>
+    </sect2>
+
+    <sect2 id="zend.serializer.adapter.wddx">
+        <title>Zend_Serializer_Adapter_Wddx</title>
+
+        <para>
+            <ulink url="http://wikipedia.org/wiki/WDDX">WDDX</ulink> (Web Distributed Data eXchange)
+            is a programming-language-, platform-, and transport-neutral data interchange mechanism
+            for passing data between different environments and different computers.
+        </para>
+
+        <para>
+            The adapter simply uses the <ulink url="http://php.net/manual/book.wddx.php">wddx_*()</ulink>
+            PHP functions. Please read the php manual to determine how you may enable them in your
+            PHP installation.
+        </para>
+
+        <para>
+            Additionally, the <ulink
+                url="http://php.net/manual/book.simplexml.php">SimpleXML</ulink> PHP extension is
+            used to check if a returned <constant>NULL</constant> value from
+            <methodname>wddx_unserialize()</methodname> is based on a serialized
+            <constant>NULL</constant> or on invalid data.
+        </para>
+
+        <para>
+            Available options include:
+        </para>
+
+        <table>
+            <tgroup cols="4">
+                 <thead>
+                      <row>
+                          <entry>Option</entry>
+
+                          <entry>Data Type</entry>
+
+                          <entry>Default Value</entry>
+
+                          <entry>Description</entry>
+                    </row>
+                 </thead>
+
+                 <tbody>
+                      <row>
+                          <entry><emphasis>comment</emphasis></entry>
+
+                          <entry><type>string</type></entry>
+
+                          <entry></entry>
+
+                          <entry>
+                            An optional comment that appears in the packet header. 
+                          </entry>
+                      </row>
+                  </tbody>
+             </tgroup>
+        </table>
+    </sect2>
+
+    <sect2 id="zend.serializer.adapter.json">
+        <title>Zend_Serializer_Adapter_Json</title>
+
+        <para>
+            The <acronym>JSON</acronym> adapter provides a bridge to the
+            <classname>Zend_Json</classname> component and/or ext/json. Please read the <link
+                linkend= "zend.json.introduction">Zend_Json documentation</link> for further
+            information.
+        </para>
+
+        <para>
+            Available options include:
+        </para>
+
+        <table>
+            <tgroup cols="4">
+                 <thead>
+                      <row>
+                        <entry>Option</entry>
+
+                        <entry>Data Type</entry>
+
+                        <entry>Default Value</entry>
+
+                        <entry>Description</entry>
+                    </row>
+                 </thead>
+
+                 <tbody>
+                      <row>
+                          <entry><emphasis>cycleCheck</emphasis></entry>
+
+                          <entry><type>boolean</type></entry>
+
+                          <entry>false</entry>
+
+                          <entry>
+                               See <xref linkend= "zend.json.advanced.objects1"/>
+                          </entry>
+                      </row>
+
+                      <row>
+                          <entry><emphasis>objectDecodeType</emphasis></entry>
+
+                          <entry><type>Zend_Json::TYPE_*</type></entry>
+
+                          <entry>Zend_Json::TYPE_ARRAY</entry>
+
+                          <entry>
+                               See <xref linkend= "zend.json.advanced.objects1"/>
+                          </entry>
+                      </row>
+
+                      <row>
+                          <entry><emphasis>enableJsonExprFinder</emphasis></entry>
+
+                          <entry><type>boolean</type></entry>
+
+                          <entry>false</entry>
+
+                          <entry>
+                               See <xref linkend= "zend.json.advanced.expr"/>
+                          </entry>
+                      </row>
+                  </tbody>
+             </tgroup>
+        </table>
+    </sect2>
+
+    <sect2 id="zend.serializer.adapter.amf03">
+        <title>Zend_Serializer_Adapter_Amf 0 and 3</title>
+
+        <para>
+            The <acronym>AMF</acronym> adapters, <classname>Zend_Serializer_Adapter_Amf0</classname>
+            and <classname>Zend_Serializer_Adapter_Amf3</classname>, provide a bridge to the
+            serializer of the <classname>Zend_Amf</classname> component. Please read the <link
+                linkend= "zend.amf.introduction">Zend_Amf documentation</link> for further
+            information.
+        </para>
+
+        <para>
+            There are no options for these adapters.
+        </para>
+    </sect2>
+
+    <sect2 id="zend.serializer.adapter.pythonpickle">
+        <title>Zend_Serializer_Adapter_PythonPickle</title>
+
+        <para>
+            This adapter converts PHP types to a <ulink
+                url="http://docs.python.org/library/pickle.html">Python Pickle</ulink> string
+            representation.  With it, you can read the serialized data with Python and read Pickled
+            data of Python with PHP.
+        </para>
+
+        <para>
+            Available options include:
+        </para>
+
+        <table>
+            <tgroup cols="4">
+                 <thead>
+                      <row>
+                        <entry>Option</entry>
+
+                        <entry>Data Type</entry>
+
+                        <entry>Default Value</entry>
+
+                        <entry>Description</entry>
+                    </row>
+                 </thead>
+
+                 <tbody>
+                      <row>
+                          <entry><emphasis>protocol</emphasis></entry>
+
+                          <entry><type>integer</type> (0 | 1 | 2 | 3)</entry>
+
+                          <entry>0</entry>
+
+                          <entry>
+                               The Pickle protocol version used on <methodname>serialize</methodname>
+                          </entry>
+                      </row>
+                  </tbody>
+             </tgroup>
+        </table>
+
+        <para>
+            Datatype merging (PHP to Python) occurs as follows:
+        </para>
+
+        <table>
+            <tgroup cols="2">
+                 <thead>
+                      <row>
+                        <entry>PHP Type</entry>
+
+                        <entry>Python Type</entry>
+                    </row>
+                 </thead>
+
+                 <tbody>
+                      <row>
+                          <entry><type>NULL</type></entry>
+
+                          <entry><type>None</type></entry>
+                      </row>
+
+                      <row>
+                          <entry><type>boolean</type></entry>
+
+                          <entry><type>boolean</type></entry>
+                      </row>
+
+                      <row>
+                          <entry><type>integer</type></entry>
+
+                          <entry><type>integer</type></entry>
+                      </row>
+
+                      <row>
+                          <entry><type>float</type></entry>
+
+                          <entry><type>float</type></entry>
+                      </row>
+
+                      <row>
+                          <entry><type>string</type></entry>
+
+                          <entry><type>string</type></entry>
+                      </row>
+
+                      <row>
+                          <entry><type>array</type></entry>
+
+                          <entry><type>list</type></entry>
+                      </row>
+
+                      <row>
+                          <entry><type>associative array</type></entry>
+
+                          <entry><type>dictionary</type></entry>
+                      </row>
+
+                      <row>
+                          <entry><type>object</type></entry>
+
+                          <entry><type>dictionary</type></entry>
+                      </row>
+                  </tbody>
+             </tgroup>
+        </table>
+
+        <para>
+            Datatype merging (Python to PHP) occurs per the following:
+        </para>
+
+        <table>
+            <tgroup cols="2">
+                 <thead>
+                      <row>
+                        <entry>Python-Type</entry>
+
+                        <entry>PHP-Type</entry>
+                    </row>
+                 </thead>
+
+                 <tbody>
+                      <row>
+                          <entry><type>None</type></entry>
+
+                          <entry><type>NULL</type></entry>
+                      </row>
+
+                      <row>
+                          <entry><type>boolean</type></entry>
+
+                          <entry><type>boolean</type></entry>
+                      </row>
+
+                      <row>
+                          <entry><type>integer</type></entry>
+
+                          <entry><type>integer</type></entry>
+                      </row>
+
+                      <row>
+                          <entry><type>long</type></entry>
+
+                          <entry>
+                              <type>integer</type>
+                              | <type>float</type>
+                              | <type>string</type>
+                              | <classname>Zend_Serializer_Exception</classname>
+                          </entry>
+                      </row>
+
+                      <row>
+                          <entry><type>float</type></entry>
+
+                          <entry><type>float</type></entry>
+                      </row>
+
+                      <row>
+                          <entry><type>string</type></entry>
+
+                          <entry><type>string</type></entry>
+                      </row>
+
+                      <row>
+                          <entry><type>bytes</type></entry>
+
+                          <entry><type>string</type></entry>
+                      </row>
+
+                      <row>
+                          <entry><type>Unicode string</type></entry>
+
+                          <entry><type>UTF-8 string</type></entry>
+                      </row>
+
+                      <row>
+                          <entry><type>list</type></entry>
+
+                          <entry><type>array</type></entry>
+                      </row>
+
+                      <row>
+                          <entry><type>tuple</type></entry>
+
+                          <entry><type>array</type></entry>
+                      </row>
+
+                      <row>
+                          <entry><type>dictionary</type></entry>
+
+                          <entry><type>associative array</type></entry>
+                      </row>
+
+                      <row>
+                          <entry>All other types</entry>
+
+                          <entry><classname>Zend_Serializer_Exception</classname></entry>
+                      </row>
+                  </tbody>
+             </tgroup>
+        </table>
+    </sect2>
+    
+    <sect2 id="zend.serializer.adapter.phpcode">
+        <title>Zend_Serializer_Adapter_PhpCode</title>
+
+        <para>
+            This adapter generates a parsable PHP code representation using <ulink
+                url="http://php.net/manual/function.var-export.php">var_export()</ulink>. On
+            restoring, the data will be executed using <ulink
+                url="http://php.net/manual/function.eval.php">eval</ulink>.
+        </para>
+
+        <para>
+            There are no configuration options for this adapter.
+        </para>
+
+        <warning>
+            <title>Unserializing objects</title>
+
+            <para>
+                Objects will be serialized using the <ulink
+                    url="http://php.net/manual/language.oop5.magic.php#language.oop5.magic.set-state">__set_state</ulink>
+                magic method. If the class doesn't implement this method, a fatal error will occur
+                during execution.
+            </para>
+        </warning>
+
+        <warning>
+            <title>Uses eval()</title>
+
+            <para>
+                The <classname>PhpCode</classname> adapter utilizes <methodname>eval()</methodname>
+                to unserialize. This introduces both a performance and potential security issue as a
+                new process will be executed. Typically, you should use the
+                <methodname>PhpSerialize</methodname> adapter unless you require human-readability
+                of the serialized data.
+            </para>
+        </warning>
+    </sect2>
+</sect1>
+<!--
+vim:se ts=4 sw=4 et:
+-->

+ 101 - 0
documentation/manual/en/module_specs/Zend_Serializer-Introduction.xml

@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Reviewed: no -->
+<sect1 id="zend.serializer.introduction">
+    <title>Introduction</title>
+
+    <para>
+        <classname>Zend_Serializer</classname> provides an adapter based interface to simply
+        generate storable representation of php types by different facilities, and recover.
+    </para>
+
+    <example id="zend.serializer.introduction.example.dynamic">
+        <title>Using <classname>Zend_Serializer</classname> dynamic interface</title>
+
+        <para>
+            To instantiate a serializer you should use the factory method with the name of the
+            adapter:
+        </para>
+
+        <programlisting language="php"><![CDATA[
+$serializer = Zend_Serializer::factory('PhpSerialize');
+// Now $serializer is an instance of Zend_Serializer_Adapter_AdapterInterface,
+// specifically Zend_Serializer_Adapter_PhpSerialize
+
+try { 
+    $serialized = $serializer->serialize($data);
+    // now $serialized is a string
+    
+    $unserialized = $serializer->unserialize($serialized);
+    // now $data == $unserialized
+} catch (Zend_Serializer_Exception $e) { 
+    echo $e; 
+} 
+]]></programlisting>
+    </example>
+
+    <para>
+        The method <methodname>serialize</methodname> generates a storable string. To regenerate
+        this serialized data you can simply call the method <methodname>unserialize</methodname>.
+    </para>
+
+    <para>
+        Any time an error is encountered serializing or unserializing,
+        <classname>Zend_Serializer</classname> will throw a
+        <classname>Zend_Serializer_Exception</classname>.
+    </para>
+
+    <para>
+        To configure a given serializer adapter, you can optionally add an array or an instance of
+        <classname>Zend_Config</classname> to the <methodname>factory</methodname> or to the
+        <methodname>un-/serialize</methodname> methods:
+    </para>
+
+    <programlisting language="php"><![CDATA[
+$serializer = Zend_Serializer::factory('Wddx', array(
+    'comment' => 'serialized by Zend_Serializer',
+));
+
+try { 
+    $serialized = $serializer->serialize($data, array('comment' => 'change comment'));
+    $unserialized = $serializer->unserialize($serialized, array(/* options for unserialize */));
+} catch (Zend_Serializer_Exception $e) { 
+    echo $e; 
+} 
+]]></programlisting>
+
+    <para>
+        Options passed to the <methodname>factory</methodname> are valid for the instantiated
+        object. You can change these options using the <methodname>setOption(s)</methodname> method.
+        To change one or more options only for a single call, pass them as the second argument to
+        either the <methodname>serialize</methodname> or <methodname>unserialize</methodname>
+        method.
+    </para>
+
+    <sect2 id="zend.serializer.introduction.example.static.php">
+        <title>Using the Zend_Serializer static interface</title>
+
+        <para>
+            You can register a specific serializer adapter as a default serialization adapter for
+            use with <classname>Zend_Serializer</classname>. By default, the
+            <classname>PhpSerialize</classname> adapter will be registered, but you can change this
+            option using the <methodname>setDefaultAdapter()</methodname> static method.
+        </para>
+
+        <programlisting language="php"><![CDATA[
+Zend_Serializer::setDefaultAdapter('PhpSerialize', $options);
+// or
+$serializer = Zend_Serializer::factory('PhpSerialize', $options);
+Zend_Serializer::setDefaultAdapter($serializer);
+
+try { 
+    $serialized   = Zend_Serializer::serialize($data, $options); 
+    $unserialized = Zend_Serializer::unserialize($serialized, $options); 
+} catch (Zend_Serializer_Exception $e) { 
+    echo $e; 
+} 
+]]></programlisting>
+    </sect2>
+</sect1>
+<!--
+vim:se ts=4 sw=4 et:
+-->

+ 164 - 0
library/Zend/Serializer.php

@@ -0,0 +1,164 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/** @see Zend_Loader_PluginLoader */
+require_once 'Zend/Loader/PluginLoader.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Serializer
+{
+    /**
+     * Plugin loader to load adapter.
+     *
+     * @var null|Zend_Loader_PluginLoader
+     */
+    private static $_adapterLoader = null;
+
+    /**
+     * The default adapter.
+     *
+     * @var string|Zend_Serializer_AdapterInterface
+     */
+    protected static $_defaultAdapter = 'PhpSerialize';
+
+    /**
+     * Create a serializer adapter instance.
+     *
+     * @param string|Zend_Serializer_Adapter_AdapterInterface $adapterName Name of the adapter class
+     * @param array |Zend_Config $opts Serializer options
+     * @return Zend_Serializer_Adapter_AdapterInterface
+     */
+    public static function factory($adapterName, $opts = array()) 
+    {
+        if ($adapterName instanceof Zend_Serializer_Adapter_AdapterInterface) {
+            return $adapterName; // $adapterName is already an adapter object
+        }
+
+        $adapterLoader = self::getAdapterLoader();
+        try {
+            $adapterClass = $adapterLoader->load($adapterName);
+        } catch (Exception $e) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('Can\'t load serializer adapter "'.$adapterName.'"', 0, $e);
+        }
+        $adapterReflection = new ReflectionClass($adapterClass);
+        if (!$adapterReflection->implementsInterface('Zend_Serializer_Adapter_AdapterInterface')) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('The serializer adapter class "'.$adapterClass.'" must implement Zend_Serializer_Adapter_AdapterInterface');
+        }
+        return new $adapterClass($opts);
+    }
+
+    /**
+     * Get the adapter plugin loader.
+     *
+     * @return Zend_Loader_PluginLoader
+     */
+    public static function getAdapterLoader() 
+    {
+        if (self::$_adapterLoader === null) {
+            $loader = new Zend_Loader_PluginLoader();
+            $loader->addPrefixPath('Zend_Serializer_Adapter', dirname(__FILE__).'/Serializer/Adapter');
+            self::$_adapterLoader = $loader;
+        }
+        return self::$_adapterLoader;
+    }
+
+    /**
+     * Change the adapter plugin load.
+     *
+     * @param  Zend_Loader_PluginLoader $pluginLoader
+     * @return void
+     */
+    public static function setAdapterLoader(Zend_Loader_PluginLoader $pluginLoader) 
+    {
+        self::$_adapterLoader = $pluginLoader;
+    }
+
+    /**
+     * Change the default adapter.
+     *
+     * @param string|Zend_Serializer_Adapter_AdapterInterface $adapter
+     * @param array|Zend_Config $options
+     */
+    public static function setDefaultAdapter($adapter, $options = array()) 
+    {
+        self::$_defaultAdapter = self::factory($adapter, $options);
+    }
+
+    /**
+     * Get the default adapter.
+     *
+     * @return Zend_Serializer_Adapter_AdapterInterface
+     */
+    public static function getDefaultAdapter() 
+    {
+        if (!self::$_defaultAdapter instanceof Zend_Serializer_Adapter_AdapterInterface) {
+            self::setDefaultAdapter(self::$_defaultAdapter);
+        }
+        return self::$_defaultAdapter;
+    }
+
+    /**
+     * Generates a storable representation of a value using the default adapter.
+     *
+     * @param mixed $value
+     * @param array $options
+     * @return string
+     * @throws Zend_Serializer_Exception
+     */
+    public static function serialize($value, array $options = array()) 
+    {
+        if (isset($options['adapter'])) {
+            $adapter = self::factory($options['adapter']);
+            unset($options['adapter']);
+        } else {
+            $adapter = self::getDefaultAdapter();
+        }
+
+        return $adapter->serialize($value, $options);
+    }
+
+    /**
+     * Creates a PHP value from a stored representation using the default adapter.
+     *
+     * @param string $serialized
+     * @param array $options
+     * @return mixed
+     * @throws Zend_Serializer_Exception
+     */
+    public static function unserialize($serialized, array $options = array()) 
+    {
+        if (isset($options['adapter'])) {
+            $adapter = self::factory($options['adapter']);
+            unset($options['adapter']);
+        } else {
+            $adapter = self::getDefaultAdapter();
+        }
+
+        return $adapter->unserialize($serialized, $options);
+    }
+}

+ 112 - 0
library/Zend/Serializer/Adapter/AdapterAbstract.php

@@ -0,0 +1,112 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @subpackage Adapter
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/** @see Zend_Serializer_Adapter_AdapterInterface */
+require_once 'Zend/Serializer/Adapter/AdapterInterface.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @subpackage Adapter
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+abstract class Zend_Serializer_Adapter_AdapterAbstract implements Zend_Serializer_Adapter_AdapterInterface
+{
+    /**
+     * Serializer options
+     *
+     * @var array
+     */
+    protected $_options = array();
+
+    /**
+     * Constructor
+     *
+     * @param array|Zend_Config $opts Serializer options
+     */
+    public function __construct($opts = array()) 
+    {
+        $this->setOptions($opts);
+    }
+
+    /**
+     * Set serializer options
+     *
+     * @param  array|Zend_Config $opts Serializer options
+     * @return Zend_Serializer_Adapter_AdapterAbstract
+     */
+    public function setOptions($opts) 
+    {
+        if ($opts instanceof Zend_Config) {
+            $opts = $opts->toArray();
+        } else {
+            $opts = (array) $opts;
+        }
+
+        foreach ($opts as $k => $v) {
+            $this->setOption($k, $v);
+        }
+        return $this;
+    }
+
+    /**
+     * Set a serializer option
+     *
+     * @param  string $name Option name
+     * @param  mixed $value Option value
+     * @return Zend_Serializer_Adapter_AdapterAbstract
+     */
+    public function setOption($name, $value) 
+    {
+        $this->_options[(string) $name] = $value;
+        return $this;
+    }
+
+    /**
+     * Get serializer options
+     *
+     * @return array
+     */
+    public function getOptions() 
+    {
+        return $this->_options;
+    }
+
+    /**
+     * Get a serializer option
+     *
+     * @param  string $name
+     * @return mixed
+     * @throws Zend_Serializer_Exception
+     */
+    public function getOption($name) 
+    {
+        $name = (string) $name;
+        if (!array_key_exists($name, $this->_options)) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('Unknown option name "'.$name.'"');
+        }
+
+        return $this->_options[$name];
+    }
+}

+ 92 - 0
library/Zend/Serializer/Adapter/AdapterInterface.php

@@ -0,0 +1,92 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @subpackage Adapter
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @subpackage Adapter
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+interface Zend_Serializer_Adapter_AdapterInterface 
+{
+    /**
+     * Constructor
+     *
+     * @param  array|Zend_Config $opts Serializer options
+     * @return void
+     */
+    public function __construct($opts = array());
+
+    /**
+     * Set serializer options
+     *
+     * @param  array|Zend_Config $opts Serializer options
+     * @return Zend_Serializer_Adapter_AdapterInterface
+     */
+    public function setOptions($opts);
+
+    /**
+     * Set a serializer option
+     *
+     * @param  string $name Option name
+     * @param  mixed $value Option value
+     * @return Zend_Serializer_Adapter_AdapterInterface
+     */
+    public function setOption($name, $value);
+
+    /**
+     * Get serializer options
+     *
+     * @return array
+     */
+    public function getOptions();
+
+    /**
+     * Get a serializer option
+     *
+     * @param  string $name
+     * @return mixed
+     * @throws Zend_Serializer_Exception
+     */
+    public function getOption($name);
+
+    /**
+     * Generates a storable representation of a value.
+     *
+     * @param  mixed $value Data to serialize
+     * @param  array $options Serialize options
+     * @return string
+     * @throws Zend_Serializer_Exception
+     */
+    public function serialize($value, array $options = array());
+
+    /**
+     * Creates a PHP value from a stored representation.
+     *
+     * @param  string $serialized Serialized string
+     * @param  array $options Unserialize options
+     * @return mixed
+     * @throws Zend_Serializer_Exception
+     */
+    public function unserialize($serialized, array $options = array());
+}

+ 88 - 0
library/Zend/Serializer/Adapter/Amf0.php

@@ -0,0 +1,88 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @subpackage Adapter
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/** @see Zend_Serializer_Adapter_AdapterAbstract */
+require_once 'Zend/Serializer/Adapter/AdapterAbstract.php';
+
+/** @see Zend_Amf_Parse_OutputStream */
+require_once 'Zend/Amf/Parse/OutputStream.php';
+
+/** @see Zend_Amf_Parse_Amf0_Serializer */
+require_once 'Zend/Amf/Parse/Amf0/Serializer.php';
+
+/** @see Zend_Amf_Parse_InputStream */
+require_once 'Zend/Amf/Parse/InputStream.php';
+
+/** @see Zend_Amf_Parse_Amf0_Deserializer */
+require_once 'Zend/Amf/Parse/Amf0/Deserializer.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @subpackage Adapter
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Serializer_Adapter_Amf0 extends Zend_Serializer_Adapter_AdapterAbstract
+{
+    /**
+     * Serialize a PHP value to AMF0 format
+     * 
+     * @param  mixed $value 
+     * @param  array $opts 
+     * @return string
+     * @throws Zend_Serializer_Exception
+     */
+    public function serialize($value, array $opts = array())
+    {
+        try  {
+            $stream     = new Zend_Amf_Parse_OutputStream();
+            $serializer = new Zend_Amf_Parse_Amf0_Serializer($stream);
+            $serializer->writeTypeMarker($value);
+            return $stream->getStream();
+        } catch (Exception $e) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('Serialization failed by previous error', 0, $e);
+        }
+    }
+
+    /**
+     * Unserialize an AMF0 value to PHP
+     * 
+     * @param  mixed $value 
+     * @param  array $opts 
+     * @return void
+     * @throws Zend_Serializer_Exception
+     */
+    public function unserialize($value, array $opts = array())
+    {
+        try {
+            $stream       = new Zend_Amf_Parse_InputStream($value);
+            $deserializer = new Zend_Amf_Parse_Amf0_Deserializer($stream);
+            return $deserializer->readTypeMarker();
+        } catch (Exception $e) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('Unserialization failed by previous error', 0, $e);
+        }
+    }
+
+}

+ 87 - 0
library/Zend/Serializer/Adapter/Amf3.php

@@ -0,0 +1,87 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @subpackage Adapter
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/** @see Zend_Serializer_Adapter_AdapterAbstract */
+require_once 'Zend/Serializer/Adapter/AdapterAbstract.php';
+
+/** @see Zend_Amf_Parse_OutputStream */
+require_once 'Zend/Amf/Parse/OutputStream.php';
+
+/** @see Zend_Amf_Parse_Amf3_Serializer */
+require_once 'Zend/Amf/Parse/Amf3/Serializer.php';
+
+/** @see Zend_Amf_Parse_InputStream */
+require_once 'Zend/Amf/Parse/InputStream.php';
+
+/** @see Zend_Amf_Parse_Amf3_Deserializer */
+require_once 'Zend/Amf/Parse/Amf3/Deserializer.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @subpackage Adapter
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Serializer_Adapter_Amf3 extends Zend_Serializer_Adapter_AdapterAbstract
+{
+    /**
+     * Serialize a PHP value to AMF3 format
+     * 
+     * @param  mixed $value 
+     * @param  array $opts 
+     * @return string
+     * @throws Zend_Serializer_Exception
+     */
+    public function serialize($value, array $opts = array())
+    {
+        try  {
+            $stream     = new Zend_Amf_Parse_OutputStream();
+            $serializer = new Zend_Amf_Parse_Amf3_Serializer($stream);
+            $serializer->writeTypeMarker($value);
+            return $stream->getStream();
+        } catch (Exception $e) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('Serialization failed by previous error', 0, $e);
+        }
+    }
+
+    /**
+     * Deserialize an AMF3 value to PHP
+     * 
+     * @param  mixed $value 
+     * @param  array $opts 
+     * @return string
+     * @throws Zend_Serializer_Exception
+     */
+    public function unserialize($value, array $opts = array())
+    {
+        try {
+            $stream       = new Zend_Amf_Parse_InputStream($value);
+            $deserializer = new Zend_Amf_Parse_Amf3_Deserializer($stream);
+            return $deserializer->readTypeMarker();
+        } catch (Exception $e) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('Unserialization failed by previous error', 0, $e);
+        }
+    }
+}

+ 98 - 0
library/Zend/Serializer/Adapter/Igbinary.php

@@ -0,0 +1,98 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @subpackage Adapter
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/** @see Zend_Serializer_Adapter_AdapterAbstract */
+require_once 'Zend/Serializer/Adapter/AdapterAbstract.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @subpackage Adapter
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Serializer_Adapter_Igbinary extends Zend_Serializer_Adapter_AdapterAbstract
+{
+    /**
+     * @var string Serialized null value
+     */
+    private static $_serializedNull = null;
+
+    /**
+     * Constructor
+     * 
+     * @param  array|Zend_Config $opts 
+     * @return void
+     * @throws Zend_Serializer_Exception If igbinary extension is not present
+     */
+    public function __construct($opts = array()) 
+    {
+        if (!extension_loaded('igbinary')) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('PHP extension "igbinary" is required for this adapter');
+        }
+
+        parent::__construct($opts);
+
+        if (self::$_serializedNull === null) {
+            self::$_serializedNull = igbinary_serialize(null);
+        }
+    }
+
+    /**
+     * Serialize PHP value to igbinary
+     * 
+     * @param  mixed $value 
+     * @param  array $opts 
+     * @return string
+     * @throws Zend_Serializer_Exception on igbinary error
+     */
+    public function serialize($value, array $opts = array())
+    {
+        $ret = igbinary_serialize($value);
+        if ($ret === false) {
+            $lastErr = error_get_last();
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception($lastErr['message']);
+        }
+        return $ret;
+    }
+
+    /**
+     * Deserialize igbinary string to PHP value
+     * 
+     * @param  string|binary $serialized 
+     * @param  array $opts 
+     * @return mixed
+     * @throws Zend_Serializer_Exception on igbinary error
+     */
+    public function unserialize($serialized, array $opts = array())
+    {
+        $ret = igbinary_unserialize($serialized);
+        if ($ret === null && $serialized !== self::$_serializedNull) {
+            $lastErr = error_get_last();
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception($lastErr['message']);
+        }
+        return $ret;
+    }
+}

+ 93 - 0
library/Zend/Serializer/Adapter/Json.php

@@ -0,0 +1,93 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @subpackage Adapter
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/** @see Zend_Serializer_Adapter_AdapterAbstract */
+require_once 'Zend/Serializer/Adapter/AdapterAbstract.php';
+
+/** @see Zend_Json */
+require_once 'Zend/Json.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @subpackage Adapter
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Serializer_Adapter_Json extends Zend_Serializer_Adapter_AdapterAbstract
+{
+    /**
+     * @var array Default options
+     */
+    protected $_options = array(
+        'cycleCheck'           => false,
+        'enableJsonExprFinder' => false,
+        'objectDecodeType'     => Zend_Json::TYPE_ARRAY,
+    );
+
+    /**
+     * Serialize PHP value to JSON
+     * 
+     * @param  mixed $value 
+     * @param  array $opts 
+     * @return string
+     * @throws Zend_Serializer_Exception on JSON encoding exception
+     */
+    public function serialize($value, array $opts = array())
+    {
+        $opts = $opts + $this->_options;
+
+        try  {
+            return Zend_Json::encode($value, $opts['cycleCheck'], $opts);
+        } catch (Exception $e) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('Serialization failed', 0, $e);
+        }
+    }
+
+    /**
+     * Deserialize JSON to PHP value
+     * 
+     * @param  string $json 
+     * @param  array $opts 
+     * @return mixed
+     */
+    public function unserialize($json, array $opts = array())
+    {
+        $opts = $opts + $this->_options;
+
+        try {
+            $ret = Zend_Json::decode($json, $opts['objectDecodeType']);
+        } catch (Exception $e) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('Unserialization failed by previous error', 0, $e);
+        }
+
+        // json_decode returns null for invalid JSON
+        if ($ret === null && $json !== 'null') {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('Invalid json data');
+        }
+
+        return $ret;
+    }
+}

+ 67 - 0
library/Zend/Serializer/Adapter/PhpCode.php

@@ -0,0 +1,67 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @subpackage Adapter
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/** @see Zend_Serializer_Adapter_AdapterAbstract */
+require_once 'Zend/Serializer/Adapter/AdapterAbstract.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @subpackage Adapter
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Serializer_Adapter_PhpCode extends Zend_Serializer_Adapter_AdapterAbstract
+{
+    /**
+     * Serialize PHP using var_export
+     * 
+     * @param  mixed $value 
+     * @param  array $opts 
+     * @return string
+     */
+    public function serialize($value, array $opts = array())
+    {
+        return var_export($value, true);
+    }
+
+    /**
+     * Deserialize PHP string
+     *
+     * Warning: this uses eval(), and should likely be avoided.
+     * 
+     * @param  string $code 
+     * @param  array $opts 
+     * @return mixed
+     * @throws Zend_Serializer_Exception on eval error
+     */
+    public function unserialize($code, array $opts = array())
+    {
+        $eval = @eval('$ret=' . $code . ';');
+        if ($eval === false) {
+                $lastErr = error_get_last();
+                require_once 'Zend/Serializer/Exception.php';
+                throw new Zend_Serializer_Exception('eval failed: ' . $lastErr['message']);
+        }
+        return $ret;
+    }
+}

+ 94 - 0
library/Zend/Serializer/Adapter/PhpSerialize.php

@@ -0,0 +1,94 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @subpackage Adapter
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/** @see Zend_Serializer_Adapter_AdapterAbstract */
+require_once 'Zend/Serializer/Adapter/AdapterAbstract.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @subpackage Adapter
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Serializer_Adapter_PhpSerialize extends Zend_Serializer_Adapter_AdapterAbstract
+{
+    /**
+     *  @var null|string Serialized boolean false value
+     */
+    private static $_serializedFalse = null;
+
+    /**
+     * Constructor
+     * 
+     * @param  array|Zend_Config $opts 
+     * @return void
+     */
+    public function __construct($opts = array()) 
+    {
+        parent::__construct($opts);
+
+        if (self::$_serializedFalse === null) {
+            self::$_serializedFalse = serialize(false);
+        }
+    }
+
+    /**
+     * Serialize using serialize()
+     * 
+     * @param  mixed $value 
+     * @param  array $opts 
+     * @return string
+     * @throws Zend_Serializer_Exception On serialize error
+     */
+    public function serialize($value, array $opts = array())
+    {
+        $ret = serialize($value);
+        if ($ret === false) {
+            $lastErr = error_get_last();
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception($lastErr['message']);
+        }
+        return $ret;
+    }
+
+    /**
+     * Unserialize
+     * 
+     * @todo   Allow integration with unserialize_callback_func
+     * @param  string $serialized 
+     * @param  array $opts 
+     * @return mixed
+     * @throws Zend_Serializer_Exception on unserialize error
+     */
+    public function unserialize($serialized, array $opts = array())
+    {
+        // TODO: @see php.ini directive "unserialize_callback_func"
+        $ret = @unserialize($serialized);
+        if ($ret === false && $serialized !== self::$_serializedFalse) {
+            $lastErr = error_get_last();
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception($lastErr['message']);
+        }
+        return $ret;
+    }
+}

+ 1494 - 0
library/Zend/Serializer/Adapter/PythonPickle.php

@@ -0,0 +1,1494 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @subpackage Adapter
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/** @see Zend_Serializer_Adapter_AdapterAbstract */
+require_once 'Zend/Serializer/Adapter/AdapterAbstract.php';
+
+/**
+ * @link       http://www.python.org
+ * @see        Phython3.1/Lib/pickle.py
+ * @see        Phython3.1/Modules/_pickle.c
+ * @link       http://pickle-js.googlecode.com
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @subpackage Adapter
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Serializer_Adapter_PythonPickle extends Zend_Serializer_Adapter_AdapterAbstract
+{
+    /* Pickle opcodes. See pickletools.py for extensive docs.  The listing
+       here is in kind-of alphabetical order of 1-character pickle code.
+       pickletools groups them by purpose. */
+    const OP_MARK            = '(';     // push special markobject on stack
+    const OP_STOP            = '.';     // every pickle ends with STOP
+    const OP_POP             = '0';     // discard topmost stack item
+    const OP_POP_MARK        = '1';     // discard stack top through topmost markobject
+    const OP_DUP             = '2';     // duplicate top stack item
+    const OP_FLOAT           = 'F';     // push float object; decimal string argument
+    const OP_INT             = 'I';     // push integer or bool; decimal string argument
+    const OP_BININT          = 'J';     // push four-byte signed int
+    const OP_BININT1         = 'K';     // push 1-byte unsigned int
+    const OP_LONG            = 'L';     // push long; decimal string argument
+    const OP_BININT2         = 'M';     // push 2-byte unsigned int
+    const OP_NONE            = 'N';     // push None
+    const OP_PERSID          = 'P';     // push persistent object; id is taken from string arg
+    const OP_BINPERSID       = 'Q';     //  "       "         "  ;  "  "   "     "  stack
+    const OP_REDUCE          = 'R';     // apply callable to argtuple, both on stack
+    const OP_STRING          = 'S';     // push string; NL-terminated string argument
+    const OP_BINSTRING       = 'T';     // push string; counted binary string argument
+    const OP_SHORT_BINSTRING = 'U';     //  "     "   ;    "      "       "      " < 256 bytes
+    const OP_UNICODE         = 'V';     // push Unicode string; raw-unicode-escaped'd argument
+    const OP_BINUNICODE      = 'X';     //   "     "       "  ; counted UTF-8 string argument
+    const OP_APPEND          = 'a';     // append stack top to list below it
+    const OP_BUILD           = 'b';     // call __setstate__ or __dict__.update()
+    const OP_GLOBAL          = 'c';     // push self.find_class(modname, name); 2 string args
+    const OP_DICT            = 'd';     // build a dict from stack items
+    const OP_EMPTY_DICT      = '}';     // push empty dict
+    const OP_APPENDS         = 'e';     // extend list on stack by topmost stack slice
+    const OP_GET             = 'g';     // push item from memo on stack; index is string arg
+    const OP_BINGET          = 'h';     //   "    "    "    "   "   "  ;   "    " 1-byte arg
+    const OP_INST            = 'i';     // build & push class instance
+    const OP_LONG_BINGET     = 'j';     // push item from memo on stack; index is 4-byte arg
+    const OP_LIST            = 'l';     // build list from topmost stack items
+    const OP_EMPTY_LIST      = ']';     // push empty list
+    const OP_OBJ             = 'o';     // build & push class instance
+    const OP_PUT             = 'p';     // store stack top in memo; index is string arg
+    const OP_BINPUT          = 'q';     //   "     "    "   "   " ;   "    " 1-byte arg
+    const OP_LONG_BINPUT     = 'r';     //   "     "    "   "   " ;   "    " 4-byte arg
+    const OP_SETITEM         = 's';     // add key+value pair to dict
+    const OP_TUPLE           = 't';     // build tuple from topmost stack items
+    const OP_EMPTY_TUPLE     = ')';     // push empty tuple
+    const OP_SETITEMS        = 'u';     // modify dict by adding topmost key+value pairs
+    const OP_BINFLOAT        = 'G';     // push float; arg is 8-byte float encoding
+
+    /* Protocol 2 */
+    const OP_PROTO           = "\x80";  // identify pickle protocol
+    const OP_NEWOBJ          = "\x81";  // build object by applying cls.__new__ to argtuple
+    const OP_EXT1            = "\x82";  // push object from extension registry; 1-byte index
+    const OP_EXT2            = "\x83";  // ditto, but 2-byte index
+    const OP_EXT4            = "\x84";  // ditto, but 4-byte index
+    const OP_TUPLE1          = "\x85";  // build 1-tuple from stack top
+    const OP_TUPLE2          = "\x86";  // build 2-tuple from two topmost stack items
+    const OP_TUPLE3          = "\x87";  // build 3-tuple from three topmost stack items
+    const OP_NEWTRUE         = "\x88";  // push True
+    const OP_NEWFALSE        = "\x89";  // push False
+    const OP_LONG1           = "\x8a";  // push long from < 256 bytes
+    const OP_LONG4           = "\x8b";  // push really big long
+
+    /* Protocol 3 (Python 3.x) */
+    const OP_BINBYTES        = 'B';     // push bytes; counted binary string argument
+    const OP_SHORT_BINBYTES  = 'C';     //  "     "   ;    "      "       "      " < 256 bytes
+
+    /**
+     * @var bool Whether or not this is a PHP 6 binary
+     */
+    protected static $_isPhp6 = null;
+
+    /**
+     * @var bool Whether or not the system is little-endian
+     */
+    protected static $_isLittleEndian = null;
+
+    /**
+     * @var array Strings representing quotes
+     */
+    protected static $_quoteString = array(
+        '\\' => '\\\\',
+        "\x00" => '\\x00', "\x01" => '\\x01', "\x02" => '\\x02', "\x03" => '\\x03',
+        "\x04" => '\\x04', "\x05" => '\\x05', "\x06" => '\\x06', "\x07" => '\\x07',
+        "\x08" => '\\x08', "\x09" => '\\t',   "\x0a" => '\\n',   "\x0b" => '\\x0b',
+        "\x0c" => '\\x0c', "\x0d" => '\\r',   "\x0e" => '\\x0e', "\x0f" => '\\x0f',
+        "\x10" => '\\x10', "\x11" => '\\x11', "\x12" => '\\x12', "\x13" => '\\x13',
+        "\x14" => '\\x14', "\x15" => '\\x15', "\x16" => '\\x16', "\x17" => '\\x17',
+        "\x18" => '\\x18', "\x19" => '\\x19', "\x1a" => '\\x1a', "\x1b" => '\\x1b',
+        "\x1c" => '\\x1c', "\x1d" => '\\x1d', "\x1e" => '\\x1e', "\x1f" => '\\x1f',
+        "\xff" => '\\xff'
+    );
+
+    /**
+     * @var array Default options
+     */
+    protected $_options = array(
+        'protocol'           => 0,
+    );
+
+    // process vars
+    protected $_protocol           = 0;
+    protected $_binary             = false;
+    protected $_memo               = array();
+    protected $_pickle             = '';
+    protected $_pickleLen          = 0;
+    protected $_pos                = 0;
+    protected $_stack              = array();
+    protected $_marker             = null;
+
+    /**
+     * Constructor
+     *
+     * @link Zend_Serializer_Adapter_AdapterAbstract::__construct()
+     */
+    public function __construct($opts=array())
+    {
+        parent::__construct($opts);
+
+        // init
+        if (self::$_isLittleEndian === null) {
+            self::$_isLittleEndian = (pack('l', 1) === "\x01\x00\x00\x00");
+        }
+        if (self::$_isPhp6 === null) {
+            self::$_isPhp6 = !version_compare(PHP_VERSION, '6.0.0', '<');
+        }
+
+        $this->_marker = new stdClass();
+    }
+
+    /**
+     * Set an option
+     *
+     * @link   Zend_Serializer_Adapter_AdapterAbstract::setOption()
+     * @param  string $name
+     * @param  mixed $value
+     * @return Zend_Serializer_Adapter_PythonPickle
+     */
+    public function setOption($name, $value)
+    {
+        switch ($name) {
+            case 'protocol':
+                $value = $this->_checkProtocolNumber($value);
+                break;
+        }
+
+        return parent::setOption($name, $value);
+    }
+
+    /**
+     * Check and normalize pickle protocol number
+     *
+     * @param  int $number
+     * @return int
+     * @throws Zend_Serializer_Exception
+     */
+    protected function _checkProtocolNumber($number)
+    {
+        $int = (int) $number;
+        if ($int < 0 || $int > 3) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('Invalid or unknown protocol version "'.$number.'"');
+        }
+        return $int;
+    }
+
+    /* serialize */
+
+    /**
+     * Serialize PHP to PythonPickle format
+     *
+     * @param  mixed $value
+     * @param  array $opts
+     * @return string
+     */
+    public function serialize($value, array $opts = array())
+    {
+        $opts = $opts + $this->_options;
+
+        $this->_protocol = $this->_checkProtocolNumber($opts['protocol']);
+        $this->_binary   = $this->_protocol != 0;
+
+        // clear process vars before serializing
+        $this->_memo   = array();
+        $this->_pickle = '';
+
+        // write
+        if ($this->_protocol >= 2) {
+            $this->_writeProto($this->_protocol);
+        }
+        $this->_write($value);
+        $this->_writeStop();
+
+        // clear process vars after serializing
+        $this->_memo = array();
+        $pickle = $this->_pickle;
+        $this->_pickle = '';
+
+        return $pickle;
+    }
+
+    /**
+     * Write a value
+     *
+     * @param  mixed $value
+     * @return void
+     * @throws Zend_Serializer_Exception on invalid or unrecognized value type
+     */
+    protected function _write($value)
+    {
+        if ($value === null) {
+            $this->_writeNull();
+        } elseif ($value === true) {
+            $this->_writeTrue();
+        } elseif ($value === false) {
+            $this->_writeFalse();
+        } elseif (is_int($value)) {
+            $this->_writeInt($value);
+        } elseif (is_float($value)) {
+            $this->_writeFloat($value);
+        } elseif (is_string($value)) {
+            // TODO: write unicode / binary
+            $this->_writeString($value);
+        } elseif (is_array($value)) {
+            if ($this->_isArrayAssoc($value)) {
+                $this->_writeArrayDict($value);
+            } else {
+                $this->_writeArrayList($value);
+            }
+        } elseif (is_object($value)) {
+            $this->_writeObject($value);
+        } else {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception(
+                'PHP-Type "'.gettype($value).'" isn\'t serializable with '.get_class($this)
+            );
+        }
+    }
+
+    /**
+     * Write pickle protocol
+     *
+     * @param  int $protocol
+     * @return void
+     */
+    protected function _writeProto($protocol)
+    {
+        $this->_pickle .= self::OP_PROTO . $protocol;
+    }
+
+    /**
+     * Write a get
+     *
+     * @param  int $id Id of memo
+     * @return void
+     */
+    protected function _writeGet($id)
+    {
+        if ($this->_binary) {
+            if ($id <= 0xff) {
+                // BINGET + chr(i)
+                $this->_pickle .= self::OP_BINGET . chr($id);
+            } else {
+                // LONG_BINGET + pack("<i", i)
+                $idBin = pack('l', $id);
+                if (self::$_isLittleEndian === false) {
+                    $idBin = strrev($bin);
+                }
+                $this->_pickle .= self::OP_LONG_BINGET . $idBin;
+            }
+        } else {
+            $this->_pickle .= self::OP_GET . $id . "\r\n";
+        }
+    }
+
+    /**
+     * Write a put
+     *
+     * @param  int $id Id of memo
+     * @return void
+     */
+    protected function _writePut($id)
+    {
+        if ($this->_binary) {
+            if ($id <= 0xff) {
+                // BINPUT + chr(i)
+                $this->_pickle .= self::OP_BINPUT . chr($id);
+            } else {
+                // LONG_BINPUT + pack("<i", i)
+                $idBin = pack('l', $id);
+                if (self::$_isLittleEndian === false) {
+                    $idBin = strrev($bin);
+                }
+                $this->_pickle .= self::OP_LONG_BINPUT . $idBin;
+            }
+        } else {
+            $this->_pickle .= self::OP_PUT . $id . "\r\n";
+        }
+    }
+
+    /**
+     * Write a null as None
+     *
+     * @return void
+     */
+    protected function _writeNull()
+    {
+        $this->_pickle .= self::OP_NONE;
+    }
+
+    /**
+     * Write a boolean true
+     *
+     * @return void
+     */
+    protected function _writeTrue()
+    {
+        if ($this->_protocol >= 2) {
+            $this->_pickle .= self::OP_NEWTRUE;
+        } else {
+            $this->_pickle .= self::OP_INT . "01\r\n";
+        }
+    }
+
+    /**
+     * Write a boolean false
+     *
+     * @return void
+     */
+    protected function _writeFalse()
+    {
+        if ($this->_protocol >= 2) {
+            $this->_pickle .= self::OP_NEWFALSE;
+        } else {
+            $this->_pickle .= self::OP_INT . "00\r\n";
+        }
+    }
+
+    /**
+     * Write an integer value
+     *
+     * @param  int $value
+     * @return void
+     */
+    protected function _writeInt($value)
+    {
+        if ($this->_binary) {
+            if ($value >= 0) {
+                if ($value <= 0xff) {
+                    // self.write(BININT1 + chr(obj))
+                    $this->_pickle .= self::OP_BININT1 . chr($value);
+                } elseif ($value <= 0xffff) {
+                    // self.write("%c%c%c" % (BININT2, obj&0xff, obj>>8))
+                    $this->_pickle .= self::OP_BININT2 . pack('v', $value);
+                }
+                return;
+            }
+
+            // Next check for 4-byte signed ints:
+            $highBits = $value >> 31;  // note that Python shift sign-extends
+            if ($highBits == 0 || $highBits == -1) {
+                // All high bits are copies of bit 2**31, so the value
+                // fits in a 4-byte signed int.
+                // self.write(BININT + pack("<i", obj))
+                $bin = pack('l', $value);
+                if (self::$_isLittleEndian === false) {
+                    $bin = strrev($bin);
+                }
+                $this->_pickle .= self::OP_BININT . $bin;
+                return;
+            }
+        }
+
+        $this->_pickle .= self::OP_INT . $value . "\r\n";
+    }
+
+    /**
+     * Write a float value
+     *
+     * @param  float $value
+     * @return void
+     */
+    protected function _writeFloat($value)
+    {
+        if ($this->_binary) {
+            // self.write(BINFLOAT + pack('>d', obj))
+            $bin = pack('d', $value);
+            if (self::$_isLittleEndian === true) {
+                $bin = strrev($bin);
+            }
+            $this->_pickle .= self::OP_BINFLOAT . $bin;
+        } else {
+            $this->_pickle .= self::OP_FLOAT . $value . "\r\n";
+        }
+    }
+
+    /**
+     * Write a string value
+     *
+     * @param  string $value
+     * @return void
+     */
+    protected function _writeString($value)
+    {
+        if ( ($id=$this->_searchMomo($value)) !== false ) {
+            $this->_writeGet($id);
+            return;
+        }
+
+        if ($this->_binary) {
+            $n = strlen($value);
+            if ($n <= 0xff) {
+                // self.write(SHORT_BINSTRING + chr(n) + obj)
+                $this->_pickle .= self::OP_SHORT_BINSTRING . chr($n) . $value;
+            } else {
+                // self.write(BINSTRING + pack("<i", n) + obj)
+                $binLen = pack('l', $n);
+                if (self::$_isLittleEndian === false) {
+                    $binLen = strrev($binLen);
+                }
+                $this->_pickle .= self::OP_BINSTRING . $binLen . $value;
+            }
+        } else {
+            $this->_pickle .= self::OP_STRING . $this->_quoteString($value) . "\r\n";
+        }
+
+        $this->_momorize($value);
+    }
+
+    /**
+     * Write an associative array value as dictionary
+     *
+     * @param  array $value
+     * @return void
+     */
+    protected function _writeArrayDict(array $value)
+    {
+        if (($id=$this->_searchMomo($value)) !== false) {
+            $this->_writeGet($id);;
+            return;
+        }
+
+        $this->_pickle .= self::OP_MARK . self::OP_DICT;
+        $this->_momorize($value);
+
+        foreach ($value as $k => $v) {
+            $this->_pickle .= $this->_write($k)
+                            . $this->_write($v)
+                            . self::OP_SETITEM;
+        }
+    }
+
+    /**
+     * Write a simple array value as list
+     *
+     * @param  array $value
+     * @return void
+     */
+    protected function _writeArrayList(array $value)
+    {
+        if (($id = $this->_searchMomo($value)) !== false) {
+            $this->_writeGet($id);
+            return;
+        }
+
+        $this->_pickle .= self::OP_MARK . self::OP_LIST;
+        $this->_momorize($value);
+
+        foreach ($value as $k => $v) {
+            $this->_pickle .= $this->_write($v) . self::OP_APPEND;
+        }
+    }
+
+    /**
+     * Write an object as an dictionary
+     *
+     * @param  object $value
+     * @return void
+     */
+    protected function _writeObject($value)
+    {
+        // can't serialize php objects to python objects yet
+        $this->_writeArrayDict(get_object_vars($value));
+    }
+
+    /**
+     * Write stop
+     *
+     * @return void
+     */
+    protected function _writeStop()
+    {
+        $this->_pickle .= self::OP_STOP;
+    }
+
+    /* serialize helper */
+
+    /**
+     * Add a value to the memo and write the id
+     *
+     * @param mixed $value
+     * @return void
+     */
+    protected function _momorize($value)
+    {
+        $id = count($this->_memo);
+        $this->_memo[$id] = $value;
+        $this->_writePut($id);
+    }
+
+    /**
+     * Search a value in the meno and return  the id
+     *
+     * @param  mixed $value
+     * @return int|false The id or false
+     */
+    protected function _searchMomo($value)
+    {
+        return array_search($value, $this->_memo, true);
+    }
+
+    /**
+     * Is an array associative?
+     *
+     * @param  array $value
+     * @return boolean
+     */
+    protected function _isArrayAssoc(array $value)
+    {
+        return array_diff_key($value, array_keys(array_keys($value)));
+    }
+
+    /**
+     * Quote/Escape a string
+     *
+     * @param  string $str
+     * @return string quoted string
+     */
+    protected function _quoteString($str)
+    {
+        $quoteArr = self::$_quoteString;
+
+        if (($cntSingleQuote = substr_count($str, "'"))
+            && ($cntDoubleQuote = substr_count($str, '"'))
+            && ($cntSingleQuote < $cntDoubleQuote)
+        ) {
+            $quoteArr['"'] = '\\"';
+            $enclosure     = '"';
+        } else {
+            $quoteArr["'"] = "\\'";
+            $enclosure     = "'";
+        }
+
+        return $enclosure . strtr($str, $quoteArr) . $enclosure;
+    }
+
+    /* unserialize */
+
+    /**
+     * Unserialize from Python Pickle format to PHP
+     *
+     * @param  string $pickle
+     * @param  array $opts
+     * @return mixed
+     * @throws Zend_Serializer_Exception on invalid Pickle string
+     */
+    public function unserialize($pickle, array $opts = array())
+    {
+        // init process vars
+        $this->_pos       = 0;
+        $this->_pickle    = $pickle;
+        $this->_pickleLen = strlen($this->_pickle);
+        $this->_memo      = array();
+        $this->_stack     = array();
+
+        // read pickle string
+        while (($op=$this->_read(1)) !== self::OP_STOP) {
+            $this->_load($op);
+        }
+
+        if (!count($this->_stack)) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('No data found');
+        }
+
+        $ret = array_pop($this->_stack);
+
+        // clear process vars
+        $this->_pos       = 0;
+        $this->_pickle    = '';
+        $this->_pickleLen = 0;
+        $this->_memo      = array();
+        $this->_stack     = array();
+
+        return $ret;
+    }
+
+    /**
+     * Load a pickle opcode
+     *
+     * @param  string $op
+     * @return void
+     * @throws Zend_Serializer_Exception on invalid opcode
+     */
+    protected function _load($op)
+    {
+        switch ($op) {
+            case self::OP_PUT:
+                $this->_loadPut();
+                break;
+            case self::OP_BINPUT:
+                $this->_loadBinPut();
+                break;
+            case self::OP_LONG_BINPUT:
+                $this->_loadLongBinPut();
+                break;
+            case self::OP_GET:
+                $this->_loadGet();
+                break;
+            case self::OP_BINGET:
+                $this->_loadBinGet();
+                break;
+            case self::OP_LONG_BINGET:
+                $this->_loadLongBinGet();
+                break;
+            case self::OP_NONE:
+                $this->_loadNone();
+                break;
+            case self::OP_NEWTRUE:
+                $this->_loadNewTrue();
+                break;
+            case self::OP_NEWFALSE:
+                $this->_loadNewFalse();
+                break;
+            case self::OP_INT:
+                $this->_loadInt();
+                break;
+            case self::OP_BININT:
+                $this->_loadBinInt();
+                break;
+            case self::OP_BININT1:
+                $this->_loadBinInt1();
+                break;
+            case self::OP_BININT2:
+                $this->_loadBinInt2();
+                break;
+            case self::OP_LONG:
+                $this->_loadLong();
+                break;
+            case self::OP_LONG1:
+                $this->_loadLong1();
+                break;
+            case self::OP_LONG4:
+                $this->_loadLong4();
+                break;
+            case self::OP_FLOAT:
+                $this->_loadFloat();
+                break;
+            case self::OP_BINFLOAT:
+                $this->_loadBinFloat();
+                break;
+            case self::OP_STRING:
+                $this->_loadString();
+                break;
+            case self::OP_BINSTRING:
+                $this->_loadBinString();
+                break;
+            case self::OP_SHORT_BINSTRING:
+                $this->_loadShortBinString();
+                break;
+            case self::OP_BINBYTES:
+                $this->_loadBinBytes();
+                break;
+            case self::OP_SHORT_BINBYTES:
+                $this->_loadShortBinBytes();
+                break;
+            case self::OP_UNICODE:
+                $this->_loadUnicode();
+                break;
+            case self::OP_BINUNICODE:
+                $this->_loadBinUnicode();
+                break;
+            case self::OP_MARK:
+                $this->_loadMark();
+                break;
+            case self::OP_LIST:
+                $this->_loadList();
+                break;
+            case self::OP_EMPTY_LIST:
+                $this->_loadEmptyList();
+                break;
+            case self::OP_APPEND:
+                $this->_loadAppend();
+                break;
+            case self::OP_APPENDS:
+                $this->_loadAppends();
+                break;
+            case self::OP_DICT:
+                $this->_loadDict();
+                break;
+            case self::OP_EMPTY_DICT:
+                $this->_loadEmptyDict();
+                break;
+            case self::OP_SETITEM:
+                $this->_loadSetItem();
+                break;
+            case self::OP_SETITEMS:
+                $this->_loadSetItems();
+                break;
+            case self::OP_TUPLE:
+                $this->_loadTuple();
+                break;
+            case self::OP_TUPLE1:
+                $this->_loadTuple1();
+                break;
+            case self::OP_TUPLE2:
+                $this->_loadTuple2();
+                break;
+            case self::OP_TUPLE3:
+                $this->_loadTuple3();
+                break;
+            case self::OP_PROTO:
+                $this->_loadProto();
+                break;
+            default:
+                require_once 'Zend/Serializer/Exception.php';
+                throw new Zend_Serializer_Exception('Invalid or unknown opcode "'.$op.'"');
+        }
+    }
+
+    /**
+     * Load a PUT opcode
+     *
+     * @return void
+     * @throws Zend_Serializer_Exception on missing stack
+     */
+    protected function _loadPut()
+    {
+        $id = (int)$this->_readline();
+
+        $lastStack = count($this->_stack)-1;
+        if (!isset($this->_stack[$lastStack])) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('No stack exist');
+        }
+        $this->_memo[$id] = & $this->_stack[$lastStack];
+    }
+
+    /**
+     * Load a binary PUT
+     *
+     * @return void
+     * @throws Zend_Serializer_Exception on missing stack
+     */
+    protected function _loadBinPut()
+    {
+        $id = ord($this->_read(1));
+
+        $lastStack = count($this->_stack)-1;
+        if (!isset($this->_stack[$lastStack])) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('No stack exist');
+        }
+        $this->_memo[$id] = & $this->_stack[$lastStack];
+    }
+
+    /**
+     * Load a long binary PUT
+     *
+     * @return void
+     * @throws Zend_Serializer_Exception on missing stack
+     */
+    protected function _loadLongBinPut()
+    {
+        $bin = $this->_read(4);
+        if (self::$_isLittleEndian === false) {
+            $bin = strrev($bin);
+        }
+        list(, $id) = unpack('l', $bin);
+
+        $lastStack = count($this->_stack)-1;
+        if (!isset($this->_stack[$lastStack])) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('No stack exist');
+        }
+        $this->_memo[$id] = & $this->_stack[$lastStack];
+    }
+
+    /**
+     * Load a GET operation
+     *
+     * @return void
+     * @throws Zend_Serializer_Exception on missing GET identifier
+     */
+    protected function _loadGet()
+    {
+        $id = (int)$this->_readline();
+
+        if (!array_key_exists($id, $this->_memo)) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('Get id "' . $id . '" not found in momo');
+        }
+        $this->_stack[] = & $this->_memo[$id];
+    }
+
+    /**
+     * Load a binary GET operation
+     *
+     * @return void
+     * @throws Zend_Serializer_Exception on missing GET identifier
+     */
+    protected function _loadBinGet()
+    {
+        $id = ord($this->_read(1));
+
+        if (!array_key_exists($id, $this->_memo)) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('Get id "' . $id . '" not found in momo');
+        }
+        $this->_stack[] = & $this->_memo[$id];
+    }
+
+    /**
+     * Load a long binary GET operation
+     *
+     * @return void
+     * @throws Zend_Serializer_Exception on missing GET identifier
+     */
+    protected function _loadLongBinGet()
+    {
+        $bin = $this->_read(4);
+        if (self::$_isLittleEndian === false) {
+            $bin = strrev($bin);
+        }
+        list(, $id) = unpack('l', $bin);
+
+        if (!array_key_exists($id, $this->_memo)) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('Get id "' . $id . '" not found in momo');
+        }
+        $this->_stack[] = & $this->_memo[$id];
+    }
+
+    /**
+     * Load a NONE operator
+     *
+     * @return void
+     */
+    protected function _loadNone()
+    {
+        $this->_stack[] = null;
+    }
+
+    /**
+     * Load a boolean TRUE operator
+     *
+     * @return void
+     */
+    protected function _loadNewTrue()
+    {
+        $this->_stack[] = true;
+    }
+
+    /**
+     * Load a boolean FALSE operator
+     *
+     * @return void
+     */
+    protected function _loadNewFalse()
+    {
+        $this->_stack[] = false;
+    }
+
+    /**
+     * Load an integer operator
+     *
+     * @return void
+     */
+    protected function _loadInt()
+    {
+        $line = $this->_readline();
+        if ($line === '01') {
+            $this->_stack[] = true;
+        } elseif ($line === '00') {
+            $this->_stack[] = false;
+        } else {
+            $this->_stack[] = (int)$line;
+        }
+    }
+
+    /**
+     * Load a binary integer operator
+     *
+     * @return void
+     */
+    protected function _loadBinInt()
+    {
+        $bin = $this->_read(4);
+        if (self::$_isLittleEndian === false) {
+            $bin = strrev($bin);
+        }
+        list(, $int)    = unpack('l', $bin);
+        $this->_stack[] = $int;
+    }
+
+    /**
+     * Load the first byte of a binary integer
+     *
+     * @return void
+     */
+    protected function _loadBinInt1()
+    {
+        $this->_stack[] = ord($this->_read(1));
+    }
+
+    /**
+     * Load the second byte of a binary integer
+     *
+     * @return void
+     */
+    protected function _loadBinInt2()
+    {
+        $bin = $this->_read(2);
+        list(, $int)    = unpack('v', $bin);
+        $this->_stack[] = $int;
+    }
+
+    /**
+     * Load a long (float) operator
+     *
+     * @return void
+     */
+    protected function _loadLong()
+    {
+        $data = rtrim($this->_readline(), 'L');
+        if ($data === '') {
+            $this->_stack[] = 0;
+        } else {
+            $this->_stack[] = $data;
+        }
+    }
+
+    /**
+     * Load a one byte long integer
+     *
+     * @return void
+     */
+    protected function _loadLong1()
+    {
+        $n    = ord($this->_read(1));
+        $data = $this->_read($n);
+        $this->_stack[] = $this->_decodeBinLong($data);
+    }
+
+    /**
+     * Load a 4 byte long integer
+     *
+     * @return void
+     */
+    protected function _loadLong4()
+    {
+        $nBin = $this->_read(4);
+        if (self::$_isLittleEndian === false) {
+            $nBin = strrev($$nBin);
+        }
+        list(, $n) = unpack('l', $nBin);
+        $data = $this->_read($n);
+
+        $this->_stack[] = $this->_decodeBinLong($data);
+    }
+
+    /**
+     * Load a float value
+     *
+     * @return void
+     */
+    protected function _loadFloat()
+    {
+        $float = (float)$this->_readline();
+        $this->_stack[] = $float;
+    }
+
+    /**
+     * Load a binary float value
+     *
+     * @return void
+     */
+    protected function _loadBinFloat()
+    {
+        $bin = $this->_read(8);
+        if (self::$_isLittleEndian === true) {
+            $bin = strrev($bin);
+        }
+        list(, $float)  = unpack('d', $bin);
+        $this->_stack[] = $float;
+    }
+
+    /**
+     * Load a string
+     *
+     * @return void
+     */
+    protected function _loadString()
+    {
+        $this->_stack[] = $this->_unquoteString((string)$this->_readline());
+    }
+
+    /**
+     * Load a binary string
+     *
+     * @return void
+     */
+    protected function _loadBinString()
+    {
+        $bin = $this->_read(4);
+        if (!self::$_isLittleEndian) {
+            $bin = strrev($bin);
+        }
+        list(, $len)    = unpack('l', $bin);
+        $this->_stack[] = (string)$this->_read($len);
+    }
+
+    /**
+     * Load a short binary string
+     *
+     * @return void
+     */
+    protected function _loadShortBinString()
+    {
+        $len            = ord($this->_read(1));
+        $this->_stack[] = (string)$this->_read($len);
+    }
+
+    /**
+     * Load arbitrary binary bytes
+     *
+     * @return void
+     */
+    protected function _loadBinBytes()
+    {
+        // read byte length
+        $nBin = $this->_read(4);
+        if (self::$_isLittleEndian === false) {
+            $nBin = strrev($$nBin);
+        }
+        list(, $n)      = unpack('l', $nBin);
+        $this->_stack[] = $this->_read($n);
+    }
+
+    /**
+     * Load a single binary byte
+     *
+     * @return void
+     */
+    protected function _loadShortBinBytes()
+    {
+        $n              = ord($this->_read(1));
+        $this->_stack[] = $this->_read($n);
+    }
+
+    /**
+     * Load a unicode string
+     *
+     * @return void
+     */
+    protected function _loadUnicode()
+    {
+        $data    = $this->_readline();
+        $pattern = '/\\\\u([a-fA-F0-9]{4})/u'; // \uXXXX
+        $data    = preg_replace_callback($pattern, array($this, '_convertMatchingUnicodeSequence2Utf8'), $data);
+
+        if (self::$_isPhp6) {
+            $data = unicode_decode($data, 'UTF-8');
+        }
+
+        $this->_stack[] = $data;
+    }
+
+    /**
+     * Convert a unicode sequence to UTF-8
+     *
+     * @param  array $match
+     * @return string
+     */
+    protected function _convertMatchingUnicodeSequence2Utf8(array $match)
+    {
+        return $this->_hex2Utf8($match[1]);
+    }
+
+    /**
+     * Convert a hex string to a UTF-8 string
+     *
+     * @param  string $sequence
+     * @return string
+     * @throws Zend_Serializer_Exception on unmatched unicode sequence
+     */
+    protected function _hex2Utf8($hex)
+    {
+        $uniCode = hexdec($hex);
+
+        if ($uniCode < 0x80) { // 1Byte
+            $utf8Char = chr($uniCode);
+
+        } elseif ($uniCode < 0x800) { // 2Byte
+            $utf8Char = chr(0xC0 | $uniCode >> 6)
+                      . chr(0x80 | $uniCode & 0x3F);
+
+        } elseif ($uniCode < 0x10000) { // 3Byte
+            $utf8Char = chr(0xE0 | $uniCode >> 12)
+                      . chr(0x80 | $uniCode >> 6 & 0x3F)
+                      . chr(0x80 | $uniCode & 0x3F);
+
+        } elseif ($uniCode < 0x110000) { // 4Byte
+            $utf8Char  = chr(0xF0 | $uniCode >> 18)
+                       . chr(0x80 | $uniCode >> 12 & 0x3F)
+                       . chr(0x80 | $uniCode >> 6 & 0x3F)
+                       . chr(0x80 | $uniCode & 0x3F);
+        } else {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('Unsupported unicode character found "' . dechex($uniCode) . '"');
+        }
+
+        return $utf8Char;
+    }
+
+    /**
+     * Load binary unicode sequence
+     *
+     * @return void
+     */
+    protected function _loadBinUnicode()
+    {
+        // read byte length
+        $n = $this->_read(4);
+        if (self::$_isLittleEndian === false) {
+            $n = strrev($n);
+        }
+        list(, $n) = unpack('l', $n);
+        $data      = $this->_read($n);
+
+        if (self::$_isPhp6) {
+            $data = unicode_decode($data, 'UTF-8');
+        }
+
+        $this->_stack[] = $data;
+    }
+
+    /**
+     * Load a marker sequence
+     *
+     * @return void
+     */
+    protected function _loadMark()
+    {
+        $this->_stack[] = $this->_marker;
+    }
+
+    /**
+     * Load an array (list)
+     *
+     * @return void
+     */
+    protected function _loadList()
+    {
+        $k = $this->_lastMarker();
+        $this->_stack[$k] = array();
+
+        // remove all elements after marker
+        $max = count($this->_stack);
+        for ($i = $k+1, $max; $i < $max; $i++) {
+            unset($this->_stack[$i]);
+        }
+    }
+
+    /**
+     * Load an append (to list) sequence
+     *
+     * @return void
+     */
+    protected function _loadAppend()
+    {
+        $value  =  array_pop($this->_stack);
+        $list   =& $this->_stack[count($this->_stack)-1];
+        $list[] =  $value;
+    }
+
+    /**
+     * Load an empty list sequence
+     *
+     * @return void
+     */
+    protected function _loadEmptyList()
+    {
+        $this->_stack[] = array();
+    }
+
+    /**
+     * Load multiple append (to list) sequences at once
+     *
+     * @return void
+     */
+    protected function _loadAppends()
+    {
+        $k    =  $this->_lastMarker();
+        $list =& $this->_stack[$k - 1];
+        $max  =  count($this->_stack);
+        for ($i = $k + 1; $i < $max; $i++) {
+            $list[] = $this->_stack[$i];
+            unset($this->_stack[$i]);
+        }
+        unset($this->_stack[$k]);
+    }
+
+    /**
+     * Load an associative array (Python dictionary)
+     *
+     * @return void
+     */
+    protected function _loadDict()
+    {
+        $k = $this->_lastMarker();
+        $this->_stack[$k] = array();
+
+        // remove all elements after marker
+        $max = count($this->_stack);
+        for($i = $k + 1; $i < $max; $i++) {
+            unset($this->_stack[$i]);
+        }
+    }
+
+    /**
+     * Load an item from a set
+     *
+     * @return void
+     */
+    protected function _loadSetItem()
+    {
+        $value =  array_pop($this->_stack);
+        $key   =  array_pop($this->_stack);
+        $dict  =& $this->_stack[count($this->_stack) - 1];
+        $dict[$key] = $value;
+    }
+
+    /**
+     * Load an empty dictionary
+     *
+     * @return void
+     */
+    protected function _loadEmptyDict()
+    {
+        $this->_stack[] = array();
+    }
+
+    /**
+     * Load set items
+     *
+     * @return void
+     */
+    protected function _loadSetItems()
+    {
+        $k    =  $this->_lastMarker();
+        $dict =& $this->_stack[$k - 1];
+        $max  =  count($this->_stack);
+        for ($i = $k + 1; $i < $max; $i += 2) {
+            $key        = $this->_stack[$i];
+            $value      = $this->_stack[$i + 1];
+            $dict[$key] = $value;
+            unset($this->_stack[$i], $this->_stack[$i+1]);
+        }
+        unset($this->_stack[$k]);
+    }
+
+    /**
+     * Load a tuple
+     *
+     * @return void
+     */
+    protected function _loadTuple()
+    {
+        $k                =  $this->_lastMarker();
+        $this->_stack[$k] =  array();
+        $tuple            =& $this->_stack[$k];
+        $max              =  count($this->_stack);
+        for($i = $k + 1; $i < $max; $i++) {
+            $tuple[] = $this->_stack[$i];
+            unset($this->_stack[$i]);
+        }
+    }
+
+    /**
+     * Load single item tuple
+     *
+     * @return void
+     */
+    protected function _loadTuple1()
+    {
+        $value1 = array_pop($this->_stack);
+        $this->_stack[] = array($value1);
+    }
+
+    /**
+     * Load two item tuple
+     *
+     * @return void
+     */
+    protected function _loadTuple2()
+    {
+        $value2 = array_pop($this->_stack);
+        $value1 = array_pop($this->_stack);
+        $this->_stack[] = array($value1, $value2);
+    }
+
+    /**
+     * Load three item tuple
+     *
+     * @return void
+     */
+    protected function _loadTuple3() {
+        $value3 = array_pop($this->_stack);
+        $value2 = array_pop($this->_stack);
+        $value1 = array_pop($this->_stack);
+        $this->_stack[] = array($value1, $value2, $value3);
+    }
+
+    /**
+     * Load a proto value
+     *
+     * @return void
+     * @throws Zend_Serializer_Exception if Pickle version does not support this feature
+     */
+    protected function _loadProto()
+    {
+        $proto = ord($this->_read(1));
+        if ($proto < 2 || $proto > 3) {
+            require_once 'Zend/Serializer/Excception.php';
+            throw new Zend_Serializer_Exception('Invalid protocol version detected');
+        }
+        $this->_protocol = $proto;
+    }
+
+    /* unserialize helper */
+
+    /**
+     * Read a segment of the pickle
+     *
+     * @param  mixed $len
+     * @return string
+     * @throws Zend_Serializer_Exception if position matches end of data
+     */
+    protected function _read($len)
+    {
+        if (($this->_pos + $len) > $this->_pickleLen) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('End of data');
+        }
+
+        $this->_pos+= $len;
+        return substr($this->_pickle, ($this->_pos - $len), $len);
+    }
+
+    /**
+     * Read a line of the pickle at once
+     *
+     * @return string
+     * @throws Zend_Serializer_Exception if no EOL character found
+     */
+    protected function _readline()
+    {
+        $eolLen = 2;
+        $eolPos = strpos($this->_pickle, "\r\n", $this->_pos);
+        if ($eolPos === false) {
+            $eolPos = strpos($this->_pickle, "\n", $this->_pos);
+            $eolLen = 1;
+        }
+
+        if ($eolPos === false) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('No new line found');
+        }
+        $ret        = substr($this->_pickle, $this->_pos, $eolPos-$this->_pos);
+        $this->_pos = $eolPos + $eolLen;
+
+        return $ret;
+    }
+
+    /**
+     * Unquote/Unescape a quoted string
+     *
+     * @param  string $str quoted string
+     * @return string unquoted string
+     */
+    protected function _unquoteString($str)
+    {
+        $quoteArr = array_flip(self::$_quoteString);
+
+        if ($str{0} == '"') {
+            $quoteArr['\\"'] = '"';
+        } else {
+            $quoteArr["\\'"] = "'";
+        }
+
+        return strtr(substr(trim($str), 1, -1), $quoteArr);
+    }
+
+    /**
+     * Return last marker position in stack
+     *
+     * @return int
+     */
+    protected function _lastMarker()
+    {
+        for ($k = count($this->_stack)-1; $k >= 0; $k -= 1) {
+            if ($this->_stack[$k] === $this->_marker) {
+                break;
+            }
+        }
+        return $k;
+    }
+
+    /**
+     * Decode a binary long sequence
+     *
+     * @param  string $data
+     * @return int|float|string
+     */
+    protected function _decodeBinLong($data)
+    {
+        $nbytes = strlen($data);
+
+        if ($nbytes == 0) {
+            return 0;
+        }
+
+        $long = 0;
+
+        if ($nbytes > 7) {
+            if (!extension_loaded('bcmath')) {
+                return INF;
+            }
+
+            for ($i=0; $i<$nbytes; $i++) {
+                $long = bcadd($long, bcmul(ord($data{$i}), bcpow(256, $i, 0)));
+            }
+            if (0x80 <= ord($data{$nbytes-1})) {
+                $long = bcsub($long, bcpow(2, $nbytes * 8));
+            }
+
+        } else {
+            for ($i=0; $i<$nbytes; $i++) {
+                $long+= ord($data{$i}) * pow(256, $i);
+            }
+            if (0x80 <= ord($data{$nbytes-1})) {
+                $long-= pow(2, $nbytes * 8);
+                // $long-= 1 << ($nbytes * 8);
+            }
+        }
+
+        return $long;
+    }
+}

+ 118 - 0
library/Zend/Serializer/Adapter/Wddx.php

@@ -0,0 +1,118 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @subpackage Adapter
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/** @see Zend_Serializer_Adapter_AdapterAbstract */
+require_once 'Zend/Serializer/Adapter/AdapterAbstract.php';
+
+/**
+ * @link       http://www.infoloom.com/gcaconfs/WEB/chicago98/simeonov.HTM
+ * @link       http://en.wikipedia.org/wiki/WDDX
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @subpackage Adapter
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Serializer_Adapter_Wddx extends Zend_Serializer_Adapter_AdapterAbstract
+{
+    /**
+     * @var array Default options
+     */
+    protected $_options = array(
+        'comment' => null,
+    );
+
+    /**
+     * Constructor
+     * 
+     * @param  array $opts 
+     * @return void
+     * @throws Zend_Serializer_Exception if wddx extension not found
+     */
+    public function __construct($opts = array())
+    {
+        if (!extension_loaded('wddx')) {
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception('PHP extension "wddx" is required for this adapter');
+        }
+
+        parent::__construct($opts);
+    }
+
+    /**
+     * Serialize PHP to WDDX
+     * 
+     * @param  mixed $value 
+     * @param  array $opts 
+     * @return string
+     * @throws Zend_Serializer_Exception on wddx error
+     */
+    public function serialize($value, array $opts = array())
+    {
+        $opts = $opts + $this->_options;
+
+        if (isset($opts['comment']) && $opts['comment']) {
+            $wddx = wddx_serialize_value($value, (string)$this->_options['comment']);
+        } else {
+            $wddx = wddx_serialize_value($value);
+        }
+
+        if ($wddx === false) {
+            $lastErr = error_get_last();
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception($lastErr['message']);
+        }
+        return $wddx;
+    }
+
+    /**
+     * Unserialize from WDDX to PHP
+     * 
+     * @param  string $wddx 
+     * @param  array $opts 
+     * @return mixed
+     * @throws Zend_Serializer_Exception on wddx error
+     */
+    public function unserialize($wddx, array $opts = array())
+    {
+        $ret = wddx_deserialize($wddx);
+
+        if ($ret === null) {
+            // check if the returned NULL is valid
+            // or based on an invalid wddx string
+            try {
+                $simpleXml = new SimpleXMLElement($wddx);
+                if (isset($simpleXml->data[0]->null[0])) {
+                    return null; // valid null
+                }
+                $errMsg = 'Can\'t unserialize wddx string';
+            } catch (Exception $e) {
+                $errMsg = $e->getMessage();
+            }
+
+            require_once 'Zend/Serializer/Exception.php';
+            throw new Zend_Serializer_Exception($errMsg);
+        }
+
+        return $ret;
+    }
+}

+ 33 - 0
library/Zend/Serializer/Exception.php

@@ -0,0 +1,33 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/** @see Zend_Exception */
+require_once 'Zend/Exception.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Serializer
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Serializer_Exception extends Zend_Exception
+{
+}

+ 2 - 0
tests/Zend/AllTests.php

@@ -79,6 +79,7 @@ require_once 'Zend/RegistryTest.php';
 require_once 'Zend/Rest/AllTests.php';
 require_once 'Zend/Queue/AllTests.php';
 require_once 'Zend/Search/Lucene/AllTests.php';
+require_once 'Zend/Serializer/AllTests.php';
 require_once 'Zend/Server/AllTests.php';
 require_once 'Zend/Service/AllTests.php';
 require_once 'Zend/Session/AllTests.php';
@@ -210,6 +211,7 @@ class Zend_AllTests
         $suite->addTest(Zend_Rest_AllTests::suite());
         $suite->addTest(Zend_Queue_AllTests::suite());
         $suite->addTest(Zend_Search_Lucene_AllTests::suite());
+        $suite->addTest(Zend_Serializer_AllTests::suite());
         $suite->addTest(Zend_Server_AllTests::suite());
         $suite->addTest(Zend_Service_AllTests::suite());
         $suite->addTest(Zend_Tag_AllTests::suite());

+ 77 - 0
tests/Zend/Serializer/Adapter/AllTests.php

@@ -0,0 +1,77 @@
+<?php
+
+/**
+ * Test helper
+ */
+require_once dirname(__FILE__) . '/../../../TestHelper.php';
+
+if (!defined('PHPUnit_MAIN_METHOD')) {
+    define('PHPUnit_MAIN_METHOD', 'Zend_Serializer_Adapter_AllTests::main');
+}
+
+/** @see Zend_Serializer_Adapter_PhpSerializeTest */
+require_once dirname(__FILE__) . '/PhpSerializeTest.php';
+
+/** @see Zend_Serializer_Adapter_PhpCodeTest */
+require_once dirname(__FILE__) . '/PhpCodeTest.php';
+
+/** @see Zend_Serializer_Adapter_JsonTest */
+require_once dirname(__FILE__) . '/JsonTest.php';
+
+/** @see Zend_Serializer_Adapter_Amf0Test */
+require_once dirname(__FILE__) . '/Amf0Test.php';
+
+/** @see Zend_Serializer_Adapter_Amf3Test */
+require_once dirname(__FILE__) . '/Amf3Test.php';
+
+/** @see Zend_Serializer_Adapter_WddxTest */
+require_once dirname(__FILE__) . '/WddxTest.php';
+
+/** @see Zend_Serializer_Adapter_IgbinaryTest */
+require_once dirname(__FILE__) . '/IgbinaryTest.php';
+
+/** @see Zend_Serializer_Adapter_PythonPickleSerializeProtocol0Test */
+require_once dirname(__FILE__) . '/PythonPickleSerializeProtocol0Test.php';
+
+/** @see Zend_Serializer_Adapter_PythonPickleSerializeProtocol1Test */
+require_once dirname(__FILE__) . '/PythonPickleSerializeProtocol1Test.php';
+
+/** @see Zend_Serializer_Adapter_PythonPickleUnserializeTest */
+require_once dirname(__FILE__) . '/PythonPickleUnserializeTest.php';
+
+class Zend_Serializer_Adapter_AllTests
+{
+    public static function main()
+    {
+        PHPUnit_TextUI_TestRunner::run(self::suite());
+    }
+
+    public static function suite()
+    {
+        $suite = new PHPUnit_Framework_TestSuite('Zend');
+
+        $suite->addTestSuite('Zend_Serializer_Adapter_PhpSerializeTest');
+        $suite->addTestSuite('Zend_Serializer_Adapter_PhpCodeTest');
+        $suite->addTestSuite('Zend_Serializer_Adapter_JsonTest');
+        $suite->addTestSuite('Zend_Serializer_Adapter_Amf0Test');
+        $suite->addTestSuite('Zend_Serializer_Adapter_Amf3Test');
+
+        if (defined('TESTS_ZEND_SERIALIZER_ADAPTER_WDDX_ENABLED') && TESTS_ZEND_SERIALIZER_ADAPTER_WDDX_ENABLED) {
+            $suite->addTestSuite('Zend_Serializer_Adapter_WddxTest');
+        }
+
+        if (defined('TESTS_ZEND_SERIALIZER_ADAPTER_IGBINARY_ENABLED') && TESTS_ZEND_SERIALIZER_ADAPTER_IGBINARY_ENABLED) {
+            $suite->addTestSuite('Zend_Serializer_Adapter_IgbinaryTest');
+        }
+
+        $suite->addTestSuite('Zend_Serializer_Adapter_PythonPickleSerializeProtocol0Test');
+        $suite->addTestSuite('Zend_Serializer_Adapter_PythonPickleSerializeProtocol1Test');
+        $suite->addTestSuite('Zend_Serializer_Adapter_PythonPickleUnserializeTest');
+
+        return $suite;
+    }
+}
+
+if (PHPUnit_MAIN_METHOD == 'Zend_Serializer_Adapter_AllTests::main') {
+    Zend_Serializer_Adapter_AllTests::main();
+}

+ 58 - 0
tests/Zend/Serializer/Adapter/Amf0Test.php

@@ -0,0 +1,58 @@
+<?php
+/**
+ * @package    Zend_Cache
+ * @subpackage UnitTests
+ */
+
+/** @see Zend_Serializer_Adapter_Amf0 */
+require_once 'Zend/Serializer/Adapter/Amf0.php';
+
+/**
+ * PHPUnit test case
+ */
+require_once 'PHPUnit/Framework/TestCase.php';
+
+/**
+ * @package    Zend_Serializer
+ * @subpackage UnitTests
+ */
+class Zend_Serializer_Adapter_Amf0Test extends PHPUnit_Framework_TestCase
+{
+
+    private $_adapter;
+
+    public function setUp()
+    {
+        $this->_adapter = new Zend_Serializer_Adapter_Amf0();
+    }
+
+    public function tearDown()
+    {
+        $this->_adapter = null;
+    }
+
+    /**
+     * Simple test to serialize a value using Zend_Amf_Parser_Amf0_Serializer
+     * -> This only tests the usage of Zend_Amf @see Zend_Amf_AllTests
+     */
+    public function testSerialize() {
+        $value    = true;
+        $expected = "\x01\x01"; // Amf0 -> true
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    /**
+     * Simple test to serialize a value using Zend_Amf_Parser_Amf0_Deserializer
+     * -> This only tests the usage of Zend_Amf @see Zend_Amf_AllTests
+     */
+    public function testUnserialize() {
+        $expected   = true;
+        $value      = "\x01\x01"; // Amf0 -> true
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+}

+ 58 - 0
tests/Zend/Serializer/Adapter/Amf3Test.php

@@ -0,0 +1,58 @@
+<?php
+/**
+ * @package    Zend_Cache
+ * @subpackage UnitTests
+ */
+
+/** @see Zend_Serializer_Adapter_Amf3 */
+require_once 'Zend/Serializer/Adapter/Amf3.php';
+
+/**
+ * PHPUnit test case
+ */
+require_once 'PHPUnit/Framework/TestCase.php';
+
+/**
+ * @package    Zend_Serializer
+ * @subpackage UnitTests
+ */
+class Zend_Serializer_Adapter_Amf3Test extends PHPUnit_Framework_TestCase
+{
+
+    private $_adapter;
+
+    public function setUp()
+    {
+        $this->_adapter = new Zend_Serializer_Adapter_Amf3();
+    }
+
+    public function tearDown()
+    {
+        $this->_adapter = null;
+    }
+
+    /**
+     * Simple test to serialize a value using Zend_Amf_Parser_Amf3_Serializer
+     * -> This only tests the usage of Zend_Amf @see Zend_Amf_AllTests
+     */
+    public function testSerialize() {
+        $value    = true;
+        $expected = "\x03"; // Amf3 -> true
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    /**
+     * Simple test to unserialize a value using Zend_Amf_Parser_Amf3_Deserializer
+     * -> This only tests the usage of Zend_Amf @see Zend_Amf_AllTests
+     */
+    public function testUnserialize() {
+        $expected   = true;
+        $value      = "\x03"; // Amf3 -> true
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+}

+ 120 - 0
tests/Zend/Serializer/Adapter/IgbinaryTest.php

@@ -0,0 +1,120 @@
+<?php
+/**
+ * @package    Zend_Cache
+ * @subpackage UnitTests
+ */
+
+/** @see Zend_Serializer_Adapter_Igbinary */
+require_once 'Zend/Serializer/Adapter/Igbinary.php';
+
+/**
+ * PHPUnit test case
+ */
+require_once 'PHPUnit/Framework/TestCase.php';
+
+/**
+ * @package    Zend_Serializer
+ * @subpackage UnitTests
+ */
+class Zend_Serializer_Adapter_IgbinaryTest extends PHPUnit_Framework_TestCase
+{
+
+    private $_adapter;
+
+    public function setUp()
+    {
+        $this->_adapter = new Zend_Serializer_Adapter_Igbinary();
+    }
+
+    public function tearDown()
+    {
+        $this->_adapter = null;
+    }
+
+    public function testSerializeString() {
+        $value    = 'test';
+        $expected = igbinary_serialize($value);
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeFalse() {
+        $value    = false;
+        $expected = igbinary_serialize($value);
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeNull() {
+        $value    = null;
+        $expected = igbinary_serialize($value);
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeNumeric() {
+        $value    = 100;
+        $expected = igbinary_serialize($value);
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeObject() {
+        $value    = new stdClass();
+        $expected = igbinary_serialize($value);
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeString() {
+        $expected = 'test';
+        $value    = igbinary_serialize($expected);
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeFalse() {
+        $expected = false;
+        $value    = igbinary_serialize($expected);
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeNull() {
+        $expected = null;
+        $value    = igbinary_serialize($expected);
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeNumeric() {
+        $expected = 100;
+        $value    = igbinary_serialize($expected);
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeObject() {
+        $expected = new stdClass();
+        $value    = igbinary_serialize($expected);
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserialzeInvalid() {
+        $value = "\0\1\r\n";
+        $this->setExpectedException('Zend_Serializer_Exception');
+        $this->_adapter->unserialize($value);
+    }
+
+}

+ 130 - 0
tests/Zend/Serializer/Adapter/JsonTest.php

@@ -0,0 +1,130 @@
+<?php
+/**
+ * @package    Zend_Cache
+ * @subpackage UnitTests
+ */
+
+/** @see Zend_Serializer_Adapter_Json */
+require_once 'Zend/Serializer/Adapter/Json.php';
+
+/**
+ * PHPUnit test case
+ */
+require_once 'PHPUnit/Framework/TestCase.php';
+
+/**
+ * @package    Zend_Serializer
+ * @subpackage UnitTests
+ */
+class Zend_Serializer_Adapter_JsonTest extends PHPUnit_Framework_TestCase
+{
+
+    private $_adapter;
+
+    public function setUp()
+    {
+        $this->_adapter = new Zend_Serializer_Adapter_Json();
+    }
+
+    public function tearDown()
+    {
+        $this->_adapter = null;
+    }
+
+    public function testSerializeString() {
+        $value    = 'test';
+        $expected = '"test"';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeFalse() {
+        $value    = false;
+        $expected = 'false';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeNull() {
+        $value    = null;
+        $expected = 'null';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeNumeric() {
+        $value    = 100;
+        $expected = '100';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeObject() {
+        $value       = new stdClass();
+        $value->test = "test";
+        $expected    = '{"test":"test"}';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeString() {
+        $value    = '"test"';
+        $expected = 'test';
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeFalse() {
+        $value    = 'false';
+        $expected = false;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeNull() {
+        $value    = 'null';
+        $expected = null;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeNumeric() {
+        $value    = '100';
+        $expected = 100;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeAsArray() {
+        $value    = '{"test":"test"}';
+        $expected = array('test' => 'test');
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeAsObject() {
+        $value      = '{"test":"test"}';
+        $expected   = new stdClass();
+        $expected->test = 'test';
+
+        $data = $this->_adapter->unserialize($value, array('objectDecodeType' => Zend_Json::TYPE_OBJECT));
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserialzeInvalid() {
+        $value = 'not a serialized string';
+        $this->setExpectedException('Zend_Serializer_Exception');
+        $this->_adapter->unserialize($value);
+    }
+
+}

+ 122 - 0
tests/Zend/Serializer/Adapter/PhpCodeTest.php

@@ -0,0 +1,122 @@
+<?php
+/**
+ * @package    Zend_Cache
+ * @subpackage UnitTests
+ */
+
+/** @see Zend_Serializer_Adapter_PhpCode */
+require_once 'Zend/Serializer/Adapter/PhpCode.php';
+
+/**
+ * PHPUnit test case
+ */
+require_once 'PHPUnit/Framework/TestCase.php';
+
+/**
+ * @package    Zend_Serializer
+ * @subpackage UnitTests
+ */
+class Zend_Serializer_Adapter_PhpCodeTest extends PHPUnit_Framework_TestCase
+{
+
+    private $_adapter;
+
+    public function setUp()
+    {
+        $this->_adapter = new Zend_Serializer_Adapter_PhpCode();
+    }
+
+    public function tearDown()
+    {
+        $this->_adapter = null;
+    }
+
+    public function testSerializeString() {
+        $value      = 'test';
+        $expected   = "'test'";
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeFalse() {
+        $value    = false;
+        $expected = 'false';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeNull() {
+        $value    = null;
+        $expected = 'NULL';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeNumeric() {
+        $value    = 100.12345;
+        $expected = '100.12345';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeObject() {
+        $value    = new stdClass();
+        $expected = "stdClass::__set_state(array(\n))";
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeString() {
+        $value    = "'test'";
+        $expected = 'test';
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeFalse() {
+        $value    = 'false';
+        $expected = false;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeNull() {
+        $value    = 'NULL';
+        $expected = null;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeNumeric() {
+        $value    = '100';
+        $expected = 100;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+/* TODO: PHP Fatal error:  Call to undefined method stdClass::__set_state()
+    public function testUnserializeObject() {
+        $value    = "stdClass::__set_state(array(\n))";
+        $expected = new stdClass();
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+*/
+
+    public function testUnserialzeInvalid() {
+        $value = 'not a serialized string';
+        $this->setExpectedException('Zend_Serializer_Exception');
+        $this->_adapter->unserialize($value);
+    }
+
+}

+ 120 - 0
tests/Zend/Serializer/Adapter/PhpSerializeTest.php

@@ -0,0 +1,120 @@
+<?php
+/**
+ * @package    Zend_Cache
+ * @subpackage UnitTests
+ */
+
+/** @see Zend_Serializer_Adapter_PhpSerialize */
+require_once 'Zend/Serializer/Adapter/PhpSerialize.php';
+
+/**
+ * PHPUnit test case
+ */
+require_once 'PHPUnit/Framework/TestCase.php';
+
+/**
+ * @package    Zend_Serializer
+ * @subpackage UnitTests
+ */
+class Zend_Serializer_Adapter_PhpSerializeTest extends PHPUnit_Framework_TestCase
+{
+
+    private $_adapter;
+
+    public function setUp()
+    {
+        $this->_adapter = new Zend_Serializer_Adapter_PhpSerialize();
+    }
+
+    public function tearDown()
+    {
+        $this->_adapter = null;
+    }
+
+    public function testSerializeString() {
+        $value      = 'test';
+        $expected   = 's:4:"test";';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeFalse() {
+        $value    = false;
+        $expected = 'b:0;';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeNull() {
+        $value    = null;
+        $expected = 'N;';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeNumeric() {
+        $value    = 100;
+        $expected = 'i:100;';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeObject() {
+        $value    = new stdClass();
+        $expected = 'O:8:"stdClass":0:{}';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeString() {
+        $value    = 's:4:"test";';
+        $expected = 'test';
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeFalse() {
+        $value    = 'b:0;';
+        $expected = false;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeNull() {
+        $value    = 'N;';
+        $expected = null;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeNumeric() {
+        $value    = 'i:100;';
+        $expected = 100;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeObject() {
+        $value    = 'O:8:"stdClass":0:{}';
+        $expected = new stdClass();
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserialzeInvalid() {
+        $value = 'not a serialized string';
+        $this->setExpectedException('Zend_Serializer_Exception');
+        $this->_adapter->unserialize($value);
+    }
+
+}

+ 146 - 0
tests/Zend/Serializer/Adapter/PythonPickleSerializeProtocol0Test.php

@@ -0,0 +1,146 @@
+<?php
+/**
+ * @package    Zend_Cache
+ * @subpackage UnitTests
+ */
+
+/** @see Zend_Serializer_Adapter_PythonPickle */
+require_once 'Zend/Serializer/Adapter/PythonPickle.php';
+
+/**
+ * PHPUnit test case
+ */
+require_once 'PHPUnit/Framework/TestCase.php';
+
+/**
+ * @package    Zend_Serializer
+ * @subpackage UnitTests
+ */
+class Zend_Serializer_Adapter_PythonPickleSerializeProtocol0Test extends PHPUnit_Framework_TestCase
+{
+
+    private $_adapter;
+
+    public function setUp()
+    {
+        $this->_adapter = new Zend_Serializer_Adapter_PythonPickle(array('protocol' => 0));
+    }
+
+    public function tearDown()
+    {
+        $this->_adapter = null;
+    }
+
+    public function testSerializeNull() {
+        $value      = null;
+        $expected   = 'N.';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeTrue() {
+        $value      = true;
+        $expected   = "I01\r\n.";
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeFalse() {
+        $value      = false;
+        $expected   = "I00\r\n.";
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeInt() {
+        $value      = -12345;
+        $expected   = "I-12345\r\n.";
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeFloat() {
+        $value      = -12345.6789;
+        $expected   = "F-12345.6789\r\n.";
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeString() {
+        $value      = 'test';
+        $expected   = "S'test'\r\np0\r\n.";
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeStringWithSpecialChars() {
+        $value      = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
+                    . "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
+                    . "\xff\\\"'";
+        $expected   = "S'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\x0c\\r\\x0e\\x0f"
+                    . "\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f"
+                    . "\\xff\\\\\"\\''\r\n"
+                    . "p0\r\n.";
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeArrayList() {
+        $value      = array('1', '2', 'test');
+        $expected   = "(lp0\r\n"
+                    . "S'1'\r\n"
+                    . "p1\r\n"
+                    . "aS'2'\r\n"
+                    . "p2\r\n"
+                    . "aS'test'\r\n"
+                    . "p3\r\n"
+                    . "a.";
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeArrayDict() {
+        $value    = array('1', '2', 'three' => 'test');
+        $expected = "(dp0\r\n"
+                  . "I0\r\n"
+                  . "S'1'\r\n"
+                  . "p1\r\n"
+                  . "sI1\r\n"
+                  . "S'2'\r\n"
+                  . "p2\r\n"
+                  . "sS'three'\r\n"
+                  . "p3\r\n"
+                  . "S'test'\r\n"
+                  . "p4\r\n"
+                  . "s.";
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeObject() {
+        $value = new StdClass();
+        $value->test  = 'test';
+        $value->test2 = 2;
+        $expected = "(dp0\r\n"
+                  . "S'test'\r\n"
+                  . "p1\r\n"
+                  . "g1\r\n"
+                  . "sS'test2'\r\n"
+                  . "p2\r\n"
+                  . "I2\r\n"
+                  . "s.";
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+}

+ 113 - 0
tests/Zend/Serializer/Adapter/PythonPickleSerializeProtocol1Test.php

@@ -0,0 +1,113 @@
+<?php
+/**
+ * @package    Zend_Cache
+ * @subpackage UnitTests
+ */
+
+/** @see Zend_Serializer_Adapter_PythonPickle */
+require_once 'Zend/Serializer/Adapter/PythonPickle.php';
+
+/**
+ * PHPUnit test case
+ */
+require_once 'PHPUnit/Framework/TestCase.php';
+
+/**
+ * @package    Zend_Serializer
+ * @subpackage UnitTests
+ */
+class Zend_Serializer_Adapter_PythonPickleSerializeProtocol1Test extends PHPUnit_Framework_TestCase
+{
+
+    private $_adapter;
+
+    public function setUp()
+    {
+        $this->_adapter = new Zend_Serializer_Adapter_PythonPickle(array('protocol' => 1));
+    }
+
+    public function tearDown()
+    {
+        $this->_adapter = null;
+    }
+
+    public function testSerializeNull() {
+        $value    = null;
+        $expected = 'N.';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeTrue() {
+        $value    = true;
+        $expected = "I01\r\n.";
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeFalse() {
+        $value    = false;
+        $expected = "I00\r\n.";
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeBinInt1() {
+        $value    = 255;
+        $expected = "K\xff.";
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeBinInt2() {
+        $value    = 256;
+        $expected = "M\x00\x01.";
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeBinInt() {
+        $value    = -2;
+        $expected = "J\xfe\xff\xff\xff.";
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeBinFloat() {
+        $value    = -12345.6789;
+        $expected = "G\xc0\xc8\x1c\xd6\xe6\x31\xf8\xa1.";
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeShortBinString() {
+        $value    = 'test';
+        $expected = "U\x04test"
+                  . "q\x00.";
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeBinString() {
+        $value    = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
+                  . "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
+                  . "01234567890123456789012345678901234567890123456789012345";
+        $expected = "T\x00\x01\x00\x00"
+                  . "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
+                  . "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
+                  . "01234567890123456789012345678901234567890123456789012345"
+                  . "q\x00.";
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+}

+ 334 - 0
tests/Zend/Serializer/Adapter/PythonPickleUnserializeTest.php

@@ -0,0 +1,334 @@
+<?php
+/**
+ * @package    Zend_Cache
+ * @subpackage UnitTests
+ */
+
+/** @see Zend_Serializer_Adapter_PythonPickle */
+require_once 'Zend/Serializer/Adapter/PythonPickle.php';
+
+/**
+ * PHPUnit test case
+ */
+require_once 'PHPUnit/Framework/TestCase.php';
+
+/**
+ * @package    Zend_Serializer
+ * @subpackage UnitTests
+ */
+class Zend_Serializer_Adapter_PythonPickleUnserializeTest extends PHPUnit_Framework_TestCase
+{
+
+    private $_adapter;
+
+    public function setUp()
+    {
+        $this->_adapter = new Zend_Serializer_Adapter_PythonPickle();
+    }
+
+    public function tearDown()
+    {
+        $this->_adapter = null;
+    }
+
+    public function testUnserializeNone() {
+        $value    = "N.";
+        $expected = null;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeNewTrue() {
+        $value    = "\x80\x02\x88.";
+        $expected = true;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeNewFalse() {
+        $value    = "\x80\x02\x89.";
+        $expected = false;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeIntTrue() {
+        $value    = "I01\r\n.";
+        $expected = true;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeIntFalse() {
+        $value    = "I00\r\n.";
+        $expected = false;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeInt() {
+        $value    = "I1\r\n.";
+        $expected = 1;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeBinInt() {
+        $value    = "\x80\x02J\xc7\xcf\xff\xff.";
+        $expected = -12345;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeBinInt1() {
+        $value    = "\x80\x02K\x02.";
+        $expected = 2;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeBinInt2() {
+        $value    = "\x80\x02M\x00\x01.";
+        $expected = 256;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeLong() {
+        $value    = "L9876543210L\r\n.";
+        $expected = '9876543210';
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeLong1() {
+        $value    = "\x80\x02\x8a\x05\xea\x16\xb0\x4c\x02.";
+        $expected = '9876543210';
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeLong4Positiv() {
+        $value    = "\x80\x02\x8b\x07\x00\x00\x00"
+                  . str_pad("\xff", 7, "\x7f")
+                  . ".";
+        $expected = '35887507618889727';
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeLong4Negativ() {
+        $value    = "\x80\x02\x8b\x07\x00\x00\x00"
+                  . str_pad("\x00", 7, "\x9f")
+                  . ".";
+        $expected = '-27127564814278912';
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeLong4InfBcMath() {
+        $value    = "\x80\x02\x8b\x08\x00\x00\x00"
+                  . str_pad("\x00", 8, "\x9f")
+                  . ".";
+        if (extension_loaded('bcmath')) {
+            $expected = '-6944656592455360768';
+        } else {
+            $expected = INF;
+        }
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeFloat() {
+        $value    = "F-12345.6789\r\n.";
+        $expected = -12345.6789;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeBinFloat() {
+        $value    = "\x80\x02G\xc0\xc8\x1c\xd6\xe6\x31\xf8\xa1.";
+        $expected = -12345.6789;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeString() {
+        $value    = "S'test'\r\np0\r\n.";
+        $expected = 'test';
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeStringDoubleQuotes() {
+        $value    = "S\"'t'e's't'\"\r\np0\r\n.";
+        $expected = "'t'e's't'";
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeStringWithSpecialChars() {
+        $value    = "S'\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\x08\\t\\n\\x0b\\x0c\\r\\x0e\\x0f"
+                  . "\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f"
+                  . "\\xff\\\\\"\\''\r\n"
+                  . "p0\r\n.";
+        $expected = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
+                  . "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
+                  . "\xff\\\"'";
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeBinString() {
+        $value    = "\x80\x02T\x00\x01\x00\x00"
+                  . "01234567890123456789012345678901234567890123456789"
+                  . "01234567890123456789012345678901234567890123456789"
+                  . "01234567890123456789012345678901234567890123456789"
+                  . "01234567890123456789012345678901234567890123456789"
+                  . "01234567890123456789012345678901234567890123456789012345"
+                  . "q\x00.";
+        $expected = '01234567890123456789012345678901234567890123456789'
+                  . '01234567890123456789012345678901234567890123456789'
+                  . '01234567890123456789012345678901234567890123456789'
+                  . '01234567890123456789012345678901234567890123456789'
+                  . '01234567890123456789012345678901234567890123456789012345';
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeShortBinString() {
+        $value    = "\x80\x02U\x04"
+                  . "test"
+                  . "q\x00.";
+        $expected = 'test';
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeUnicode() {
+        $value    = "Vtest\\u0400\r\n" // test + ` + E
+                  . "p0\r\n"
+                  . ".";
+        $expected = "test\xd0\x80";
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeBinUnicode() {
+        $value    = "\x80\x02" . "X\x07\x00\x00\x00" . "test\xd0\x80\n.";
+        $expected = "test\xd0\x80\n"; // test + ` + E + \n
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeListAppend() {
+        $value = "(lp0\r\n"
+               . "I1\r\n"
+               . "aI2\r\n"
+               . "aI3\r\n"
+               . "a.";
+        $expected = array(1,2,3);
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeEmptyListAppends() {
+        $value    = "\x80\x02]q\x00(K\x01K\x02K\x03e.";
+        $expected = array(1,2,3);
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeDictSetItem() {
+        $value = "(dp0\r\n"
+               . "S'test1'\r\n"
+               . "p1\r\n"
+               . "I1\r\n"
+               . "sI0\r\n"
+               . "I2\r\n"
+               . "sS'test3'\r\n"
+               . "p2\r\n"
+               . "g2\r\n"
+               . "s.";
+        $expected = array('test1' => 1, 0 => 2, 'test3' => 'test3');
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeEmptyDictSetItems() {
+        $value    = "\x80\x02}q\x00(U\x05test1q\x01K\x01K\x00K\x02U\x05test3q\x02h\x02u.";
+        $expected = array('test1' => 1, 0 => 2, 'test3' => 'test3');
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeTuple() {
+        $value    = "(I1\r\n"
+                  . "I2\r\n"
+                  . "I3\r\n"
+                  . "tp0\r\n"
+                  . ".";
+        $expected = array(1,2,3);
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeTuple1() {
+        $value    = "\x80\x02K\x01\x85q\x00.";
+        $expected = array(1);
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeTuple2() {
+        $value    = "\x80\x02K\x01K\x02\x86q\x00.";
+        $expected = array(1,2);
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeTuple3() {
+        $value    = "\x80\x02K\x01K\x02K\x03\x87q\x00.";
+        $expected = array(1,2,3);
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserialzeInvalid() {
+        $value = 'not a serialized string';
+        $this->setExpectedException('Zend_Serializer_Exception');
+        $this->_adapter->unserialize($value);
+    }
+
+}

+ 179 - 0
tests/Zend/Serializer/Adapter/WddxTest.php

@@ -0,0 +1,179 @@
+<?php
+/**
+ * @package    Zend_Cache
+ * @subpackage UnitTests
+ */
+
+/** @see Zend_Serializer_Adapter_Wddx */
+require_once 'Zend/Serializer/Adapter/Wddx.php';
+
+/**
+ * PHPUnit test case
+ */
+require_once 'PHPUnit/Framework/TestCase.php';
+
+/**
+ * @package    Zend_Serializer
+ * @subpackage UnitTests
+ */
+class Zend_Serializer_Adapter_WddxTest extends PHPUnit_Framework_TestCase
+{
+
+    private $_adapter;
+
+    public function setUp()
+    {
+        $this->_adapter = new Zend_Serializer_Adapter_Wddx();
+    }
+
+    public function tearDown()
+    {
+        $this->_adapter = null;
+    }
+
+    public function testSerializeString() {
+        $value    = 'test';
+        $expected = '<wddxPacket version=\'1.0\'><header/>'
+                  . '<data><string>test</string></data></wddxPacket>';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeStringWithComment() {
+        $value    = 'test';
+        $expected = '<wddxPacket version=\'1.0\'><header><comment>a test comment</comment></header>'
+                  . '<data><string>test</string></data></wddxPacket>';
+
+        $data = $this->_adapter->serialize($value, array('comment' => 'a test comment'));
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeFalse() {
+        $value    = false;
+        $expected = '<wddxPacket version=\'1.0\'><header/>'
+                  . '<data><boolean value=\'false\'/></data></wddxPacket>';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeTrue() {
+        $value    = true;
+        $expected = '<wddxPacket version=\'1.0\'><header/>'
+                  . '<data><boolean value=\'true\'/></data></wddxPacket>';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeNull() {
+        $value    = null;
+        $expected = '<wddxPacket version=\'1.0\'><header/>'
+                  . '<data><null/></data></wddxPacket>';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeNumeric() {
+        $value    = 100;
+        $expected = '<wddxPacket version=\'1.0\'><header/>'
+                  . '<data><number>100</number></data></wddxPacket>';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testSerializeObject() {
+        $value = new stdClass();
+        $value->test = "test";
+        $expected = '<wddxPacket version=\'1.0\'><header/>'
+                  . '<data><struct>'
+                  . '<var name=\'php_class_name\'><string>stdClass</string></var>'
+                  . '<var name=\'test\'><string>test</string></var>'
+                  . '</struct></data></wddxPacket>';
+
+        $data = $this->_adapter->serialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeString() {
+        $value    = '<wddxPacket version=\'1.0\'><header/>'
+                  . '<data><string>test</string></data></wddxPacket>';
+        $expected = 'test';
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeFalse() {
+        $value    = '<wddxPacket version=\'1.0\'><header/>'
+                  . '<data><boolean value=\'false\'/></data></wddxPacket>';
+        $expected = false;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeTrue() {
+        $value    = '<wddxPacket version=\'1.0\'><header/>'
+                  . '<data><boolean value=\'true\'/></data></wddxPacket>';
+        $expected = true;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeNull1() {
+        $value    = '<wddxPacket version=\'1.0\'><header/>'
+                  . '<data><null/></data></wddxPacket>';
+        $expected = null;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    /**
+     * test to unserialize a valid null value by an valid wddx
+     * but with some differenzes to the null cenerated by php
+     * -> the invalid check have to success for all valid wddx null
+     */
+    public function testUnserializeNull2() {
+        $value    = '<wddxPacket version=\'1.0\'><header/>' . "\n"
+                  . '<data><null/></data></wddxPacket>';
+        $expected = null;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeNumeric() {
+        $value    = '<wddxPacket version=\'1.0\'><header/>'
+                  . '<data><number>100</number></data></wddxPacket>';
+        $expected = 100;
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserializeObject() {
+        $value    = '<wddxPacket version=\'1.0\'><header/>'
+                  . '<data><struct>'
+                  . '<var name=\'php_class_name\'><string>stdClass</string></var>'
+                  . '<var name=\'test\'><string>test</string></var>'
+                  . '</struct></data></wddxPacket>';
+        $expected = new stdClass();
+        $expected->test = 'test';
+
+        $data = $this->_adapter->unserialize($value);
+        $this->assertEquals($expected, $data);
+    }
+
+    public function testUnserialzeInvalid() {
+        $value = 'not a serialized string';
+        $this->setExpectedException('Zend_Serializer_Exception');
+        $this->_adapter->unserialize($value);
+    }
+
+}

+ 45 - 0
tests/Zend/Serializer/AllTests.php

@@ -0,0 +1,45 @@
+<?php
+
+/**
+ * Test helper
+ */
+require_once dirname(__FILE__) . '/../../TestHelper.php';
+
+if (!defined('PHPUnit_MAIN_METHOD')) {
+    define('PHPUnit_MAIN_METHOD', 'Zend_Serializer_AllTests::main');
+}
+
+/** @see Zend_Serializer_Adapter_AllTests */
+require_once dirname(__FILE__) . '/Adapter/AllTests.php';
+
+/** @see Zend_Serializer_SerializerTest */
+require_once dirname(__FILE__) . '/SerializerTest.php';
+
+class Zend_Serializer_AllTests
+{
+    public static function main()
+    {
+        PHPUnit_TextUI_TestRunner::run(self::suite());
+    }
+
+    public static function suite()
+    {
+        $suite = new PHPUnit_Framework_TestSuite('Zend');
+
+        /*
+         * Performe Zend_Serializer_Adapter tests
+         */
+        $suite->addTest(Zend_Serializer_Adapter_AllTests::suite());
+
+        /**
+         * Performe Zend_Serializer tests
+         */
+        $suite->addTestSuite('Zend_Serializer_SerializerTest');
+
+        return $suite;
+    }
+}
+
+if (PHPUnit_MAIN_METHOD == 'Zend_Serializer_AllTests::main') {
+    Zend_Serializer_AllTests::main();
+}

+ 108 - 0
tests/Zend/Serializer/SerializerTest.php

@@ -0,0 +1,108 @@
+<?php
+/**
+ * @package    Zend_Serializer
+ * @subpackage UnitTests
+ */
+
+/**
+ * Zend_Serializer
+ */
+require_once 'Zend/Serializer.php';
+
+/**
+ * PHPUnit test case
+ */
+require_once 'PHPUnit/Framework/TestCase.php';
+
+/**
+ * @package    Zend_Serializer
+ * @subpackage UnitTests
+ */
+class Zend_Serializer_SerializerTest extends PHPUnit_Framework_TestCase
+{
+
+    public function setUp()
+    {
+    }
+
+    public function tearDown()
+    {
+    }
+
+    public function testGetDefaultAdapterLoader() {
+        $this->assertTrue(Zend_Serializer::getAdapterLoader() instanceof Zend_Loader_PluginLoader);
+    }
+
+    public function testChangeAdapterLoader() {
+        $oldLoader = Zend_Serializer::getAdapterLoader();
+        $newLoader = new Zend_Loader_PluginLoader();
+        Zend_Serializer::setAdapterLoader($newLoader);
+        $this->assertTrue(Zend_Serializer::getAdapterLoader() === $newLoader);
+        Zend_Serializer::setAdapterLoader($oldLoader);
+    }
+
+    public function testFactoryValidCall() {
+        $serializer = Zend_Serializer::factory('PhpSerialize');
+        $this->assertTrue($serializer instanceof Zend_Serializer_Adapter_PhpSerialize);
+    }
+
+    public function testFactoryUnknownAdapter() {
+        $this->setExpectedException('Zend_Serializer_Exception');
+        Zend_Serializer::factory('unknown');
+    }
+
+    public function testDefaultAdapter() {
+        $adapter = Zend_Serializer::getDefaultAdapter();
+        $this->assertTrue($adapter instanceof Zend_Serializer_Adapter_AdapterInterface);
+    }
+
+    public function testChangeDefaultAdapterWithString() {
+        $oldAdapter = Zend_Serializer::getDefaultAdapter();
+        $newAdapter = 'Json';
+
+        Zend_Serializer::setDefaultAdapter($newAdapter);
+        $this->assertTrue(Zend_Serializer::getDefaultAdapter() instanceof Zend_Serializer_Adapter_Json);
+
+        Zend_Serializer::setDefaultAdapter($oldAdapter);
+    }
+
+    public function testChangeDefaultAdapterWithInstance() {
+        $oldAdapter = Zend_Serializer::getDefaultAdapter();
+        $newAdapter = new Zend_Serializer_Adapter_PhpSerialize();
+
+        Zend_Serializer::setDefaultAdapter($newAdapter);
+        $this->assertTrue($newAdapter === Zend_Serializer::getDefaultAdapter());
+
+        Zend_Serializer::setDefaultAdapter($oldAdapter);
+    }
+
+    public function testSerializeDefaultAdapter() {
+        $value = 'test';
+        $adapter = Zend_Serializer::getDefaultAdapter();
+        $expected = $adapter->serialize($value);
+        $this->assertEquals($expected, Zend_Serializer::serialize($value));
+    }
+
+    public function testSerializeSpecificAdapter() {
+        $value = 'test';
+        $adapter = new Zend_Serializer_Adapter_Json();
+        $expected = $adapter->serialize($value);
+        $this->assertEquals($expected, Zend_Serializer::serialize($value, array('adapter' => $adapter)));
+    }
+
+    public function testUnserializeDefaultAdapter() {
+        $value = 'test';
+        $adapter = Zend_Serializer::getDefaultAdapter();
+        $value = $adapter->serialize($value);
+        $expected = $adapter->unserialize($value);
+        $this->assertEquals($expected, Zend_Serializer::unserialize($value));
+    }
+
+    public function testUnserializeSpecificAdapter() {
+        $adapter = new Zend_Serializer_Adapter_Json();
+        $value = '"test"';
+        $expected = $adapter->unserialize($value);
+        $this->assertEquals($expected, Zend_Serializer::unserialize($value, array('adapter' => $adapter)));
+    }
+
+}