"Fossies" - the Fresh Open Source Software Archive 
Member "drupal-9.4.5/vendor/laminas/laminas-feed/src/Reader/AbstractEntry.php" (24 Mar 2022, 4851 Bytes) of package /linux/www/drupal-9.4.5.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 <?php
2
3 namespace Laminas\Feed\Reader;
4
5 use DOMDocument;
6 use DOMElement;
7 use DOMXPath;
8
9 use function array_key_exists;
10 use function call_user_func_array;
11 use function in_array;
12 use function method_exists;
13
14 /**
15 * @deprecated This (abstract) class is deprecated. Use Laminas\Feed\Reader\Entry\AbstractEntry instead.
16 */
17 abstract class AbstractEntry
18 {
19 /**
20 * Feed entry data
21 *
22 * @var array
23 */
24 protected $data = [];
25
26 /**
27 * DOM document object
28 *
29 * @var DOMDocument
30 */
31 protected $domDocument;
32
33 /**
34 * Entry instance
35 *
36 * @var DOMElement
37 */
38 protected $entry;
39
40 /**
41 * Pointer to the current entry
42 *
43 * @var int
44 */
45 protected $entryKey = 0;
46
47 /**
48 * XPath object
49 *
50 * @var DOMXPath
51 */
52 protected $xpath;
53
54 /**
55 * Registered extensions
56 *
57 * @var array
58 */
59 protected $extensions = [];
60
61 /**
62 * @param int $entryKey
63 * @param null|string $type
64 */
65 public function __construct(DOMElement $entry, $entryKey, $type = null)
66 {
67 $this->entry = $entry;
68 $this->entryKey = $entryKey;
69 $this->domDocument = $entry->ownerDocument;
70 if ($type !== null) {
71 $this->data['type'] = $type;
72 } else {
73 $this->data['type'] = Reader::detectType($entry);
74 }
75 $this->_loadExtensions();
76 }
77
78 /**
79 * Get the DOM
80 *
81 * @return DOMDocument
82 */
83 public function getDomDocument()
84 {
85 return $this->domDocument;
86 }
87
88 /**
89 * Get the entry element
90 *
91 * @return DOMElement
92 */
93 public function getElement()
94 {
95 return $this->entry;
96 }
97
98 /**
99 * Get the Entry's encoding
100 *
101 * @return string
102 */
103 public function getEncoding()
104 {
105 $assumed = $this->getDomDocument()->encoding;
106 if (empty($assumed)) {
107 $assumed = 'UTF-8';
108 }
109 return $assumed;
110 }
111
112 /**
113 * Get entry as xml
114 *
115 * @return string
116 */
117 public function saveXml()
118 {
119 $dom = new DOMDocument('1.0', $this->getEncoding());
120 $entry = $dom->importNode($this->getElement(), true);
121 $dom->appendChild($entry);
122 return $dom->saveXML();
123 }
124
125 /**
126 * Get the entry type
127 *
128 * @return string
129 */
130 public function getType()
131 {
132 return $this->data['type'];
133 }
134
135 /**
136 * Get the XPath query object
137 *
138 * @return DOMXPath
139 */
140 public function getXpath()
141 {
142 if (! $this->xpath) {
143 $this->setXpath(new DOMXPath($this->getDomDocument()));
144 }
145 return $this->xpath;
146 }
147
148 /**
149 * Set the XPath query
150 *
151 * @return $this
152 */
153 public function setXpath(DOMXPath $xpath)
154 {
155 $this->xpath = $xpath;
156 return $this;
157 }
158
159 /**
160 * Get registered extensions
161 *
162 * @return array
163 */
164 public function getExtensions()
165 {
166 return $this->extensions;
167 }
168
169 /**
170 * Return an Extension object with the matching name (postfixed with _Entry)
171 *
172 * @param string $name
173 * @return null|Extension\AbstractEntry
174 */
175 public function getExtension($name)
176 {
177 if (array_key_exists($name . '\Entry', $this->extensions)) {
178 return $this->extensions[$name . '\Entry'];
179 }
180
181 return null;
182 }
183
184 /**
185 * Method overloading: call given method on first extension implementing it
186 *
187 * @param string $method
188 * @param array $args
189 * @return mixed
190 * @throws Exception\BadMethodCallException If no extensions implements the method.
191 */
192 public function __call($method, $args)
193 {
194 foreach ($this->extensions as $extension) {
195 if (method_exists($extension, $method)) {
196 return call_user_func_array([$extension, $method], $args);
197 }
198 }
199 throw new Exception\BadMethodCallException(
200 'Method: ' . $method . ' does not exist and could not be located on a registered Extension'
201 );
202 }
203
204 /**
205 * Load extensions from Laminas\Feed\Reader\Reader
206 *
207 * @return void
208 */
209 // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
210 protected function _loadExtensions()
211 {
212 $all = Reader::getExtensions();
213 $feed = $all['entry'];
214 foreach ($feed as $extension) {
215 if (in_array($extension, $all['core'])) {
216 continue;
217 }
218 $className = Reader::getPluginLoader()->getClassName($extension);
219 $this->extensions[$extension] = new $className(
220 $this->getElement(),
221 $this->entryKey,
222 $this->data['type']
223 );
224 }
225 }
226 }