Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Feed / Reader / AbstractFeed.php
blob6a5cee33a56d8f2fb4d1cc9b585a0c3725a41c76
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Feed\Reader;
12 use DOMDocument;
13 use DOMElement;
14 use DOMXPath;
16 abstract class AbstractFeed implements Feed\FeedInterface
18 /**
19 * Parsed feed data
21 * @var array
23 protected $data = array();
25 /**
26 * Parsed feed data in the shape of a DOMDocument
28 * @var DOMDocument
30 protected $domDocument = null;
32 /**
33 * An array of parsed feed entries
35 * @var array
37 protected $entries = array();
39 /**
40 * A pointer for the iterator to keep track of the entries array
42 * @var int
44 protected $entriesKey = 0;
46 /**
47 * The base XPath query used to retrieve feed data
49 * @var DOMXPath
51 protected $xpath = null;
53 /**
54 * Array of loaded extensions
56 * @var array
58 protected $extensions = array();
60 /**
61 * Original Source URI (set if imported from a URI)
63 * @var string
65 protected $originalSourceUri = null;
67 /**
68 * Constructor
70 * @param DomDocument $domDocument The DOM object for the feed's XML
71 * @param string $type Feed type
73 public function __construct(DOMDocument $domDocument, $type = null)
75 $this->domDocument = $domDocument;
76 $this->xpath = new DOMXPath($this->domDocument);
78 if ($type !== null) {
79 $this->data['type'] = $type;
80 } else {
81 $this->data['type'] = Reader::detectType($this->domDocument);
83 $this->registerNamespaces();
84 $this->indexEntries();
85 $this->loadExtensions();
88 /**
89 * Set an original source URI for the feed being parsed. This value
90 * is returned from getFeedLink() method if the feed does not carry
91 * a self-referencing URI.
93 * @param string $uri
95 public function setOriginalSourceUri($uri)
97 $this->originalSourceUri = $uri;
101 * Get an original source URI for the feed being parsed. Returns null if
102 * unset or the feed was not imported from a URI.
104 * @return string|null
106 public function getOriginalSourceUri()
108 return $this->originalSourceUri;
112 * Get the number of feed entries.
113 * Required by the Iterator interface.
115 * @return int
117 public function count()
119 return count($this->entries);
123 * Return the current entry
125 * @return \Zend\Feed\Reader\AbstractEntry
127 public function current()
129 if (substr($this->getType(), 0, 3) == 'rss') {
130 $reader = new Entry\RSS($this->entries[$this->key()], $this->key(), $this->getType());
131 } else {
132 $reader = new Entry\Atom($this->entries[$this->key()], $this->key(), $this->getType());
135 $reader->setXpath($this->xpath);
137 return $reader;
141 * Get the DOM
143 * @return DOMDocument
145 public function getDomDocument()
147 return $this->domDocument;
151 * Get the Feed's encoding
153 * @return string
155 public function getEncoding()
157 $assumed = $this->getDomDocument()->encoding;
158 if (empty($assumed)) {
159 $assumed = 'UTF-8';
161 return $assumed;
165 * Get feed as xml
167 * @return string
169 public function saveXml()
171 return $this->getDomDocument()->saveXml();
175 * Get the DOMElement representing the items/feed element
177 * @return DOMElement
179 public function getElement()
181 return $this->getDomDocument()->documentElement;
185 * Get the DOMXPath object for this feed
187 * @return DOMXPath
189 public function getXpath()
191 return $this->xpath;
195 * Get the feed type
197 * @return string
199 public function getType()
201 return $this->data['type'];
205 * Return the current feed key
207 * @return int
209 public function key()
211 return $this->entriesKey;
215 * Move the feed pointer forward
218 public function next()
220 ++$this->entriesKey;
224 * Reset the pointer in the feed object
227 public function rewind()
229 $this->entriesKey = 0;
233 * Check to see if the iterator is still valid
235 * @return bool
237 public function valid()
239 return 0 <= $this->entriesKey && $this->entriesKey < $this->count();
242 public function getExtensions()
244 return $this->extensions;
247 public function __call($method, $args)
249 foreach ($this->extensions as $extension) {
250 if (method_exists($extension, $method)) {
251 return call_user_func_array(array($extension, $method), $args);
254 throw new Exception\BadMethodCallException('Method: ' . $method
255 . 'does not exist and could not be located on a registered Extension');
259 * Return an Extension object with the matching name (postfixed with _Feed)
261 * @param string $name
262 * @return \Zend\Feed\Reader\Extension\AbstractFeed
264 public function getExtension($name)
266 if (array_key_exists($name . '\Feed', $this->extensions)) {
267 return $this->extensions[$name . '\Feed'];
269 return null;
272 protected function loadExtensions()
274 $all = Reader::getExtensions();
275 $manager = Reader::getExtensionManager();
276 $feed = $all['feed'];
277 foreach ($feed as $extension) {
278 if (in_array($extension, $all['core'])) {
279 continue;
281 $plugin = $manager->get($extension);
282 $plugin->setDomDocument($this->getDomDocument());
283 $plugin->setType($this->data['type']);
284 $plugin->setXpath($this->xpath);
285 $this->extensions[$extension] = $plugin;
290 * Read all entries to the internal entries array
293 abstract protected function indexEntries();
296 * Register the default namespaces for the current feed format
299 abstract protected function registerNamespaces();