PageRenderTime 26ms CodeModel.GetById 20ms app.highlight 5ms RepoModel.GetById 0ms app.codeStats 0ms

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