EntryAbstract.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Feed_Reader
  17. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * @category Zend
  23. * @package Zend_Feed_Reader
  24. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  25. * @license http://framework.zend.com/license/new-bsd New BSD License
  26. */
  27. abstract class Zend_Feed_Reader_Entry_EntryAbstract
  28. {
  29. /**
  30. * Feed entry data
  31. *
  32. * @var array
  33. */
  34. protected $_data = array();
  35. /**
  36. * DOM document object
  37. *
  38. * @var DOMDocument
  39. */
  40. protected $_domDocument = null;
  41. /**
  42. * Entry instance
  43. *
  44. * @var Zend_Feed_Entry_Interface
  45. */
  46. protected $_entry = null;
  47. /**
  48. * Pointer to the current entry
  49. *
  50. * @var int
  51. */
  52. protected $_entryKey = 0;
  53. /**
  54. * XPath object
  55. *
  56. * @var DOMXPath
  57. */
  58. protected $_xpath = null;
  59. /**
  60. * Registered extensions
  61. *
  62. * @var array
  63. */
  64. protected $_extensions = array();
  65. /**
  66. * Constructor
  67. *
  68. * @param DOMElement $entry
  69. * @param int $entryKey
  70. * @param string $type
  71. * @return void
  72. */
  73. public function __construct(DOMElement $entry, $entryKey, $type = null)
  74. {
  75. $this->_entry = $entry;
  76. $this->_entryKey = $entryKey;
  77. $this->_domDocument = $entry->ownerDocument;
  78. if ($type !== null) {
  79. $this->_data['type'] = $type;
  80. } else {
  81. $this->_data['type'] = Zend_Feed_Reader::detectType($feed);
  82. }
  83. $this->_loadExtensions();
  84. }
  85. /**
  86. * Get the DOM
  87. *
  88. * @return DOMDocument
  89. */
  90. public function getDomDocument()
  91. {
  92. return $this->_domDocument;
  93. }
  94. /**
  95. * Get the entry element
  96. *
  97. * @return Zend_Feed_Entry_Interface
  98. */
  99. public function getEntryElement()
  100. {
  101. return $this->_entry;
  102. }
  103. /**
  104. * Get the Entry's encoding
  105. *
  106. * @return string
  107. */
  108. public function getEncoding()
  109. {
  110. $assumed = $this->getDomDocument()->encoding;
  111. return $assumed;
  112. }
  113. /**
  114. * Get the entry type
  115. *
  116. * @return string
  117. */
  118. public function getType()
  119. {
  120. return $this->_data['type'];
  121. }
  122. /**
  123. * Get the XPath query object
  124. *
  125. * @return DOMXPath
  126. */
  127. public function getXpath()
  128. {
  129. return $this->_xpath;
  130. }
  131. /**
  132. * Set the XPath query
  133. *
  134. * @param DOMXPath $xpath
  135. * @return Zend_Feed_Reader_Entry_EntryAbstract
  136. */
  137. public function setXpath(DOMXPath $xpath)
  138. {
  139. $this->_xpath = $xpath;
  140. return $this;
  141. }
  142. /**
  143. * Serialize the entry to an array
  144. *
  145. * @return array
  146. */
  147. public function toArray()
  148. {
  149. return $this->_data;
  150. }
  151. /**
  152. * Get registered extensions
  153. *
  154. * @return array
  155. */
  156. public function getExtensions()
  157. {
  158. return $this->_extensions;
  159. }
  160. /**
  161. * Method overloading: call given method on first extension implementing it
  162. *
  163. * @param string $method
  164. * @param array $args
  165. * @return mixed
  166. * @throws Zend_Feed_Exception if no extensions implements the method
  167. */
  168. public function __call($method, $args)
  169. {
  170. foreach ($this->_extensions as $extension) {
  171. if (method_exists($extension, $method)) {
  172. return call_user_func_array(array($extension, $method), $args);
  173. }
  174. }
  175. require_once 'Zend/Feed/Exception.php';
  176. throw new Zend_Feed_Exception('Method: ' . $method
  177. . 'does not exist and could not be located on a registered Extension');
  178. }
  179. /**
  180. * Load extensions from Zend_Feed_Reader
  181. *
  182. * @return void
  183. */
  184. protected function _loadExtensions()
  185. {
  186. $all = Zend_Feed_Reader::getExtensions();
  187. $feed = $all['entry'];
  188. foreach ($feed as $extension) {
  189. if (in_array($extension, $all['core'])) {
  190. continue;
  191. }
  192. $className = Zend_Feed_Reader::getPluginLoader()->getClassName($extension);
  193. $this->_extensions[$className] = new $className(
  194. $this->getEntryElement(), $this->_entryKey, $this->_data['type']
  195. );
  196. }
  197. }
  198. }