File: Zend_Feed-CustomFeed.xml

package info (click to toggle)
zendframework 1.12.9%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 133,584 kB
  • sloc: xml: 1,311,829; php: 570,173; sh: 170; makefile: 125; sql: 121
file content (96 lines) | stat: -rw-r--r-- 2,805 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?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:
-->