Parcourir la source

All interfaces and abstract classes renamed to namespace friendly terms.
Paths of interfaces/abstracts files updated in source
Zend_Feed_Reader::importFeed() now checks for the updated interface type correctly


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@16953 44c647ce-9c0f-0410-b52a-842ac1e357ba

padraic il y a 16 ans
Parent
commit
186cba3948

+ 2 - 2
library/Zend/Feed/Reader.php

@@ -422,7 +422,7 @@ class Zend_Feed_Reader
      */
     public static function detectType($feed)
     {
-        if ($feed instanceof Zend_Feed_Reader_Feed_Interface) {
+        if ($feed instanceof Zend_Feed_Reader_FeedInterface) {
             $dom = $feed->getDomDocument();
         } elseif($feed instanceof DomDocument) {
             $dom = $feed;
@@ -444,7 +444,7 @@ class Zend_Feed_Reader
             }
         } else {
             require_once 'Zend/Feed/Exception.php';
-            throw new Zend_Feed_Exception('Invalid object/scalar provided: must be of type Zend_Feed_Reader_Feed_Interface, DomDocument or string');
+            throw new Zend_Feed_Exception('Invalid object/scalar provided: must be of type Zend_Feed_Reader_FeedInterface, DomDocument or string');
         }
         $xpath = new DOMXPath($dom);
 

+ 5 - 5
library/Zend/Feed/Reader/Entry/Atom.php

@@ -25,14 +25,14 @@
 require_once 'Zend/Feed/Reader.php';
 
 /**
- * @see Zend_Feed_Reader_Entry_Interface
+ * @see Zend_Feed_Reader_EntryInterface
  */
-require_once 'Zend/Feed/Reader/Entry/Interface.php';
+require_once 'Zend/Feed/Reader/EntryInterface.php';
 
 /**
- * @see Zend_Feed_Reader_Entry_EntryAbstract
+ * @see Zend_Feed_Reader_EntryAbstract
  */
-require_once 'Zend/Feed/Reader/Entry/EntryAbstract.php';
+require_once 'Zend/Feed/Reader/EntryAbstract.php';
 
 /**
  * @see Zend_Feed_Reader_Extension_Atom_Entry
@@ -45,7 +45,7 @@ require_once 'Zend/Feed/Reader/Extension/Atom/Entry.php';
  * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
-class Zend_Feed_Reader_Entry_Atom extends Zend_Feed_Reader_Entry_EntryAbstract implements Zend_Feed_Reader_Entry_Interface
+class Zend_Feed_Reader_Entry_Atom extends Zend_Feed_Reader_EntryAbstract implements Zend_Feed_Reader_EntryInterface
 {
     /**
      * XPath query

+ 5 - 5
library/Zend/Feed/Reader/Entry/Rss.php

@@ -25,14 +25,14 @@
 require_once 'Zend/Feed/Reader.php';
 
 /**
- * @see Zend_Feed_Reader_Entry_Interface
+ * @see Zend_Feed_Reader_EntryInterface
  */
-require_once 'Zend/Feed/Reader/Entry/Interface.php';
+require_once 'Zend/Feed/Reader/EntryInterface.php';
 
 /**
- * @see Zend_Feed_Reader_Entry_EntryAbstract
+ * @see Zend_Feed_Reader_EntryAbstract
  */
-require_once 'Zend/Feed/Reader/Entry/EntryAbstract.php';
+require_once 'Zend/Feed/Reader/EntryAbstract.php';
 
 /**
  * @see Zend_Feed_Reader_Extension_DublinCore_Entry
@@ -75,7 +75,7 @@ require_once 'Zend/Date.php';
  * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
-class Zend_Feed_Reader_Entry_Rss extends Zend_Feed_Reader_Entry_EntryAbstract implements Zend_Feed_Reader_Entry_Interface
+class Zend_Feed_Reader_Entry_Rss extends Zend_Feed_Reader_EntryAbstract implements Zend_Feed_Reader_EntryInterface
 {
     /**
      * Dublin Core object

+ 215 - 0
library/Zend/Feed/Reader/EntryAbstract.php

@@ -0,0 +1,215 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Feed_Reader
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @category   Zend
+ * @package    Zend_Feed_Reader
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+abstract class Zend_Feed_Reader_EntryAbstract
+{
+    /**
+     * Feed entry data
+     *
+     * @var array
+     */
+    protected $_data = array();
+
+    /**
+     * DOM document object
+     *
+     * @var DOMDocument
+     */
+    protected $_domDocument = null;
+
+    /**
+     * Entry instance
+     *
+     * @var Zend_Feed_Entry_Interface
+     */
+    protected $_entry = null;
+
+    /**
+     * Pointer to the current entry
+     *
+     * @var int
+     */
+    protected $_entryKey = 0;
+
+    /**
+     * XPath object
+     *
+     * @var DOMXPath
+     */
+    protected $_xpath = null;
+
+    /**
+     * Registered extensions
+     *
+     * @var array
+     */
+    protected $_extensions = array();
+
+    /**
+     * Constructor
+     *
+     * @param  DOMElement $entry
+     * @param  int $entryKey
+     * @param  string $type
+     * @return void
+     */
+    public function __construct(DOMElement $entry, $entryKey, $type = null)
+    {
+        $this->_entry       = $entry;
+        $this->_entryKey    = $entryKey;
+        $this->_domDocument = $entry->ownerDocument;
+        if ($type !== null) {
+            $this->_data['type'] = $type;
+        } else {
+            $this->_data['type'] = Zend_Feed_Reader::detectType($feed);
+        }
+        $this->_loadExtensions();
+    }
+
+    /**
+     * Get the DOM
+     *
+     * @return DOMDocument
+     */
+    public function getDomDocument()
+    {
+        return $this->_domDocument;
+    }
+
+    /**
+     * Get the entry element
+     *
+     * @return Zend_Feed_Entry_Interface
+     */
+    public function getEntryElement()
+    {
+        return $this->_entry;
+    }
+
+    /**
+     * Get the Entry's encoding
+     *
+     * @return string
+     */
+    public function getEncoding()
+    {
+        $assumed = $this->getDomDocument()->encoding;
+        return $assumed;
+    }
+
+	/**
+     * Get the entry type
+     *
+     * @return string
+     */
+    public function getType()
+    {
+        return $this->_data['type'];
+    }
+
+    /**
+     * Get the XPath query object
+     *
+     * @return DOMXPath
+     */
+    public function getXpath()
+    {
+        return $this->_xpath;
+    }
+
+	/**
+     * Set the XPath query
+     *
+     * @param  DOMXPath $xpath
+     * @return Zend_Feed_Reader_Entry_EntryAbstract
+     */
+    public function setXpath(DOMXPath $xpath)
+    {
+        $this->_xpath = $xpath;
+        return $this;
+    }
+
+    /**
+     * Serialize the entry to an array
+     *
+     * @return array
+     */
+    public function toArray()
+    {
+        return $this->_data;
+    }
+
+    /**
+     * Get registered extensions
+     *
+     * @return array
+     */
+    public function getExtensions()
+    {
+        return $this->_extensions;
+    }
+
+    /**
+     * Method overloading: call given method on first extension implementing it
+     *
+     * @param  string $method
+     * @param  array $args
+     * @return mixed
+     * @throws Zend_Feed_Exception if no extensions implements the method
+     */
+    public function __call($method, $args)
+    {
+        foreach ($this->_extensions as $extension) {
+            if (method_exists($extension, $method)) {
+                return call_user_func_array(array($extension, $method), $args);
+            }
+        }
+        require_once 'Zend/Feed/Exception.php';
+        throw new Zend_Feed_Exception('Method: ' . $method
+            . 'does not exist and could not be located on a registered Extension');
+    }
+
+    /**
+     * Load extensions from Zend_Feed_Reader
+     *
+     * @return void
+     */
+    protected function _loadExtensions()
+    {
+        $all = Zend_Feed_Reader::getExtensions();
+        $feed = $all['entry'];
+        foreach ($feed as $extension) {
+            if (in_array($extension, $all['core'])) {
+                continue;
+            }
+            $className = Zend_Feed_Reader::getPluginLoader()->getClassName($extension);
+            $this->_extensions[$className] = new $className(
+                $this->getEntryElement(), $this->_entryKey, $this->_data['type']
+            );
+        }
+    }
+}

