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

Code refactor to support SM v2 + v3 #10

Merged
merged 4 commits into from
Feb 3, 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
18 changes: 16 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,25 @@ matrix:
- php: 5.5
env:
- EXECUTE_CS_CHECK=true
- php: 5.5
env:
- SERVICE_MANAGER_VERSION='^2.7.3'
- php: 5.6
env:
- EXECUTE_TEST_COVERALLS=true
- php: 5.6
env:
- SERVICE_MANAGER_VERSION='^2.7.3'
- php: 7
- php: hhvm
allow_failures:
- php: 7
env:
- SERVICE_MANAGER_VERSION='^2.7.3'
- php: hhvm
- php: hhvm
env:
- SERVICE_MANAGER_VERSION='^2.7.3'
allow_failures:
- php: hhvm

notifications:
irc: "irc.freenode.org#zftalk.dev"
Expand All @@ -33,6 +45,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
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"require": {
"php": ">=5.5",
"zendframework/zend-escaper": "~2.5",
"zendframework/zend-stdlib": "~2.5"
"zendframework/zend-stdlib": "^3.0"
},
"require-dev": {
"zendframework/zend-config": "~2.5",
"zendframework/zend-servicemanager": "dev-develop as 2.7.0",
"zendframework/zend-config": "dev-develop as 2.6.0",
"zendframework/zend-servicemanager": "^2.7.4 || ^3.0.3",
"fabpot/php-cs-fixer": "1.7.*",
"phpunit/PHPUnit": "~4.0"
},
Expand Down
44 changes: 44 additions & 0 deletions src/Cloud/DecoratorPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

namespace Zend\Tag\Cloud;

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

/**
* Plugin manager implementation for decorators.
Expand All @@ -37,7 +39,49 @@ class DecoratorPluginManager extends AbstractPluginManager
protected $factories = [
Decorator\HtmlCloud::class => InvokableFactory::class,
Decorator\HtmlTag::class => InvokableFactory::class,
// Legacy (v2) due to alias resolution; canonical form of resolved
// alias is used to look up the factory, while the non-normalized
// resolved alias is used as the requested name passed to the factory.
'zendtagclouddecoratorhtmlcloud' => InvokableFactory::class,
'zendtagclouddecoratorhtmltag' => InvokableFactory::class
];

protected $instanceOf = Decorator\DecoratorInterface::class;

/**
* Validate the plugin is of the expected type (v3).
*
* Validates against `$instanceOf`.
*
* @param mixed $instance
* @throws InvalidServiceException
*/
public function validate($instance)
{
if (! $instance instanceof $this->instanceOf) {
throw new InvalidServiceException(sprintf(
'%s can only create instances of %s; %s is invalid',
get_class($this),
$this->instanceOf,
(is_object($instance) ? get_class($instance) : gettype($instance))
));
}
}

/**
* Validate the plugin is of the expected type (v2).
*
* Proxies to `validate()`.
*
* @param mixed $instance
* @throws InvalidServiceException
*/
public function validatePlugin($instance)
{
try {
$this->validate($instance);
} catch (InvalidServiceException $e) {
throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
}
}
}
10 changes: 10 additions & 0 deletions test/Cloud/CloudTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use stdClass;
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\Config as SMConfig;
use Zend\Tag;
use Zend\Tag\Cloud;
use Zend\Tag\Cloud\Decorator\HtmlCloud;
Expand Down Expand Up @@ -320,12 +321,21 @@ protected function getCloud($options = null, $setDecoratorPluginManager = true)

if ($setDecoratorPluginManager) {
$decorators = $cloud->getDecoratorPluginManager();
/*
$decorators->configure([
'invokables' => [
'CloudDummy' => CloudDummy::class,
'TagDummy' => TagDummy::class
]
]);
*/
$smConfig = new SMConfig([
'invokables' => [
'CloudDummy' => CloudDummy::class,
'TagDummy' => TagDummy::class
]
]);
$smConfig->configureServiceManager($decorators);
}

return $cloud;
Expand Down
38 changes: 38 additions & 0 deletions test/Cloud/Decorator/DecoratorPluginManagerCompatibilityTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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\ServiceManager;

use PHPUnit_Framework_TestCase as TestCase;
use Zend\ServiceManager\ServiceManager;
use Zend\Tag\Cloud\DecoratorPluginManager;
use Zend\Tag\Cloud\Decorator\DecoratorInterface;
use Zend\ServiceManager\Test\CommonPluginManagerTrait;

/**
* Example test of using CommonPluginManagerTrait
*/
class DecoratorPluginManagerCompatibilityTest extends TestCase
{
use CommonPluginManagerTrait;

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

protected function getV2InvalidPluginException()
{
return \RuntimeException::class;
}

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