717718c6aece2b288e330c85d356046680f18dc4
[yaffs-website] / vendor / zendframework / zend-feed / src / Writer / Renderer / Entry / Atom / Deleted.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\Renderer\Entry\Atom;
11
12 use DateTime;
13 use DOMDocument;
14 use DOMElement;
15 use Zend\Feed\Writer;
16 use Zend\Feed\Writer\Renderer;
17
18 class Deleted extends Renderer\AbstractRenderer implements Renderer\RendererInterface
19 {
20     /**
21      * Constructor
22      *
23      * @param  Writer\Deleted $container
24      */
25     public function __construct(Writer\Deleted $container)
26     {
27         parent::__construct($container);
28     }
29
30     /**
31      * Render atom entry
32      *
33      * @return Writer\Renderer\Entry\Atom
34      */
35     public function render()
36     {
37         $this->dom = new DOMDocument('1.0', $this->container->getEncoding());
38         $this->dom->formatOutput = true;
39         $entry = $this->dom->createElement('at:deleted-entry');
40         $this->dom->appendChild($entry);
41
42         $entry->setAttribute('ref', $this->container->getReference());
43         $entry->setAttribute('when', $this->container->getWhen()->format(DateTime::ATOM));
44
45         $this->_setBy($this->dom, $entry);
46         $this->_setComment($this->dom, $entry);
47
48         return $this;
49     }
50
51     /**
52      * Set tombstone comment
53      *
54      * @param  DOMDocument $dom
55      * @param  DOMElement $root
56      * @return void
57      */
58     // @codingStandardsIgnoreStart
59     protected function _setComment(DOMDocument $dom, DOMElement $root)
60     {
61         // @codingStandardsIgnoreEnd
62         if (! $this->getDataContainer()->getComment()) {
63             return;
64         }
65         $c = $dom->createElement('at:comment');
66         $root->appendChild($c);
67         $c->setAttribute('type', 'html');
68         $cdata = $dom->createCDATASection($this->getDataContainer()->getComment());
69         $c->appendChild($cdata);
70     }
71
72     /**
73      * Set entry authors
74      *
75      * @param  DOMDocument $dom
76      * @param  DOMElement $root
77      * @return void
78      */
79     // @codingStandardsIgnoreStart
80     protected function _setBy(DOMDocument $dom, DOMElement $root)
81     {
82         // @codingStandardsIgnoreEnd
83         $data = $this->container->getBy();
84         if ((! $data || empty($data))) {
85             return;
86         }
87         $author = $this->dom->createElement('at:by');
88         $name = $this->dom->createElement('name');
89         $author->appendChild($name);
90         $root->appendChild($author);
91         $text = $dom->createTextNode($data['name']);
92         $name->appendChild($text);
93         if (array_key_exists('email', $data)) {
94             $email = $this->dom->createElement('email');
95             $author->appendChild($email);
96             $text = $dom->createTextNode($data['email']);
97             $email->appendChild($text);
98         }
99         if (array_key_exists('uri', $data)) {
100             $uri = $this->dom->createElement('uri');
101             $author->appendChild($uri);
102             $text = $dom->createTextNode($data['uri']);
103             $uri->appendChild($text);
104         }
105     }
106 }