Skip to end of metadata
Go to start of metadata

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

Zend Framework: Zend_Serializer Component Proposal

Proposed Component Name Zend_Serializer
Developer Notes http://framework.zend.com/wiki/display/ZFDEV/Zend_Serializer
Proposers Marc Bennewitz
Zend Liaison TBD
Revision 1.0 - 20. Oct 2009: Initial Draft.
1.1 - 07. Dec 2009: Milestone 3 & 4 finished (wiki revision: 12)

Table of Contents

1. Overview

Zend_Serializer is a simple component to un-/serialize values by different adapters.

2. References

3. Component Requirements, Constraints, and Acceptance Criteria

  • The component factory will use a configurable plugin loader to instantiate adapters.
  • The component will throw an exception if un-/serialization failed (instead of returning false).
  • The component adapters doesn't implement the Serializable interface of spl.

4. Dependencies on Other Framework Components

  • Zend_Exception
  • Zend_Json (only json adapter)
  • Zend_Amf (only amf[0|3] adapter)
  • Zend_Loader_PluginLoader (to load adapter class)

5. Theory of Operation

The Component instantiate a adapter on factory which implements un-/serialize methods, these methods will be used generates a string representation of a value and vice versa.
The static implementation within Zend_Serializer::[un]serialize generates an instance of the selected adapter in given options or an configurable default adapter will be used.

6. Milestones / Tasks

  • Milestone 1: [DONE]: Finish proposal
  • Milestone 2: [DONE]: Working prototype
  • Milestone 3: [DONE]: Prototype checked into the incubator
  • Milestone 4: [DONE]: Unit tests exist finished and component is working
  • Milestone 5: Initial documentation exists
  • Milestone 6: Changed related components
  • Milestone 7: Moved to core.

7. Class Index

  • Zend_Serializer
  • Zend_Serializer_Exception
  • Zend_Serializer_Adapter_AdapterInterface
  • Zend_Serializer_Adapter_AbstractAdapter
  • Zend_Serializer_Adapter_PhpSerialize (using [un]serialize)
  • Zend_Serializer_Adapter_PhpCode (using var_export + eval)
  • Zend_Serializer_Adapter_Wddx
  • Zend_Serializer_Adapter_Json
  • Zend_Serializer_Adapter_Igbinary
  • Zend_Serializer_Adapter_PythonPickle
  • Zend_Serializer_Adapter_Amf0
  • Zend_Serializer_Adapter_Amf3

8. Use Cases

UC-01
UC-02

9. Class Skeletons

]]></ac:plain-text-body></ac:macro>

]]></ac:plain-text-body></ac:macro>

Labels:
serialize serialize Delete
unserialize unserialize Delete
dump dump Delete
string string Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Oct 29, 2009

    <ac:macro ac:name="note"><ac:parameter ac:name="title">Zend Acceptance</ac:parameter><ac:rich-text-body>
    <p>This proposal is accepted for immediate development in the standard incubator. The structure makes sense, but we have the following request:</p>
    <ul>
    <li>Please provide a default plugin loader for the package to ensure that the default serializers may be found.</li>
    </ul>
    </ac:rich-text-body></ac:macro>

  2. Nov 02, 2009

    <p>Hello Mark,</p>

    <p>for Zend Entity I wrote an XML Serializer, already fully tested. You can extract this code into the Zend_Serializer namespace if you want (given Zend Entity is discontinued also):</p>

    <p><a class="external-link" href="http://framework.zend.com/svn/framework/standard/branches/user/beberlei/ZendEntityLatest/library/Zend/Entity/Entity/StateTransformer/XmlSerializer.php">http://framework.zend.com/svn/framework/standard/branches/user/beberlei/ZendEntityLatest/library/Zend/Entity/Entity/StateTransformer/XmlSerializer.php</a></p>

    <p><a class="external-link" href="http://framework.zend.com/svn/framework/standard/branches/user/beberlei/ZendEntityLatest/tests/Zend/Entity/Entity/StateTransformer/XmlSerializerTest.php">http://framework.zend.com/svn/framework/standard/branches/user/beberlei/ZendEntityLatest/tests/Zend/Entity/Entity/StateTransformer/XmlSerializerTest.php</a></p>

    <p>It supports Arrays only though, how do you support Objects on the other adapters given you don't know what the constructor looks like?</p>

    1. Dec 06, 2009

      <p>hi benjamin,</p>

      <p>is your XmlSerializer based on a standard ?</p>

      <p>"It supports Arrays"<br />
      -> This isn't a good way to add an adapter who only supports serializing arrays.</p>

      <p>"how do you support Objects on the other adapters given you"</p>
      <ul class="alternate">
      <li>igbinary works with php object serializing</li>
      <li>json is only a wrapper for serialize data with Zend_Serializer using Zend_Json</li>
      <li>wddx see <a class="external-link" href="http://de.php.net/manual/en/book.wddx.php">http://de.php.net/manual/en/book.wddx.php</a></li>
      <li>pickle converts objects as a python dictionaries (like associative arrays)</li>
      </ul>

  3. Nov 05, 2009

    <p>If possible Zend_Serialize should use Serializable::serialize() or __sleep(), when an object implements them. __wakeup() and Serializable::unserialize() might not make as much sense, because objects don't map well to other serialize formats. The case I've seen is the pickle implementation, which always uses get_object_vars().</p>

    1. Nov 06, 2009

      <p>how are objects handled by Zend_Serializer anyways? <ac:emoticon ac:name="smile" /></p>

      1. Nov 06, 2009

        <p>They are converted to dictionaries. And it's correct. But if an object already knows, which properties define the state of the object and which are just resources, cached values, etc. it would be a good idea to build upon this callbacks.</p>

    2. Dec 06, 2009

      <p>hi nico</p>

      <p><strong>Serializable::serialize()</strong> can't use because it returns an already serialized string of the object. You can use Zend_Serializer within Serializable::[un]serialize()</p>

      <p><strong>__sleep</strong> could be used but i don't know if this is a good idea because the object which implements __sleep & __wakeup assumed that __wakeup will be called on unserializing but the object will be converted to an dictionary. On Zend_Json its the same.<br />
      -> My first solution was to merge some php objects to python objects (like php DateTime -> python datetime.datetime) but the pickled data of python objects are really hard to clone.</p>

  4. Dec 07, 2009

    <p>finished Milestone 3 & 4 with littel changes:</p>

    <ul class="alternate">
    <li>renamed Zend_Serializer_AdapterInterface to Zend_Serializer_Adapter_AdapterInterface</li>
    <li>added Zend_Serializer_Adapter_AbstractAdapter</li>
    </ul>

    <p><strong>better handling different types of php serializing</strong></p>
    <ul class="alternate">
    <li>renamed Zend_Serializer_Adapter_Php to Zend_Serializer_Adapter_PhpSerialize</li>
    <li>added Zend_Serializer_Adapter_PhpCode (using var_export + eval)</li>
    </ul>

    <p><strong>better handling different types of python serializing</strong></p>
    <ul class="alternate">
    <li>renamed Zend_Serializer_Adapter_Pickle to Zend_Serializer_Adapter_PythonPickle</li>
    </ul>

    <p>changed initial variable of Zend_Serializer::$_defaultAdapter from null to 'PhpSerialize'</p>