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

Commit

Permalink
Merge branch 'master' into rfc/escaper
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 24 changed files with 102 additions and 168 deletions.
54 changes: 19 additions & 35 deletions src/Cloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Tag;

use Zend\Config,
Zend\Tag\Exception\InvalidArgumentException,
use Traversable;
use Zend\Stdlib\ArrayUtils;
use Zend\Tag\Exception\InvalidArgumentException,
Zend\Loader\Broker;

/**
Expand All @@ -37,16 +35,16 @@
class Cloud
{
/**
* Decorator for the cloud
* DecoratorInterface for the cloud
*
* @var \Zend\Tag\Cloud\Decorator\Cloud
* @var Cloud
*/
protected $_cloudDecorator = null;

/**
* Decorator for the tags
* DecoratorInterface for the tags
*
* @var \Zend\Tag\Cloud\Decorator\Tag
* @var Tag
*/
protected $_tagDecorator = null;

Expand Down Expand Up @@ -77,32 +75,18 @@ class Cloud
/**
* Create a new tag cloud with options
*
* @param mixed $options
* @param array|Traversable $options
*/
public function __construct($options = null)
{
if ($options instanceof Config\Config) {
$this->setConfig($options);
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
}

if (is_array($options)) {
$this->setOptions($options);
}
}

/**
* Set options from Zend_Config
*
* @param \Zend\Config\Config $config
* @return \Zend\Tag\Cloud
*/
public function setConfig(Config\Config $config)
{
$this->setOptions($config->toArray());

return $this;
}