+ 136 - 0
library/Zend/Feed/Reader/EntryInterface.php

@@ -0,0 +1,136 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Feed_Reader
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @category   Zend
+ * @package    Zend_Feed_Reader
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+interface Zend_Feed_Reader_EntryInterface
+{
+    /**
+     * Get the specified author
+     *
+     * @param  int $index
+     * @return string|null
+     */
+    public function getAuthor($index = 0);
+
+    /**
+     * Get an array with feed authors
+     *
+     * @return array
+     */
+    public function getAuthors();
+
+    /**
+     * Get the entry content
+     *
+     * @return string
+     */
+    public function getContent();
+
+    /**
+     * Get the entry creation date
+     *
+     * @return string
+     */
+    public function getDateCreated();
+
+    /**
+     * Get the entry modification date
+     *
+     * @return string
+     */
+    public function getDateModified();
+
+    /**
+     * Get the entry description
+     *
+     * @return string
+     */
+    public function getDescription();
+
+    /**
+     * Get the entry enclosure
+     *
+     * @return stdClass
+     */
+    public function getEnclosure();
+
+    /**
+     * Get the entry ID
+     *
+     * @return string
+     */
+    public function getId();
+
+    /**
+     * Get a specific link
+     *
+     * @param  int $index
+     * @return string
+     */
+    public function getLink($index = 0);
+
+    /**
+     * Get all links
+     *
+     * @return array
+     */
+    public function getLinks();
+
+    /**
+     * Get a permalink to the entry
+     *
+     * @return string
+     */
+    public function getPermalink();
+
+    /**
+     * Get the entry title
+     *
+     * @return string
+     */
+    public function getTitle();
+
+    /**
+     * Get the number of comments/replies for current entry
+     *
+     * @return integer
+     */
+    public function getCommentCount();
+
+    /**
+     * Returns a URI pointing to the HTML page where comments can be made on this entry
+     *
+     * @return string
+     */
+    public function getCommentLink();
+
+    /**
+     * Returns a URI pointing to a feed of all comments for this entry
+     *
+     * @return string
+     */
+    public function getCommentFeedLink();
+}

