comparison vendor/zendframework/zend-feed/src/Reader/Extension/AbstractFeed.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children a9cd425dd02b
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
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\Reader\Extension;
11
12 use DOMDocument;
13 use DOMXPath;
14 use Zend\Feed\Reader;
15
16 abstract class AbstractFeed
17 {
18 /**
19 * Parsed feed data
20 *
21 * @var array
22 */
23 protected $data = [];
24
25 /**
26 * Parsed feed data in the shape of a DOMDocument
27 *
28 * @var DOMDocument
29 */
30 protected $domDocument = null;
31
32 /**
33 * The base XPath query used to retrieve feed data
34 *
35 * @var DOMXPath
36 */
37 protected $xpath = null;
38
39 /**
40 * The XPath prefix
41 *
42 * @var string
43 */
44 protected $xpathPrefix = '';
45
46 /**
47 * Set the DOM document
48 *
49 * @param DOMDocument $dom
50 * @return AbstractFeed
51 */
52 public function setDomDocument(DOMDocument $dom)
53 {
54 $this->domDocument = $dom;
55 return $this;
56 }
57
58 /**
59 * Get the DOM
60 *
61 * @return DOMDocument
62 */
63 public function getDomDocument()
64 {
65 return $this->domDocument;
66 }
67
68 /**
69 * Get the Feed's encoding
70 *
71 * @return string
72 */
73 public function getEncoding()
74 {
75 $assumed = $this->getDomDocument()->encoding;
76 return $assumed;
77 }
78
79 /**
80 * Set the feed type
81 *
82 * @param string $type
83 * @return AbstractFeed
84 */
85 public function setType($type)
86 {
87 $this->data['type'] = $type;
88 return $this;
89 }
90
91 /**
92 * Get the feed type
93 *
94 * If null, it will attempt to autodetect the type.
95 *
96 * @return string
97 */
98 public function getType()
99 {
100 $type = $this->data['type'];
101 if (null === $type) {
102 $type = Reader\Reader::detectType($this->getDomDocument());
103 $this->setType($type);
104 }
105 return $type;
106 }
107
108 /**
109 * Return the feed as an array
110 *
111 * @return array
112 */
113 public function toArray() // untested
114 {
115 return $this->data;
116 }
117
118 /**
119 * Set the XPath query
120 *
121 * @param DOMXPath $xpath
122 * @return AbstractEntry
123 */
124 public function setXpath(DOMXPath $xpath = null)
125 {
126 if (null === $xpath) {
127 $this->xpath = null;
128 return $this;
129 }
130
131 $this->xpath = $xpath;
132 $this->registerNamespaces();
133 return $this;
134 }
135
136 /**
137 * Get the DOMXPath object
138 *
139 * @return string
140 */
141 public function getXpath()
142 {
143 if (null === $this->xpath) {
144 $this->setXpath(new DOMXPath($this->getDomDocument()));
145 }
146
147 return $this->xpath;
148 }
149
150 /**
151 * Get the XPath prefix
152 *
153 * @return string
154 */
155 public function getXpathPrefix()
156 {
157 return $this->xpathPrefix;
158 }
159
160 /**
161 * Set the XPath prefix
162 *
163 * @param string $prefix
164 * @return void
165 */
166 public function setXpathPrefix($prefix)
167 {
168 $this->xpathPrefix = $prefix;
169 }
170
171 /**
172 * Register the default namespaces for the current feed format
173 */
174 abstract protected function registerNamespaces();
175 }