/**
* Set options from array
*
Expand Down Expand Up @@ -149,12 +133,12 @@ public function setTags(array $tags)
$itemList = $this->getItemList();

foreach ($tags as $tag) {
if ($tag instanceof Taggable) {
if ($tag instanceof TaggableInterface) {
$itemList[] = $tag;
} else if (is_array($tag)) {
$itemList[] = new Item($tag);
} else {
throw new InvalidArgumentException('Tag must be an instance of Zend\Tag\Taggable or an array');
throw new InvalidArgumentException('Tag must be an instance of Zend\Tag\TaggableInterface or an array');
}
}

Expand All @@ -164,19 +148,19 @@ public function setTags(array $tags)
/**
* Append a single tag to the cloud
*
* @param \Zend\Tag\Taggable|array $tag
* @param \Zend\Tag\TaggableInterface|array $tag
* @throws \Zend\Tag\Exception\InvalidArgumentException
* @return \Zend\Tag\Cloud
*/
public function appendTag($tag)
{
$tags = $this->getItemList();
if ($tag instanceof Taggable) {
if ($tag instanceof TaggableInterface) {
$tags[] = $tag;
} else if (is_array($tag)) {
$tags[] = new Item($tag);
} else {
throw new InvalidArgumentException('Tag must be an instance of Zend\Tag\Taggable or an array');
throw new InvalidArgumentException('Tag must be an instance of Zend\Tag\TaggableInterface or an array');
}

return $this;
Expand Down Expand Up @@ -235,7 +219,7 @@ public function setCloudDecorator($decorator)
}

if (!($decorator instanceof Cloud\Decorator\Cloud)) {
throw new InvalidArgumentException('Decorator is no instance of Zend\Tag\Cloud\Decorator\Cloud');
throw new InvalidArgumentException('DecoratorInterface is no instance of Zend\Tag\Cloud\Decorator\Cloud');
}

$this->_cloudDecorator = $decorator;
Expand All @@ -246,7 +230,7 @@ public function setCloudDecorator($decorator)
/**
* Get the decorator for the cloud
*
* @return \Zend\Tag\Cloud\Decorator\Cloud
* @return Cloud
*/
public function getCloudDecorator()
{
Expand Down Expand Up @@ -282,7 +266,7 @@ public function setTagDecorator($decorator)
}

if (!($decorator instanceof Cloud\Decorator\Tag)) {
throw new InvalidArgumentException('Decorator is no instance of Zend\Tag\Cloud\Decorator\Tag');
throw new InvalidArgumentException('DecoratorInterface is no instance of Zend\Tag\Cloud\Decorator\Tag');
}

$this->_tagDecorator = $decorator;
Expand All @@ -293,7 +277,7 @@ public function setTagDecorator($decorator)
/**
* Get the decorator for the tags
*
* @return \Zend\Tag\Cloud\Decorator\Tag
* @return Tag
*/
public function getTagDecorator()
{
Expand Down
14 changes: 6 additions & 8 deletions src/Cloud/Decorator/Cloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Tag\Cloud\Decorator;

use Zend\Tag\Cloud\Decorator;
use Traversable;
use Zend\Stdlib\ArrayUtils;
use Zend\Tag\Cloud\Decorator\DecoratorInterface as Decorator;

/**
* Abstract class for cloud decorators
Expand All @@ -49,14 +48,13 @@ abstract class Cloud implements Decorator
/**
* Create a new cloud decorator with options
*
* @param mixed $options
* @param array|Traversable $options
*/
public function __construct($options = null)
{
if ($options instanceof \Zend\Config\Config) {
$options = $options->toArray();
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
}

if (is_array($options)) {
$this->setOptions($options);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Tag\Cloud;
namespace Zend\Tag\Cloud\Decorator;

/**
* Interface for decorators
Expand All @@ -30,7 +30,7 @@
* @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 Decorator
interface DecoratorInterface
{
/**
* Constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Tag\Cloud\Decorator;
namespace Zend\Tag\Cloud\Decorator\Exception;

use Zend\Tag\Exception\ExceptionInterface as Exception;

/**
* Exception class for Zend_Tag_Cloud_Decorator
Expand All @@ -32,6 +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
*/
interface Exception extends \Zend\Tag\Exception
{
}
interface ExceptionInterface extends Exception
{}
9 changes: 6 additions & 3 deletions src/Cloud/Decorator/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

namespace Zend\Tag\Cloud\Decorator\Exception;

use Zend\Tag\Exception;

class InvalidArgumentException
extends \InvalidArgumentException
implements \Zend\Tag\Cloud\Decorator\Exception
{}
extends Exception\InvalidArgumentException
implements ExceptionInterface
{}
14 changes: 5 additions & 9 deletions src/Cloud/Decorator/HtmlCloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Tag\Cloud\Decorator;

/**
* Simple HTML decorator for clouds
*
* @uses \Zend\Tag\Cloud\Decorator\Cloud
* @category Zend
* @package Zend_Tag
* @uses \Zend\Tag\Cloud\Decorator\Cloud
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
Expand Down Expand Up @@ -71,7 +66,7 @@ public function getEncoding()
* Set encoding
*
* @param string
* @return \Zend\Tag\Cloud\Decorator\HTMLCloud
* @return HTMLCloud
*/
public function setEncoding($value)
{
Expand All @@ -83,7 +78,7 @@ public function setEncoding($value)
* Set the HTML tags surrounding all tags
*
* @param array $htmlTags
* @return \Zend\Tag\Cloud\Decorator\HTMLCloud
* @return HTMLCloud
*/
public function setHTMLTags(array $htmlTags)
{
Expand All @@ -105,7 +100,7 @@ public function getHTMLTags()
* Set the separator between the single tags
*
* @param string
* @return \Zend\Tag\Cloud\Decorator\HTMLCloud
* @return HTMLCloud
*/
public function setSeparator($separator)
{
Expand All @@ -127,12 +122,13 @@ public function getSeparator()
* Defined by Zend\Tag\Cloud\Decorator\Cloud
*
* @param array $tags
* @throws Exception\InvalidArgumentException
* @return string
*/
public function render($tags)
{
if (!is_array($tags)) {
throw new Exception(sprintf(
throw new Exception\InvalidArgumentException(sprintf(
'HtmlCloud::render() expects an array argument; received "%s"',
(is_object($tags) ? get_class($tags) : gettype($tags))
));
Expand Down
Loading

0 comments on commit ce9b366

Please sign in to comment.