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
<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>
<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>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>
<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>
<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>
<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>
<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>
8 Comments
comments.show.hideOct 29, 2009
Matthew Weier O'Phinney
<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>
Nov 02, 2009
Benjamin Eberlei
<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>
Dec 06, 2009
Marc Bennewitz (private)
<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>
Nov 05, 2009
Nico Edtinger
<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>
Nov 06, 2009
Benjamin Eberlei
<p>how are objects handled by Zend_Serializer anyways? <ac:emoticon ac:name="smile" /></p>
Nov 06, 2009
Nico Edtinger
<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>
Dec 06, 2009
Marc Bennewitz (private)
<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>
Dec 07, 2009
Marc Bennewitz (private)
<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>