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: 11) |
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 |
|---|
8 Comments
comments.show.hideOct 29, 2009
Matthew Weier O'Phinney
This proposal is accepted for immediate development in the standard incubator. The structure makes sense, but we have the following request:
Nov 02, 2009
Benjamin Eberlei
Hello Mark,
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):
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/tests/Zend/Entity/Entity/StateTransformer/XmlSerializerTest.php
It supports Arrays only though, how do you support Objects on the other adapters given you don't know what the constructor looks like?
Dec 06, 2009
Marc Bennewitz (private)
hi benjamin,
is your XmlSerializer based on a standard ?
"It supports Arrays"
-> This isn't a good way to add an adapter who only supports serializing arrays.
"how do you support Objects on the other adapters given you"
Nov 05, 2009
Nico Edtinger
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().
Nov 06, 2009
Benjamin Eberlei
how are objects handled by Zend_Serializer anyways?
Nov 06, 2009
Nico Edtinger
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.
Dec 06, 2009
Marc Bennewitz (private)
hi nico
Serializable::serialize() can't use because it returns an already serialized string of the object. You can use Zend_Serializer within Serializable::[un]serialize()
__sleep 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.
-> 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.
Dec 07, 2009
Marc Bennewitz (private)
finished Milestone 3 & 4 with littel changes:
better handling different types of php serializing
better handling different types of python serializing
changed initial variable of Zend_Serializer::$_defaultAdapter from null to 'PhpSerialize'