Dojo and other Javascript toolkits are often choosing to abstract data access for their widgets in order to allow switching data sources. Dojo does this via a variety of data stores, which consume data in the dojo.data format. dojo.data is a simple format for wrapping data sets and providing basic metadata about them:
To dissect this in PHP terms, we have a structure like the following:
When using Zend Framework, however, you will rarely have a data construct that matches this. This proposal would provide a component that could consume a variety of data constructs to utilize as dojo.data items, and mutators for specifying the identifier and optional label attributes of the records in the data store. Additionally, accessors would allow for retrieving the information.
This component could then be used as a backend data store for use with Dojo's QueryReadStore. This would require serialization of the data and metadata stored in the object to JSON (which is consumed natively by QueryReadStore). While dojo supports other data stores, these data stores utilize special formats already and will not require usage of this component. As examples, the CsvStore, OpmlStore, and AtomStore all leverage the self-documenting capabilities of those formats in order to provide introspection of the returned data. The only other format of much interest to ZF developers might be the XmlStore. This store allows parsing of arbitrary XML collections. However, it's a read-write store, and would be best used with public, editable XML documents.
3. Component Requirements, Constraints, and Acceptance Criteria
MUST allow attaching arbitrary data sets:
Zend_Db_Table_Rowset_Abstract
Arrays
Service results
MUST require specifying identifier attribute name
MUST require specifying label attribute name
MUST provide accessors and mutators to data items
MUST serialize to JSON
SHOULD implement string serialization proxying to JSON serialization
MUST allow access to metadata and data within PHP
4. Dependencies on Other Framework Components
HARD depedencies
Zend_Exception
SOFT dependencies
Zend_Db_Table_Rowset_Abstract
Potentially Zend_Service consumables
5. Theory of Operation
A developer will attach a data set and specify an identifier when instantiating Zend_Dojo_Data; alternately, these can be specified via mutators. Serialization will happen on demand via a toJson() method.
<p>Which types are supported as items? Only arrays or also objects (maybe with a toArray() method) and scalars (with an implicit attribute name 'value' or 'scalar').</p>
<p>What I'm missing is Zend_Dojo_Data implementing ArrayAccess. setItem(), getItem() and removeItem() are essentially the same as offsetSet(), offsetGet() and offsetUnset().</p>
<p>If you look at the examples, the primary use case I suggest is a Zend_Db_Table_Rowset. However, I'll likely go the same route as with partials, and have the following criteria:</p>
<ul>
<li>objects
<ul>
<li>implementing toArray()</li>
<li>Traversable objects (would traverse and cast each value)</li>
</ul>
</li>
<li>associative arrays</li>
</ul>
<p>Each item added would need to be either an assoc array or an object (dojo.data items are JS objects). If an object is passed as an item, it will either need to implement toArray(), or we will use get_object_vars().</p>
<p>I will update the proposal to indicate that the class will implement ArrayAccess, Iterator, and Countable – this was intended from the outset.</p>
<ac:macro ac:name="note"><ac:parameter ac:name="title">Zend Comments</ac:parameter><ac:rich-text-body>
<p>This proposal has been approved for standard/incubator development as is.</p></ac:rich-text-body></ac:macro>
4 Comments
comments.show.hideJun 20, 2008
Remi ++
<p>Great idea. I love it, how you (Matthew) integrates all this Dojo stuff. Great work!</p>
<p>Remi</p>
Jun 20, 2008
Nico Edtinger
<p>Which types are supported as items? Only arrays or also objects (maybe with a toArray() method) and scalars (with an implicit attribute name 'value' or 'scalar').</p>
<p>What I'm missing is Zend_Dojo_Data implementing ArrayAccess. setItem(), getItem() and removeItem() are essentially the same as offsetSet(), offsetGet() and offsetUnset().</p>
Jun 21, 2008
Matthew Weier O'Phinney
<p>If you look at the examples, the primary use case I suggest is a Zend_Db_Table_Rowset. However, I'll likely go the same route as with partials, and have the following criteria:</p>
<ul>
<li>objects
<ul>
<li>implementing toArray()</li>
<li>Traversable objects (would traverse and cast each value)</li>
</ul>
</li>
<li>associative arrays</li>
</ul>
<p>Each item added would need to be either an assoc array or an object (dojo.data items are JS objects). If an object is passed as an item, it will either need to implement toArray(), or we will use get_object_vars().</p>
<p>I will update the proposal to indicate that the class will implement ArrayAccess, Iterator, and Countable – this was intended from the outset.</p>
Jun 26, 2008
Alexander Veremyev
<ac:macro ac:name="note"><ac:parameter ac:name="title">Zend Comments</ac:parameter><ac:rich-text-body>
<p>This proposal has been approved for standard/incubator development as is.</p></ac:rich-text-body></ac:macro>