+ 3 - 3
library/Zend/Feed/Reader/Feed/Atom.php

@@ -20,9 +20,9 @@
  */
 
 /**
- * @see Zend_Feed_Reader_Feed_FeedAbstract
+ * @see Zend_Feed_Reader_FeedAbstract
  */
-require_once 'Zend/Feed/Reader/Feed/FeedAbstract.php';
+require_once 'Zend/Feed/Reader/FeedAbstract.php';
 
 /**
  * @see Zend_Feed_Reader_Extension_Atom_Feed
@@ -35,7 +35,7 @@ require_once 'Zend/Feed/Reader/Extension/Atom/Feed.php';
  * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
-class Zend_Feed_Reader_Feed_Atom extends Zend_Feed_Reader_Feed_FeedAbstract
+class Zend_Feed_Reader_Feed_Atom extends Zend_Feed_Reader_FeedAbstract
 {
 
     /**

+ 3 - 3
library/Zend/Feed/Reader/Feed/Rss.php

@@ -20,9 +20,9 @@
  */
 
 /**
- * @see Zend_Feed_Reader_Feed_FeedAbstract
+ * @see Zend_Feed_Reader_FeedAbstract
  */
-require_once 'Zend/Feed/Reader/Feed/FeedAbstract.php';
+require_once 'Zend/Feed/Reader/FeedAbstract.php';
 
 /**
  * @see Zend_feed_Reader_Extension_Atom_Feed
@@ -45,7 +45,7 @@ require_once 'Zend/Date.php';
  * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
-class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_Feed_FeedAbstract
+class Zend_Feed_Reader_Feed_Rss extends Zend_Feed_Reader_FeedAbstract
 {
     /**
      * Atom feed

+ 260 - 0
library/Zend/Feed/Reader/FeedAbstract.php

@@ -0,0 +1,260 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Feed_Reader
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Feed_Reader
+ */
+require_once 'Zend/Feed/Reader.php';
+
+/**
+ * @see Zend_Feed_Reader_Entry_Atom
+ */
+require_once 'Zend/Feed/Reader/Entry/Atom.php';
+
+
+/**
+ * @see Zend_Feed_Reader_Entry_Rss
+ */
+require_once 'Zend/Feed/Reader/Entry/Rss.php';
+
+/**
+ * @see Zend_feed_Reader_FeedInterface
+ */
+require_once 'Zend/Feed/Reader/FeedInterface.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Feed_Reader
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+abstract class Zend_Feed_Reader_FeedAbstract implements Zend_Feed_Reader_FeedInterface
+{
+	/**
+     * Parsed feed data
+     *
+     * @var array
+     */
+    protected $_data = array();
+
+    /**
+     * Parsed feed data in the shape of a DOMDocument
+     *
+     * @var DOMDocument
+     */
+    protected $_domDocument = null;
+
+    /**
+     * An array of parsed feed entries
+     *
+     * @var array
+     */
+    protected $_entries = array();
+
+    /**
+     * A pointer for the iterator to keep track of the entries array
+     *
+     * @var int
+     */
+    protected $_entriesKey = 0;
+
+    /**
+     * The base XPath query used to retrieve feed data
+     *
+     * @var DOMXPath
+     */
+    protected $_xpath = null;
+
+    protected $_extensions = array();
+
+    /**
+     * Constructor
+     *
+     * @param DomDocument The DOM object for the feed's XML
+     * @param string $type Feed type
+     */
+    public function __construct(DomDocument $domDocument, $type = null)
+    {
+        $this->_domDocument = $domDocument;
+        $this->_xpath = new DOMXPath($this->_domDocument);
+
+        if ($type !== null) {
+            $this->_data['type'] = $type;
+        } else {
+            $this->_data['type'] = Zend_Feed_Reader::detectType($this->_domDocument);
+        }
+        $this->_registerNamespaces();
+        $this->_indexEntries();
+        $this->_loadExtensions();
+    }
+
+	/**
+     * Get the number of feed entries.
+     * Required by the Iterator interface.
+     *
+     * @return int
+     */
+    public function count()
+    {
+        return count($this->_entries);
+    }
+
+	/**
+     * Return the current entry
+     *
+     * @return Zend_Feed_Reader_Entry_Interface
+     */
+    public function current()
+    {
+        if (substr($this->getType(), 0, 3) == 'rss') {
+            $reader = new Zend_Feed_Reader_Entry_Rss($this->_entries[$this->key()], $this->key(), $this->getType());
+        } else {
+            $reader = new Zend_Feed_Reader_Entry_Atom($this->_entries[$this->key()], $this->key(), $this->getType());
+        }
+
+        $reader->setXpath($this->_xpath);
+
+        return $reader;
+    }
+
+    /**
+     * Get the DOM
+     *
+     * @return DOMDocument
+     */
+    public function getDomDocument()
+    {
+        return $this->_domDocument;
+    }
+
+    /**
+     * Get the Feed's encoding
+     *
+     * @return string
+     */
+    public function getEncoding()
+    {
+        $assumed = $this->getDomDocument()->encoding;
+        return $assumed;
+    }
+
+    /**
+     * Get the feed type
+     *
+     * @return string
+     */
+    public function getType()
+    {
+        return $this->_data['type'];
+    }
+
+	/**
+     * Return the current feed key
+     *
+     * @return unknown
+     */
+    public function key()
+    {
+        return $this->_entriesKey;
+    }
+
+	/**
+     * Move the feed pointer forward
+     *
+     */
+    public function next()
+    {
+        ++$this->_entriesKey;
+    }
+
+    /**
+     * Reset the pointer in the feed object
+     *
+     */
+    public function rewind()
+    {
+        $this->_entriesKey = 0;
+    }
+
+    /**
+     * Return the feed as an array
+     *
+     * @return array
+     */
+    public function toArray() // untested
+    {
+        return $this->_data;
+    }
+
+    /**
+     * Check to see if the iterator is still valid
+     *
+     * @return boolean
+     */
+    public function valid()
+    {
+        return 0 <= $this->_entriesKey && $this->_entriesKey < $this->count();
+    }
+
+    public function getExtensions()
+    {
+        return $this->_extensions;
+    }
+
+    public function __call($method, $args)
+    {
+        foreach ($this->_extensions as $extension) {
+            if (method_exists($extension, $method)) {
+                return call_user_func_array(array($extension, $method), $args);
+            }
+        }
+        require_once 'Zend/Feed/Exception.php';
+        throw new Zend_Feed_Exception('Method: ' . $method
+        . 'does not exist and could not be located on a registered Extension');
+    }
+
+    protected function _loadExtensions()
+    {
+        $all = Zend_Feed_Reader::getExtensions();
+        $feed = $all['feed'];
+        foreach ($feed as $extension) {
+            if (in_array($extension, $all['core'])) {
+                continue;
+            }
+            $className = Zend_Feed_Reader::getPluginLoader()->getClassName($extension);
+            $this->_extensions[$className] = new $className(
+                $this->getDomDocument(), $this->_data['type'], $this->_xpath
+            );
+        }
+    }
+
+    /**
+     * Read all entries to the internal entries array
+     *
+     */
+    abstract protected function _indexEntries();
+
+    /**
+     * Register the default namespaces for the current feed format
+     *
+     */
+    abstract protected function _registerNamespaces();
+}

