diff --git a/.travis.yml b/.travis.yml index 73f4c14..8432b54 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,9 +16,11 @@ matrix: include: - php: 5.5 env: + - SERVICE_MANAGER_VERSION="^2.7.3" - EXECUTE_CS_CHECK=true - php: 5.6 env: + - SERVICE_MANAGER_VERSION="^2.7.3" - EXECUTE_TEST_COVERALLS=true - php: 7 - php: hhvm @@ -34,6 +36,8 @@ before_install: - if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi - composer self-update - if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi + - if [[ $SERVICE_MANAGER_VERSION != '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:$SERVICE_MANAGER_VERSION" ; fi + - if [[ $SERVICE_MANAGER_VERSION == '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:^3.0" ; fi install: - travis_retry composer install --no-interaction --ignore-platform-reqs diff --git a/composer.json b/composer.json index 3916e33..e35239f 100644 --- a/composer.json +++ b/composer.json @@ -15,14 +15,14 @@ "require": { "php": ">=5.5", "zendframework/zend-stdlib": "dev-develop as 2.8.0", - "zendframework/zend-servicemanager": "dev-develop as 2.7.0" + "zendframework/zend-servicemanager": "^2.7.3 || ^3.0" }, "minimum-stability": "dev", "prefer-stable": true, "extra": { "branch-alias": { "dev-master": "2.5-dev", - "dev-develop": "3.0-dev" + "dev-develop": "2.6-dev" } }, "autoload-dev": { diff --git a/src/Table/DecoratorManager.php b/src/Table/DecoratorManager.php index 750c11e..ea24c53 100644 --- a/src/Table/DecoratorManager.php +++ b/src/Table/DecoratorManager.php @@ -9,6 +9,7 @@ namespace Zend\Text\Table; +use Zend\ServiceManager\Exception\InvalidServiceException; use Zend\ServiceManager\Factory\InvokableFactory; use Zend\ServiceManager\AbstractPluginManager; @@ -28,16 +29,57 @@ class DecoratorManager extends AbstractPluginManager */ protected $aliases = [ 'ascii' => Decorator\Ascii::class, + 'Ascii' => Decorator\Ascii::class, 'blank' => Decorator\Blank::class, + 'Blank' => Decorator\Blank::class, 'unicode' => Decorator\Unicode::class, + 'Unicode' => Decorator\Unicode::class, ]; protected $factories = [ - Decorator\Ascii::class => InvokableFactory::class, - Decorator\Blank::class => InvokableFactory::class, - Decorator\Unicode::class => InvokableFactory::class, + Decorator\Ascii::class => InvokableFactory::class, + Decorator\Unicode::class => InvokableFactory::class, + Decorator\Blank::class => InvokableFactory::class, + 'zendtexttabledecoratorascii' => InvokableFactory::class, + 'zendtexttabledecoratorblank' => InvokableFactory::class, + 'zendtexttabledecoratorunicode' => InvokableFactory::class, ]; protected $instanceOf = Decorator\DecoratorInterface::class; + + /** + * {@inheritdoc} (v3) + */ + public function validate($instance) + { + if ($instance instanceof $this->instanceOf) { + // we're okay + return; + } + + throw new InvalidServiceException(sprintf( + 'Plugin of type %s is invalid; must implement %s\Decorator\DecoratorInterface', + (is_object($instance) ? get_class($instance) : gettype($instance)), + __NAMESPACE__ + )); + } + + /** + * Validate the plugin (v2) + * + * Checks that the decorator loaded is an instance of Decorator\DecoratorInterface. + * + * @param mixed $plugin + * @return void + * @throws Exception\InvalidDecoratorException if invalid + */ + public function validatePlugin($plugin) + { + try { + $this->validate($plugin); + } catch (InvalidServiceException $e) { + throw new Exception\InvalidDecoratorException($e->getMessage(), $e->getCode(), $e); + } + } } diff --git a/test/Table/DecoratorManagerTest.php b/test/Table/DecoratorManagerTest.php new file mode 100644 index 0000000..a7876ba --- /dev/null +++ b/test/Table/DecoratorManagerTest.php @@ -0,0 +1,37 @@ +