Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/feed_writer-tests' of https://github.com/Maks3w/zf2
Browse files Browse the repository at this point in the history
 into hotfix/feed-authors
  • Loading branch information
Show file tree
Hide file tree
Showing 11 changed files with 729 additions and 717 deletions.
70 changes: 33 additions & 37 deletions src/Writer/AbstractFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,54 +62,50 @@ public function __construct()
/**
* Set a single author
*
* @param int $index
* @return string|null
* The following option keys are supported:
* 'name' => (string) The name
* 'email' => (string) An optional email
* 'uri' => (string) An optional and valid URI
*
* @param array $author
* @throws Exception\InvalidArgumentException If any value of $author not follow the format.
* @return void
*/
public function addAuthor($name, $email = null, $uri = null)
public function addAuthor(array $author)
{
$author = array();
if (is_array($name)) {
if (!array_key_exists('name', $name) || empty($name['name']) || !is_string($name['name'])) {
throw new Exception('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 Exception('Invalid parameter: "email" array value must be a non-empty string');
}
$author['email'] = $name['email'];
}
if (isset($name['uri'])) {
if (empty($name['uri']) || !is_string($name['uri']) || !Uri\UriFactory::factory($name['uri'])->isValid()) {
throw new Exception('Invalid parameter: "uri" array value must be a non-empty string and valid URI/IRI');
}
$author['uri'] = $name['uri'];
}
} else {
if (empty($name['name']) || !is_string($name['name'])) {
throw new Exception('Invalid parameter: "name" must be a non-empty string value');
}
$author['name'] = $name;
if (isset($email)) {
if (empty($email) || !is_string($email)) {
throw new Exception('Invalid parameter: "email" value must be a non-empty string');
}
$author['email'] = $email;
// Check array values
if (!array_key_exists('name', $author)
|| empty($author['name'])
|| !is_string($author['name'])
) {
throw new Exception\InvalidArgumentException(
'Invalid parameter: author array must include a "name" key with a non-empty string value');
}

if (isset($author['email'])) {
if (empty($author['email']) || !is_string($author['email'])) {
throw new Exception\InvalidArgumentException(
'Invalid parameter: "email" array value must be a non-empty string');
}
if (isset($uri)) {
if (empty($uri) || !is_string($uri) || !Uri\UriFactory::factory($uri)->isValid()) {
throw new Exception('Invalid parameter: "uri" value must be a non-empty string and valid URI/IRI');
}
$author['uri'] = $uri;
}
if (isset($author['uri'])) {
if (empty($author['uri']) || !is_string($author['uri']) ||
!Uri\UriFactory::factory($author['uri'])->isValid()
) {
throw new Exception\InvalidArgumentException(
'Invalid parameter: "uri" array value must be a non-empty string and valid URI/IRI');
}
}

$this->_data['authors'][] = $author;
}

/**
* Set an array with feed authors
*
* @return array
* @see addAuthor
* @param array $authors
* @return void
*/
public function addAuthors(array $authors)
{
Expand Down
77 changes: 33 additions & 44 deletions src/Writer/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,61 +69,50 @@ public function __construct()
/**
* Set a single author
*
* @param int $index
* @return string|null
* The following option keys are supported:
* 'name' => (string) The name
* 'email' => (string) An optional email
* 'uri' => (string) An optional and valid URI
*
* @param array $author
* @throws Exception\InvalidArgumentException If any value of $author not follow the format.
* @return void
*/
public function addAuthor($name, $email = null, $uri = null)
public function addAuthor(array $author)
{
$author = array();
if (is_array($name)) {
if (!array_key_exists('name', $name)
|| empty($name['name'])
|| !is_string($name['name'])
) {
throw new Exception('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 Exception('Invalid parameter: "email" array value must be a non-empty string');
}
$author['email'] = $name['email'];
}
if (isset($name['uri'])) {
if (empty($name['uri']) || !is_string($name['uri']) || !Uri\UriFactory::factory($name['uri'])->isValid()) {
throw new Exception('Invalid parameter: "uri" array value must be a non-empty string and valid URI/IRI');
}
$author['uri'] = $name['uri'];
}
/**
* @deprecated
* Array notation (above) is preferred and will be the sole supported input from ZF 2.0
*/
} else {
if (empty($name['name']) || !is_string($name['name'])) {
throw new Exception('Invalid parameter: "name" must be a non-empty string value');
}
$author['name'] = $name;
if (isset($email)) {
if (empty($email) || !is_string($email)) {
throw new Exception('Invalid parameter: "email" value must be a non-empty string');
}
$author['email'] = $email;
// Check array values
if (!array_key_exists('name', $author)
|| empty($author['name'])
|| !is_string($author['name'])
) {
throw new Exception\InvalidArgumentException(
'Invalid parameter: author array must include a "name" key with a non-empty string value');
}

if (isset($author['email'])) {
if (empty($author['email']) || !is_string($author['email'])) {
throw new Exception\InvalidArgumentException(
'Invalid parameter: "email" array value must be a non-empty string');
}
if (isset($uri)) {
if (empty($uri) || !is_string($uri) || !Uri\UriFactory::factory($uri)->isValid()) {
throw new Exception('Invalid parameter: "uri" array value must be a non-empty string and valid URI/IRI');
}
$author['uri'] = $uri;
}
if (isset($author['uri'])) {
if (empty($author['uri']) || !is_string($author['uri']) ||
!Uri\UriFactory::factory($author['uri'])->isValid()
) {
throw new Exception\InvalidArgumentException(
'Invalid parameter: "uri" array value must be a non-empty string and valid URI/IRI');
}
}

$this->_data['authors'][] = $author;
}

/**
* Set an array with feed authors
*
* @return array
* @see addAuthor
* @param array $authors
* @return void
*/
public function addAuthors(array $authors)
{
Expand Down
37 changes: 37 additions & 0 deletions src/Writer/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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 [email protected] so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Feed
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Feed\Writer\Exception;

/**
* Feed exceptions
*
* Interface to represent exceptions that occur during Feed operations.
*
* @todo This Exception is pending of exception's milestone
*
* @category Zend
* @package Zend_Feed
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface ExceptionInterface
{
}
4 changes: 1 addition & 3 deletions src/Writer/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

namespace Zend\Feed\Writer\Exception;

use Zend\Feed\Writer\Exception;

/**
* Feed exceptions
*
Expand All @@ -36,5 +34,5 @@
*/
class InvalidArgumentException
extends \InvalidArgumentException
implements Exception
implements ExceptionInterface
{}
8 changes: 1 addition & 7 deletions src/Writer/Exception/InvalidMethodException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@

namespace Zend\Feed\Writer\Exception;

/**
* @see Zend_Feed_Exception
*/
require_once 'Zend/Feed/Exception.php';


/**
* Feed exceptions
*
Expand All @@ -37,5 +31,5 @@
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class InvalidMethodException extends \Exception
class InvalidMethodException extends \Exception implements ExceptionInterface
{}
Loading

0 comments on commit 1169a58

Please sign in to comment.