Skip to content

Commit

Permalink
Zend\Feed\Writer cleanup
Browse files Browse the repository at this point in the history
- Swapped "ComponentAbstract" for "AbstractComponent" throughout
- Renamed and reorg'd Component/Component naming instances
- Moved InvalidMethodException up one level
- Updated code and tests to reflect the above
  • Loading branch information
weierophinney committed Jul 7, 2010
1 parent d2f5537 commit 871a8eb
Show file tree
Hide file tree
Showing 36 changed files with 360 additions and 373 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
/**
* @namespace
*/
namespace Zend\Feed\Writer\Feed;
use Zend\Feed\Writer;
namespace Zend\Feed\Writer;

use Zend\Feed;
use Zend\URI;
use Zend\Date;
Expand All @@ -33,15 +33,15 @@
* @uses \Zend\Feed\Exception
* @uses \Zend\Feed\Writer\Writer
* @uses \Zend\Feed\Writer\Entry
* @uses \Zend\Feed\Writer\Renderer\Feed\Atom\Atom
* @uses \Zend\Feed\Writer\Renderer\Feed\Atom
* @uses \Zend\Feed\Writer\Renderer\Feed\RSS
* @uses \Zend\Uri\Uri
* @category Zend
* @package Zend_Feed_Writer
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class FeedAbstract
class AbstractFeed
{
/**
* Contains all Feed level date to append in feed output
Expand All @@ -66,7 +66,7 @@ class FeedAbstract
*/
public function __construct()
{
Writer\Writer::registerCoreExtensions();
Writer::registerCoreExtensions();
$this->_loadExtensions();
}

Expand Down Expand Up @@ -652,7 +652,7 @@ public function __call($method, $args)
foreach ($this->_extensions as $extension) {
try {
return call_user_func_array(array($extension, $method), $args);
} catch (Feed\Writer\Exception\InvalidMethodException $e) {
} catch (InvalidMethodException $e) {
}
}
throw new Feed\Exception('Method: ' . $method
Expand All @@ -666,10 +666,10 @@ public function __call($method, $args)
*/
protected function _loadExtensions()
{
$all = Writer\Writer::getExtensions();
$all = Writer::getExtensions();
$exts = $all['feed'];
foreach ($exts as $ext) {
$className = Writer\Writer::getPluginLoader()->getClassName($ext);
$className = Writer::getPluginLoader()->getClassName($ext);
$this->_extensions[$ext] = new $className();
$this->_extensions[$ext]->setEncoding($this->getEncoding());
}
Expand Down
17 changes: 9 additions & 8 deletions library/Zend/Feed/Writer/Deleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
* @namespace
*/
namespace Zend\Feed\Writer;
use Zend\Feed;
use Zend\Date;

use Zend\Feed\Exception as FeedException,
Zend\Date;

/**
* @uses \Zend\Date\Date
Expand Down Expand Up @@ -61,7 +62,7 @@ class Deleted
public function setEncoding($encoding)
{
if (empty($encoding) || !is_string($encoding)) {
throw new Feed\Exception('Invalid parameter: parameter must be a non-empty string');
throw new FeedException('Invalid parameter: parameter must be a non-empty string');
}
$this->_data['encoding'] = $encoding;
}
Expand Down Expand Up @@ -116,7 +117,7 @@ public function getType()
public function setReference($reference)
{
if (empty($reference) || !is_string($reference)) {
throw new Feed\Exception('Invalid parameter: reference must be a non-empty string');
throw new FeedException('Invalid parameter: reference must be a non-empty string');
}
$this->_data['reference'] = $reference;
}
Expand All @@ -139,7 +140,7 @@ public function setWhen($date = null)
} elseif ($date instanceof Date\Date) {
$zdate = $date;
} else {
throw new Feed\Exception('Invalid Zend_Date object or UNIX Timestamp passed as parameter');
throw new FeedException('Invalid Zend_Date object or UNIX Timestamp passed as parameter');
}
$this->_data['when'] = $zdate;
}
Expand All @@ -159,12 +160,12 @@ public function setBy(array $by)
|| empty($by['name'])
|| !is_string($by['name'])
) {
throw new Feed\Exception('Invalid parameter: author array must include a "name" key with a non-empty string value');
throw new FeedException('Invalid parameter: author array must include a "name" key with a non-empty string value');
}
$author['name'] = $by['name'];
if (isset($by['email'])) {
if (empty($by['email']) || !is_string($by['email'])) {
throw new Feed\Exception('Invalid parameter: "email" array value must be a non-empty string');
throw new FeedException('Invalid parameter: "email" array value must be a non-empty string');
}
$author['email'] = $by['email'];
}
Expand All @@ -173,7 +174,7 @@ public function setBy(array $by)
|| !is_string($by['uri'])
|| !\Zend\URI\URL::validate($by['uri'])
) {
throw new Feed\Exception('Invalid parameter: "uri" array value must be a non-empty string and valid URI/IRI');
throw new FeedException('Invalid parameter: "uri" array value must be a non-empty string and valid URI/IRI');
}
$author['uri'] = $by['uri'];
}
Expand Down
59 changes: 30 additions & 29 deletions library/Zend/Feed/Writer/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
* @namespace
*/
namespace Zend\Feed\Writer;
use Zend\Feed;

use Zend\Feed\Exception as FeedException;
use Zend\URI;
use Zend\Date;

Expand Down Expand Up @@ -89,12 +90,12 @@ public function addAuthor($name, $email = null, $uri = null)
|| empty($name['name'])
|| !is_string($name['name'])
) {
throw new Feed\Exception('Invalid parameter: author array must include a "name" key with a non-empty string value');
throw new FeedException('Invalid parameter: author array must include a "name" key with a non-empty string value');
}
$author['name'] = $name['name'];
if (isset($name['email'])) {
if (empty($name['email']) || !is_string($name['email'])) {
throw new Feed\Exception('Invalid parameter: "email" array value must be a non-empty string');
throw new FeedException('Invalid parameter: "email" array value must be a non-empty string');
}
$author['email'] = $name['email'];
}
Expand All @@ -103,7 +104,7 @@ public function addAuthor($name, $email = null, $uri = null)
|| !is_string($name['uri'])
|| !\Zend\URI\URL::validate($name['uri'])
) {
throw new Feed\Exception('Invalid parameter: "uri" array value must be a non-empty string and valid URI/IRI');
throw new FeedException('Invalid parameter: "uri" array value must be a non-empty string and valid URI/IRI');
}
$author['uri'] = $name['uri'];
}
Expand All @@ -113,18 +114,18 @@ public function addAuthor($name, $email = null, $uri = null)
*/
} else {
if (empty($name['name']) || !is_string($name['name'])) {
throw new Feed\Exception('Invalid parameter: "name" must be a non-empty string value');
throw new FeedException('Invalid parameter: "name" must be a non-empty string value');
}
$author['name'] = $name;
if (isset($email)) {
if (empty($email) || !is_string($email)) {
throw new Feed\Exception('Invalid parameter: "email" value must be a non-empty string');
throw new FeedException('Invalid parameter: "email" value must be a non-empty string');
}
$author['email'] = $email;
}
if (isset($uri)) {
if (empty($uri) || !is_string($uri) || !\Zend\URI\URL::validate($uri)) {
throw new Feed\Exception('Invalid parameter: "uri" value must be a non-empty string and valid URI/IRI');
throw new FeedException('Invalid parameter: "uri" value must be a non-empty string and valid URI/IRI');
}
$author['uri'] = $uri;
}
Expand Down Expand Up @@ -152,7 +153,7 @@ public function addAuthors(array $authors)
public function setEncoding($encoding)
{
if (empty($encoding) || !is_string($encoding)) {
throw new Feed\Exception('Invalid parameter: parameter must be a non-empty string');
throw new FeedException('Invalid parameter: parameter must be a non-empty string');
}
$this->_data['encoding'] = $encoding;
}
Expand All @@ -178,7 +179,7 @@ public function getEncoding()
public function setCopyright($copyright)
{
if (empty($copyright) || !is_string($copyright)) {
throw new Feed\Exception('Invalid parameter: parameter must be a non-empty string');
throw new FeedException('Invalid parameter: parameter must be a non-empty string');
}
$this->_data['copyright'] = $copyright;
}
Expand All @@ -191,7 +192,7 @@ public function setCopyright($copyright)
public function setContent($content)
{
if (empty($content) || !is_string($content)) {
throw new Feed\Exception('Invalid parameter: parameter must be a non-empty string');
throw new FeedException('Invalid parameter: parameter must be a non-empty string');
}
$this->_data['content'] = $content;
}
Expand All @@ -211,7 +212,7 @@ public function setDateCreated($date = null)
} elseif ($date instanceof Date\Date) {
$zdate = $date;
} else {
throw new Feed\Exception('Invalid Zend_Date object or UNIX Timestamp passed as parameter');
throw new FeedException('Invalid Zend_Date object or UNIX Timestamp passed as parameter');
}
$this->_data['dateCreated'] = $zdate;
}
Expand All @@ -231,7 +232,7 @@ public function setDateModified($date = null)
} elseif ($date instanceof Date\Date) {
$zdate = $date;
} else {
throw new Feed\Exception('Invalid Zend_Date object or UNIX Timestamp passed as parameter');
throw new FeedException('Invalid Zend_Date object or UNIX Timestamp passed as parameter');
}
$this->_data['dateModified'] = $zdate;
}
Expand All @@ -244,7 +245,7 @@ public function setDateModified($date = null)
public function setDescription($description)
{
if (empty($description) || !is_string($description)) {
throw new Feed\Exception('Invalid parameter: parameter must be a non-empty string');
throw new FeedException('Invalid parameter: parameter must be a non-empty string');
}
$this->_data['description'] = $description;
}
Expand All @@ -257,7 +258,7 @@ public function setDescription($description)
public function setId($id)
{
if (empty($id) || !is_string($id)) {
throw new Feed\Exception('Invalid parameter: parameter must be a non-empty string');
throw new FeedException('Invalid parameter: parameter must be a non-empty string');
}
$this->_data['id'] = $id;
}
Expand All @@ -270,7 +271,7 @@ public function setId($id)
public function setLink($link)
{
if (empty($link) || !is_string($link) || !\Zend\URI\URL::validate($link)) {
throw new Feed\Exception('Invalid parameter: parameter must be a non-empty string and valid URI/IRI');
throw new FeedException('Invalid parameter: parameter must be a non-empty string and valid URI/IRI');
}
$this->_data['link'] = $link;
}
Expand All @@ -283,7 +284,7 @@ public function setLink($link)
public function setCommentCount($count)
{
if (empty($count) || !is_numeric($count) || (int) $count < 0) {
throw new Feed\Exception('Invalid parameter: "count" must be a non-empty integer number');
throw new FeedException('Invalid parameter: "count" must be a non-empty integer number');
}
$this->_data['commentCount'] = (int) $count;
}
Expand All @@ -296,7 +297,7 @@ public function setCommentCount($count)
public function setCommentLink($link)
{
if (empty($link) || !is_string($link) || !\Zend\URI\URL::validate($link)) {
throw new Feed\Exception('Invalid parameter: "link" must be a non-empty string and valid URI/IRI');
throw new FeedException('Invalid parameter: "link" must be a non-empty string and valid URI/IRI');
}
$this->_data['commentLink'] = $link;
}
Expand All @@ -309,10 +310,10 @@ public function setCommentLink($link)
public function setCommentFeedLink(array $link)
{
if (!isset($link['uri']) || !is_string($link['uri']) || !\Zend\URI\URL::validate($link['uri'])) {
throw new Feed\Exception('Invalid parameter: "link" must be a non-empty string and valid URI/IRI');
throw new FeedException('Invalid parameter: "link" must be a non-empty string and valid URI/IRI');
}
if (!isset($link['type']) || !in_array($link['type'], array('atom', 'rss', 'rdf'))) {
throw new Feed\Exception('Invalid parameter: "type" must be one'
throw new FeedException('Invalid parameter: "type" must be one'
. ' of "atom", "rss" or "rdf"');
}
if (!isset($this->_data['commentFeedLinks'])) {
Expand Down Expand Up @@ -343,7 +344,7 @@ public function setCommentFeedLinks(array $links)
public function setTitle($title)
{
if (empty($title) || !is_string($title)) {
throw new Feed\Exception('Invalid parameter: parameter must be a non-empty string');
throw new FeedException('Invalid parameter: parameter must be a non-empty string');
}
$this->_data['title'] = $title;
}
Expand Down Expand Up @@ -527,7 +528,7 @@ public function getCommentFeedLinks()
public function addCategory(array $category)
{
if (!isset($category['term'])) {
throw new Feed\Exception('Each category must be an array and '
throw new FeedException('Each category must be an array and '
. 'contain at least a "term" element containing the machine '
. ' readable category name');
}
Expand All @@ -536,7 +537,7 @@ public function addCategory(array $category)
|| !is_string($category['scheme'])
|| !\Zend\URI\URL::validate($category['scheme'])
) {
throw new Feed\Exception('The Atom scheme or RSS domain of'
throw new FeedException('The Atom scheme or RSS domain of'
. ' a category must be a valid URI');
}
}
Expand Down Expand Up @@ -579,19 +580,19 @@ public function getCategories()
public function setEnclosure(array $enclosure)
{
if (!isset($enclosure['type'])) {
throw new Feed\Exception('Enclosure "type" is not set');
throw new FeedException('Enclosure "type" is not set');
}
if (!isset($enclosure['length'])) {
throw new Feed\Exception('Enclosure "length" is not set');
throw new FeedException('Enclosure "length" is not set');
}
if (!isset($enclosure['uri'])) {
throw new Feed\Exception('Enclosure "uri" is not set');
throw new FeedException('Enclosure "uri" is not set');
}
if (!\Zend\URI\URL::validate($enclosure['uri'])) {
throw new Feed\Exception('Enclosure "uri" is not a valid URI/IRI');
throw new FeedException('Enclosure "uri" is not a valid URI/IRI');
}
if ((int) $enclosure['length'] <= 0) {
throw new Feed\Exception('Enclosure "length" must be an integer'
throw new FeedException('Enclosure "length" must be an integer'
. ' indicating the content\'s length in bytes');
}
$this->_data['enclosure'] = $enclosure;
Expand Down Expand Up @@ -681,10 +682,10 @@ public function __call($method, $args)
foreach ($this->_extensions as $extension) {
try {
return call_user_func_array(array($extension, $method), $args);
} catch (Exception\InvalidMethodException $e) {
} catch (InvalidMethodException $e) {
}
}
throw new Feed\Exception('Method: ' . $method
throw new FeedException('Method: ' . $method
. ' does not exist and could not be located on a registered Extension');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
namespace Zend\Feed\Writer\Extension;

/**
* @uses \Zend\Feed\Writer\Extension\RendererInterface
* @uses \Zend\Feed\Writer\Extension
* @category Zend
* @package Zend_Feed_Writer_Entry_Rss
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class RendererAbstract
implements RendererInterface
abstract class AbstractRenderer implements Renderer
{
/**
* @var DOMDocument
Expand Down Expand Up @@ -86,7 +85,7 @@ public function __construct($container)
* Set feed encoding
*
* @param string $enc
* @return \Zend\Feed\Writer\Extension\RendererAbstract
* @return \Zend\Feed\Writer\Extension\AbstractRenderer
*/
public function setEncoding($enc)
{
Expand All @@ -109,7 +108,7 @@ public function getEncoding()
*
* @param DOMDocument $dom
* @param DOMElement $base
* @return \Zend\Feed\Writer\Extension\RendererAbstract
* @return \Zend\Feed\Writer\Extension\AbstractRenderer
*/
public function setDomDocument(\DOMDocument $dom, \DOMElement $base)
{
Expand All @@ -132,7 +131,7 @@ public function getDataContainer()
* Set feed type
*
* @param string $type
* @return \Zend\Feed\Writer\Extension\RendererAbstract
* @return \Zend\Feed\Writer\Extension\AbstractRenderer
*/
public function setType($type)
{
Expand All @@ -154,7 +153,7 @@ public function getType()
* Set root element of document
*
* @param DOMElement $root
* @return \Zend\Feed\Writer\Extension\RendererAbstract
* @return \Zend\Feed\Writer\Extension\AbstractRenderer
*/
public function setRootElement(\DOMElement $root)
{
Expand Down
Loading

0 comments on commit 871a8eb

Please sign in to comment.