+ 115 - 0
library/Zend/Feed/Reader/FeedInterface.php

@@ -0,0 +1,115 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Feed_Reader
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @category   Zend
+ * @package    Zend_Feed_Reader
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+interface Zend_Feed_Reader_FeedInterface extends Iterator, Countable
+{
+    /**
+     * Get a single author
+     *
+     * @param  int $index
+     * @return string|null
+     */
+    public function getAuthor($index = 0);
+
+    /**
+     * Get an array with feed authors
+     *
+     * @return array
+     */
+    public function getAuthors();
+
+    /**
+     * Get the copyright entry
+     *
+     * @return string|null
+     */
+    public function getCopyright();
+
+    /**
+     * Get the feed creation date
+     *
+     * @return string|null
+     */
+    public function getDateCreated();
+
+    /**
+     * Get the feed modification date
+     *
+     * @return string|null
+     */
+    public function getDateModified();
+
+    /**
+     * Get the feed description
+     *
+     * @return string|null
+     */
+    public function getDescription();
+
+    /**
+     * Get the feed generator entry
+     *
+     * @return string|null
+     */
+    public function getGenerator();
+
+    /**
+     * Get the feed ID
+     *
+     * @return string|null
+     */
+    public function getId();
+
+    /**
+     * Get the feed language
+     *
+     * @return string|null
+     */
+    public function getLanguage();
+
+    /**
+     * Get a link to the HTML source
+     *
+     * @return string|null
+     */
+    public function getLink();
+
+    /**
+     * Get a link to the XML feed
+     *
+     * @return string|null
+     */
+    public function getFeedLink();
+
+    /**
+     * Get the feed title
+     *
+     * @return string|null
+     */
+    public function getTitle();
+
+}