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

Updated factories, reverted validatePlugin for v2-v3 compat #9

Merged
merged 2 commits into from
Feb 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ matrix:
include:
- php: 5.5
env:
- SERVICE_MANAGER_VERSION="^2.7.3"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All references to 2.7.3 and 3.0 need to be updated to 2.7.5 and 3.0.3, respectively, as those are the versions adding the CommonPluginManagerTrait. I can take care of that on merge, however.

- EXECUTE_CS_CHECK=true
- php: 5.6
env:
- SERVICE_MANAGER_VERSION="^2.7.3"
- EXECUTE_TEST_COVERALLS=true
- php: 7
- php: hhvm
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
"require": {
"php": ">=5.5",
"zendframework/zend-stdlib": "dev-develop as 2.8.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be updated to ^2.7 || ^3.0; I'll do that on merge.

"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": {
Expand Down
48 changes: 45 additions & 3 deletions src/Table/DecoratorManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Zend\Text\Table;

use Zend\ServiceManager\Exception\InvalidServiceException;
use Zend\ServiceManager\Factory\InvokableFactory;
use Zend\ServiceManager\AbstractPluginManager;

Expand All @@ -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);
}
}
}
37 changes: 37 additions & 0 deletions test/Table/DecoratorManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Text\Table;

use PHPUnit_Framework_TestCase as TestCase;
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\Test\CommonPluginManagerTrait;
use Zend\Text\Table\Decorator\DecoratorInterface;
use Zend\Text\Table\DecoratorManager;
use Zend\Text\Table\Exception\InvalidDecoratorException;

class DecoratorManagerTest extends TestCase
{
use CommonPluginManagerTrait;

protected function getPluginManager()
{
return new DecoratorManager(new ServiceManager());
}

protected function getV2InvalidPluginException()
{
return InvalidDecoratorException::class;
}

protected function getInstanceOf()
{
return DecoratorInterface::class;
}
}