diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 21d57da..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "tools/phptools"] - path = tools/phptools - url = git://github.com/ralphschindler/PHPTools.git diff --git a/.travis/run-tests.sh b/.travis/run-tests.sh deleted file mode 100755 index a84e0ba..0000000 --- a/.travis/run-tests.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -travisdir=$(dirname "$0") -testdir="$travisdir/../tests" -testedcomponents=(`cat "$travisdir/tested-components"`) -result=0 - -for tested in "${testedcomponents[@]}" - do - echo "$tested:" - phpunit -c $testdir/phpunit.xml.dist $testdir/$tested - result=$(($result || $?)) -done - -exit $result diff --git a/.travis/skipped-components b/.travis/skipped-components deleted file mode 100644 index 171dfe9..0000000 --- a/.travis/skipped-components +++ /dev/null @@ -1,7 +0,0 @@ -Zend/Amf -Zend/Date -Zend/Dojo -Zend/Queue -Zend/Service -Zend/Test -Zend/Wildfire diff --git a/.travis/tested-components b/.travis/tested-components deleted file mode 100644 index b0b9438..0000000 --- a/.travis/tested-components +++ /dev/null @@ -1,61 +0,0 @@ -Zend/Acl -Zend/Authentication -Zend/Barcode -Zend/Cache -Zend/Captcha -Zend/Cloud -Zend/Code -Zend/Config -Zend/Console -Zend/Crypt -Zend/Currency -Zend/Db -Zend/Di -Zend/DocBook -Zend/Dojo -Zend/Dom -Zend/EventManager -Zend/Feed -Zend/File -Zend/Filter -Zend/Form -Zend/GData -Zend/Http -Zend/InfoCard -Zend/InputFilter -Zend/Json -Zend/Ldap -Zend/Loader -Zend/Locale -Zend/Log -Zend/Mail -Zend/Markup -Zend/Math -Zend/Measure -Zend/Memory -Zend/Mime -Zend/ModuleManager -Zend/Mvc -Zend/Navigation -Zend/OAuth -Zend/OpenId -Zend/Paginator -Zend/Pdf -Zend/ProgressBar -Zend/RegistryTest.php -Zend/Rest -Zend/Search -Zend/Serializer -Zend/Server -Zend/Session -Zend/Soap -Zend/Stdlib -Zend/Tag -Zend/Text -Zend/TimeSync -Zend/Translator -Zend/Uri -Zend/Validator -Zend/VersionTest.php -Zend/View -Zend/XmlRpc diff --git a/composer.json b/composer.json index cf46b02..77c2c66 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "zendframework/zend-tag", - "description": "Zend\\Tag component", + "description": "a component suite which provides a facility to work with taggable Items", "license": "BSD-3-Clause", "keywords": [ "zf2", @@ -9,11 +9,11 @@ "homepage": "https://github.com/zendframework/zend-tag", "autoload": { "psr-4": { - "Zend\\Tag\\": "src/" + "Zend\\Tag": "src/" } }, "require": { - "php": ">=5.3.23", + "php": ">=5.3.3", "zendframework/zend-escaper": "self.version", "zendframework/zend-stdlib": "self.version" }, diff --git a/src/Cloud.php b/src/Cloud.php index 6fc8cb9..876986f 100644 --- a/src/Cloud.php +++ b/src/Cloud.php @@ -1,36 +1,21 @@ getItemList(); - foreach ($tags as $tag) { - 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\TaggableInterface or an array'); - } + $this->appendTag($tag); } - return $this; } /** * Append a single tag to the cloud * - * @param \Zend\Tag\TaggableInterface|array $tag - * @throws \Zend\Tag\Exception\InvalidArgumentException - * @return \Zend\Tag\Cloud + * @param TaggableInterface|array $tag + * @throws Exception\InvalidArgumentException + * @return Cloud */ public function appendTag($tag) { $tags = $this->getItemList(); + 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\TaggableInterface or an array'); + return $this; + } + + if (!is_array($tag)) { + throw new Exception\InvalidArgumentException(sprintf( + 'Tag must be an instance of %s\TaggableInterface or an array; received "%s"', + __NAMESPACE__, + (is_object($tag) ? get_class($tag) : gettype($tag)) + )); } + $tags[] = new Item($tag); + return $this; } /** * Set the item list * - * @param \Zend\Tag\ItemList $itemList - * @return \Zend\Tag\Cloud + * @param ItemList $itemList + * @return Cloud */ public function setItemList(ItemList $itemList) { @@ -183,7 +166,7 @@ public function setItemList(ItemList $itemList) * * If item list is undefined, creates one. * - * @return \Zend\Tag\ItemList + * @return ItemList */ public function getItemList() { @@ -197,8 +180,8 @@ public function getItemList() * Set the decorator for the cloud * * @param mixed $decorator - * @throws \Zend\Tag\Exception\InvalidArgumentException - * @return \Zend\Tag\Cloud + * @throws Exception\InvalidArgumentException + * @return Cloud */ public function setCloudDecorator($decorator) { @@ -215,11 +198,11 @@ public function setCloudDecorator($decorator) } if (is_string($decorator)) { - $decorator = $this->getDecoratorBroker()->load($decorator, $options); + $decorator = $this->getDecoratorPluginManager()->get($decorator, $options); } - if (!($decorator instanceof Cloud\Decorator\Cloud)) { - throw new InvalidArgumentException('DecoratorInterface is no instance of Zend\Tag\Cloud\Decorator\Cloud'); + if (!($decorator instanceof Cloud\Decorator\AbstractCloud)) { + throw new Exception\InvalidArgumentException('DecoratorInterface is no instance of Cloud\Decorator\AbstractCloud'); } $this->_cloudDecorator = $decorator; @@ -244,8 +227,8 @@ public function getCloudDecorator() * Set the decorator for the tags * * @param mixed $decorator - * @throws \Zend\Tag\Exception\InvalidArgumentException - * @return \Zend\Tag\Cloud + * @throws Exception\InvalidArgumentException + * @return Cloud */ public function setTagDecorator($decorator) { @@ -262,11 +245,11 @@ public function setTagDecorator($decorator) } if (is_string($decorator)) { - $decorator = $this->getDecoratorBroker()->load($decorator, $options); + $decorator = $this->getDecoratorPluginManager()->get($decorator, $options); } - if (!($decorator instanceof Cloud\Decorator\Tag)) { - throw new InvalidArgumentException('DecoratorInterface is no instance of Zend\Tag\Cloud\Decorator\Tag'); + if (!($decorator instanceof Cloud\Decorator\AbstractTag)) { + throw new Exception\InvalidArgumentException('DecoratorInterface is no instance of Cloud\Decorator\Tag'); } $this->_tagDecorator = $decorator; @@ -288,29 +271,29 @@ public function getTagDecorator() } /** - * Set plugin broker for use with decorators + * Set plugin manager for use with decorators * - * @param \Zend\Loader\Broker $broker - * @return \Zend\Tag\Cloud + * @param Cloud\DecoratorPluginManager $decorators + * @return Cloud */ - public function setDecoratorBroker(Broker $broker) + public function setDecoratorPluginManager(Cloud\DecoratorPluginManager $decorators) { - $this->_decoratorBroker = $broker; + $this->_decorators = $decorators; return $this; } /** - * Get the plugin broker for decorators + * Get the plugin manager for decorators * - * @return \Zend\Loader\Broker + * @return Cloud\DecoratorPluginManager */ - public function getDecoratorBroker() + public function getDecoratorPluginManager() { - if ($this->_decoratorBroker === null) { - $this->_decoratorBroker = new Cloud\DecoratorBroker(); + if ($this->_decorators === null) { + $this->_decorators = new Cloud\DecoratorPluginManager(); } - return $this->_decoratorBroker; + return $this->_decorators; } /** diff --git a/src/Cloud/Decorator/Cloud.php b/src/Cloud/Decorator/AbstractCloud.php similarity index 58% rename from src/Cloud/Decorator/Cloud.php rename to src/Cloud/Decorator/AbstractCloud.php index 81b6aa9..faba86a 100644 --- a/src/Cloud/Decorator/Cloud.php +++ b/src/Cloud/Decorator/AbstractCloud.php @@ -1,22 +1,11 @@ 'Zend\Tag\Cloud\Decorator\HtmlCloud', - 'htmlcloud' => 'Zend\Tag\Cloud\Decorator\HtmlCloud', - 'html_tag' => 'Zend\Tag\Cloud\Decorator\HtmlTag', - 'htmltag' => 'Zend\Tag\Cloud\Decorator\HtmlTag', - 'tag' => 'Zend\Tag\Cloud\Decorator\Tag', - ); -} diff --git a/src/Cloud/DecoratorPluginManager.php b/src/Cloud/DecoratorPluginManager.php new file mode 100644 index 0000000..d39f5ed --- /dev/null +++ b/src/Cloud/DecoratorPluginManager.php @@ -0,0 +1,64 @@ + 'Zend\Tag\Cloud\Decorator\HtmlCloud', + 'htmltag' => 'Zend\Tag\Cloud\Decorator\HtmlTag', + 'tag' => 'Zend\Tag\Cloud\Decorator\Tag', + ); + + /** + * Validate the plugin + * + * Checks that the decorator loaded is an instance + * of Decorator\DecoratorInterface. + * + * @param mixed $plugin + * @return void + * @throws Exception\InvalidArgumentException if invalid + */ + public function validatePlugin($plugin) + { + if ($plugin instanceof Decorator\DecoratorInterface) { + // we're okay + return; + } + + throw new Exception\InvalidArgumentException(sprintf( + 'Plugin of type %s is invalid; must implement %s\Decorator\DecoratorInterface', + (is_object($plugin) ? get_class($plugin) : gettype($plugin)), + __NAMESPACE__ + )); + } +} + diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index 1dc92e7..dc8ce57 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -1,21 +1,11 @@ _getCloud(); - try { - $cloud->setCloudDecorator(new \stdClass()); - $this->fail('An expected Zend\Tag\Exception\InvalidArgumentException was not raised'); - } catch (InvalidArgumentException $e) { - $this->assertEquals('DecoratorInterface is no instance of Zend\Tag\Cloud\Decorator\Cloud', $e->getMessage()); - } + $this->setExpectedException('Zend\Tag\Exception\InvalidArgumentException', 'DecoratorInterface'); + $cloud->setCloudDecorator(new \stdClass()); } public function testSetTagDecoratorViaArray() @@ -102,27 +83,23 @@ public function testSetInvalidTagDecorator() { $cloud = $this->_getCloud(); - try { - $cloud->setTagDecorator(new \stdClass()); - $this->fail('An expected Zend\Tag\Exception\InvalidArgumentException was not raised'); - } catch (InvalidArgumentException $e) { - $this->assertEquals('DecoratorInterface is no instance of Zend\Tag\Cloud\Decorator\Tag', $e->getMessage()); - } + $this->setExpectedException('Zend\Tag\Exception\InvalidArgumentException', 'DecoratorInterface'); + $cloud->setTagDecorator(new \stdClass()); } - public function testSetDecoratorBroker() + public function testSetDecoratorPluginManager() { - $broker = new PluginBroker(); - $cloud = $this->_getCloud(array(), null); - $cloud->setDecoratorBroker($broker); - $this->assertSame($broker, $cloud->getDecoratorBroker()); + $decorators = new DecoratorPluginManager(); + $cloud = $this->_getCloud(array(), null); + $cloud->setDecoratorPluginManager($decorators); + $this->assertSame($decorators, $cloud->getDecoratorPluginManager()); } - public function testSetDecoratorBrokerViaOptions() + public function testSetDecoratorPluginManagerViaOptions() { - $broker = new PluginBroker(); - $cloud = $this->_getCloud(array('decoratorBroker' => $broker), null); - $this->assertSame($broker, $cloud->getDecoratorBroker()); + $decorators = new DecoratorPluginManager(); + $cloud = $this->_getCloud(array('decoratorPluginManager' => $decorators), null); + $this->assertSame($decorators, $cloud->getDecoratorPluginManager()); } public function testAppendTagAsArray() @@ -149,12 +126,8 @@ public function testAppendInvalidTag() { $cloud = $this->_getCloud(); - try { - $cloud->appendTag('foo'); - $this->fail('An expected Zend\Tag\Exception\InvalidArgumentException was not raised'); - } catch (InvalidArgumentException $e) { - $this->assertEquals('Tag must be an instance of Zend\Tag\TaggableInterface or an array', $e->getMessage()); - } + $this->setExpectedException('Zend\Tag\Exception\InvalidArgumentException', 'TaggableInterface'); + $cloud->appendTag('foo'); } public function testSetTagsAsArray() @@ -197,12 +170,8 @@ public function testSetInvalidTags() { $cloud = $this->_getCloud(); - try { - $cloud->setTags(array('foo')); - $this->fail('An expected Zend\Tag\Exception\InvalidArgumentException was not raised'); - } catch (InvalidArgumentException $e) { - $this->assertEquals('Tag must be an instance of Zend\Tag\TaggableInterface or an array', $e->getMessage()); - } + $this->setExpectedException('Zend\Tag\Exception\InvalidArgumentException', 'TaggableInterface'); + $cloud->setTags(array('foo')); } public function testConstructorWithArray() @@ -262,18 +231,16 @@ public function testRenderViaToString() $this->assertEquals($expected, (string) $cloud); } - protected function _getCloud($options = null, $setDecoratorBroker = true) + protected function _getCloud($options = null, $setDecoratorPluginManager = true) { $cloud = new Tag\Cloud($options); - if ($setDecoratorBroker) { - $loader = $cloud->getDecoratorBroker()->getClassLoader(); - $loader->registerPlugins(array( - 'clouddummy' => 'ZendTest\Tag\Cloud\TestAsset\CloudDummy', - 'clouddummy1' => 'ZendTest\Tag\Cloud\TestAsset\CloudDummy1', - 'clouddummy2' => 'ZendTest\Tag\Cloud\TestAsset\CloudDummy2', - 'tagdummy' => 'ZendTest\Tag\Cloud\TestAsset\TagDummy', - )); + if ($setDecoratorPluginManager) { + $decorators = $cloud->getDecoratorPluginManager(); + $decorators->setInvokableClass('clouddummy', 'ZendTest\Tag\Cloud\TestAsset\CloudDummy'); + $decorators->setInvokableClass('clouddummy1', 'ZendTest\Tag\Cloud\TestAsset\CloudDummy1'); + $decorators->setInvokableClass('clouddummy2', 'ZendTest\Tag\Cloud\TestAsset\CloudDummy2'); + $decorators->setInvokableClass('tagdummy', 'ZendTest\Tag\Cloud\TestAsset\TagDummy'); } return $cloud; diff --git a/test/Cloud/Decorator/HtmlCloudTest.php b/test/Cloud/Decorator/HtmlCloudTest.php index f3b1067..9ddfe38 100644 --- a/test/Cloud/Decorator/HtmlCloudTest.php +++ b/test/Cloud/Decorator/HtmlCloudTest.php @@ -1,22 +1,11 @@