/library/Zend/Feed/Reader/Extension/FeedAbstract.php

https://bitbucket.org/hamidrezas/melobit · PHP · 189 lines · 62 code · 22 blank · 105 comment · 4 complexity · 27c518c77eb82d3149bf3c19c67f279e MD5 · raw file

  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-2012 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: FeedAbstract.php 24594 2012-01-05 21:27:01Z matthew $
  20. */
  21. /**
  22. * @see Zend_Feed_Reader
  23. */
  24. require_once 'Zend/Feed/Reader.php';
  25. /**
  26. * @see Zend_Feed_Reader_Entry_Atom
  27. */
  28. require_once 'Zend/Feed/Reader/Entry/Atom.php';
  29. /**
  30. * @see Zend_Feed_Reader_Entry_Rss
  31. */
  32. require_once 'Zend/Feed/Reader/Entry/Rss.php';
  33. /**
  34. * @category Zend
  35. * @package Zend_Feed_Reader
  36. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. */
  39. abstract class Zend_Feed_Reader_Extension_FeedAbstract
  40. {
  41. /**
  42. * Parsed feed data
  43. *
  44. * @var array
  45. */
  46. protected $_data = array();
  47. /**
  48. * Parsed feed data in the shape of a DOMDocument
  49. *
  50. * @var DOMDocument
  51. */
  52. protected $_domDocument = null;
  53. /**
  54. * The base XPath query used to retrieve feed data
  55. *
  56. * @var DOMXPath
  57. */
  58. protected $_xpath = null;
  59. /**
  60. * The XPath prefix
  61. *
  62. * @var string
  63. */
  64. protected $_xpathPrefix = '';
  65. /**
  66. * Constructor
  67. *
  68. * @param Zend_Feed_Abstract $feed The source Zend_Feed object
  69. * @param string $type Feed type
  70. * @return void
  71. */
  72. public function __construct(DomDocument $dom, $type = null, DOMXPath $xpath = null)
  73. {
  74. $this->_domDocument = $dom;
  75. if ($type !== null) {
  76. $this->_data['type'] = $type;
  77. } else {
  78. $this->_data['type'] = Zend_Feed_Reader::detectType($dom);
  79. }
  80. if ($xpath !== null) {
  81. $this->_xpath = $xpath;
  82. } else {
  83. $this->_xpath = new DOMXPath($this->_domDocument);
  84. }
  85. $this->_registerNamespaces();
  86. }
  87. /**
  88. * Get the DOM
  89. *
  90. * @return DOMDocument
  91. */
  92. public function getDomDocument()
  93. {
  94. return $this->_domDocument;
  95. }
  96. /**
  97. * Get the Feed's encoding
  98. *
  99. * @return string
  100. */
  101. public function getEncoding()
  102. {
  103. $assumed = $this->getDomDocument()->encoding;
  104. return $assumed;
  105. }
  106. /**
  107. * Get the feed type
  108. *
  109. * @return string
  110. */
  111. public function getType()
  112. {
  113. return $this->_data['type'];
  114. }
  115. /**
  116. * Return the feed as an array
  117. *
  118. * @return array
  119. */
  120. public function toArray() // untested
  121. {
  122. return $this->_data;
  123. }
  124. /**
  125. * Set the XPath query
  126. *
  127. * @param DOMXPath $xpath
  128. * @return Zend_Feed_Reader_Extension_EntryAbstract
  129. */
  130. public function setXpath(DOMXPath $xpath)
  131. {
  132. $this->_xpath = $xpath;
  133. $this->_registerNamespaces();
  134. return $this;
  135. }
  136. /**
  137. * Get the DOMXPath object
  138. *
  139. * @return string
  140. */
  141. public function getXpath()
  142. {
  143. return $this->_xpath;
  144. }
  145. /**
  146. * Get the XPath prefix
  147. *
  148. * @return string
  149. */
  150. public function getXpathPrefix()
  151. {
  152. return $this->_xpathPrefix;
  153. }
  154. /**
  155. * Set the XPath prefix
  156. *
  157. * @return Zend_Feed_Reader_Feed_Atom
  158. */
  159. public function setXpathPrefix($prefix)
  160. {
  161. $this->_xpathPrefix = $prefix;
  162. }
  163. /**
  164. * Register the default namespaces for the current feed format
  165. */
  166. abstract protected function _registerNamespaces();
  167. }