| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- Reviewed: no -->
- <sect1 id="zend.feed.custom-feed">
- <title>Custom Feed and Entry Classes</title>
- <para>
- Finally, you can extend the <classname>Zend_Feed</classname> classes if you'd like to
- provide your own format or niceties like automatic handling of elements that should go into
- a custom namespace.
- </para>
- <para>
- Here is an example of a custom Atom entry class that handles its own
- <emphasis>myns:</emphasis> namespace entries. Note that it also makes the
- <methodname>registerNamespace()</methodname> call for you, so the end user doesn't need to
- worry about namespaces at all.
- </para>
- <example id="zend.feed.custom-feed.example.extending">
- <title>Extending the Atom Entry Class with Custom Namespaces</title>
- <programlisting language="php"><![CDATA[
- /**
- * The custom entry class automatically knows the feed URI (optional) and
- * can automatically add extra namespaces.
- */
- class MyEntry extends Zend_Feed_Entry_Atom
- {
- public function __construct($uri = 'http://www.example.com/myfeed/',
- $xml = null)
- {
- parent::__construct($uri, $xml);
- Zend_Feed::registerNamespace('myns',
- 'http://www.example.com/myns/1.0');
- }
- public function __get($var)
- {
- switch ($var) {
- case 'myUpdated':
- // Translate myUpdated to myns:updated.
- return parent::__get('myns:updated');
- default:
- return parent::__get($var);
- }
- }
- public function __set($var, $value)
- {
- switch ($var) {
- case 'myUpdated':
- // Translate myUpdated to myns:updated.
- parent::__set('myns:updated', $value);
- break;
- default:
- parent::__set($var, $value);
- }
- }
- public function __call($var, $unused)
- {
- switch ($var) {
- case 'myUpdated':
- // Translate myUpdated to myns:updated.
- return parent::__call('myns:updated', $unused);
- default:
- return parent::__call($var, $unused);
- }
- }
- }
- ]]></programlisting>
- <para>
- Then to use this class, you'd just instantiate it directly and set the
- <property>myUpdated</property> property:
- </para>
- <programlisting language="php"><![CDATA[
- $entry = new MyEntry();
- $entry->myUpdated = '2005-04-19T15:30';
- // method-style call is handled by __call function
- $entry->myUpdated();
- // property-style call is handled by __get function
- $entry->myUpdated;
- ]]></programlisting>
- </example>
- </sect1>
- <!--
- vim:se ts=4 sw=4 et:
- -->
|