e69f95056089639f026f3c0a0f9d582bba0a777d
[yaffs-website] / vendor / zendframework / zend-feed / src / Writer / Extension / DublinCore / Renderer / Feed.php
1 <?php
2 /**
3  * Zend Framework (http://framework.zend.com/)
4  *
5  * @link      http://github.com/zendframework/zf2 for the canonical source repository
6  * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7  * @license   http://framework.zend.com/license/new-bsd New BSD License
8  */
9
10 namespace Zend\Feed\Writer\Extension\DublinCore\Renderer;
11
12 use DOMDocument;
13 use DOMElement;
14 use Zend\Feed\Writer\Extension;
15
16 /**
17 */
18 class Feed extends Extension\AbstractRenderer
19 {
20     /**
21      * Set to TRUE if a rendering method actually renders something. This
22      * is used to prevent premature appending of a XML namespace declaration
23      * until an element which requires it is actually appended.
24      *
25      * @var bool
26      */
27     protected $called = false;
28
29     /**
30      * Render feed
31      *
32      * @return void
33      */
34     public function render()
35     {
36         if (strtolower($this->getType()) == 'atom') {
37             return;
38         }
39         $this->_setAuthors($this->dom, $this->base);
40         if ($this->called) {
41             $this->_appendNamespaces();
42         }
43     }
44
45     /**
46      * Append namespaces to feed element
47      *
48      * @return void
49      */
50     // @codingStandardsIgnoreStart
51     protected function _appendNamespaces()
52     {
53         // @codingStandardsIgnoreEnd
54         $this->getRootElement()->setAttribute(
55             'xmlns:dc',
56             'http://purl.org/dc/elements/1.1/'
57         );
58     }
59
60     /**
61      * Set feed authors
62      *
63      * @param  DOMDocument $dom
64      * @param  DOMElement $root
65      * @return void
66      */
67     // @codingStandardsIgnoreStart
68     protected function _setAuthors(DOMDocument $dom, DOMElement $root)
69     {
70         // @codingStandardsIgnoreEnd
71         $authors = $this->getDataContainer()->getAuthors();
72         if (! $authors || empty($authors)) {
73             return;
74         }
75         foreach ($authors as $data) {
76             $author = $this->dom->createElement('dc:creator');
77             if (array_key_exists('name', $data)) {
78                 $text = $dom->createTextNode($data['name']);
79                 $author->appendChild($text);
80                 $root->appendChild($author);
81             }
82         }
83         $this->called = true;
84     }
85 }