Custom Feed and Entry ClassesΒΆ

Finally, you can extend the Zend_Feed classes if you’d like to provide your own format or niceties like automatic handling of elements that should go into a custom namespace.

Here is an example of a custom Atom entry class that handles its own myns: namespace entries. Note that it also makes the registerNamespace() call for you, so the end user doesn’t need to worry about namespaces at all.

Extending the Atom Entry Class with Custom Namespaces

 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
/**
 * 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);
        }
    }
}

Then to use this class, you’d just instantiate it directly and set the myUpdated property:

1
2
3
4
5
6
7
$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;

Project Versions

This Page

Note: You need to stay logged into your GitHub account to contribute to the documentation.

Edit this document

Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Login with your GitHub account.
  2. Go to Custom Feed and Entry Classes on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.