diff --git a/.travis.yml b/.travis.yml index a0e0b75f7..12b898d8f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,16 +38,23 @@ matrix: - php: 5.5 env: - EXECUTE_CS_CHECK=true - - PECL_INSTALL_APCU='apcu-4.0.8' + - php: 5.5 + env: + - SERVICE_MANAGER_V2=true - php: 5.6 env: - EXECUTE_TEST_COVERALLS=true - - PECL_INSTALL_APCU='apcu-4.0.8' + - php: 5.6 + env: + - SERVICE_MANAGER_V2=true + - php: 7 - php: 7 env: - - PECL_INSTALL_APCU='apcu' - - PECL_INSTALL_APCU_BC='apcu_bc-beta' + - SERVICE_MANAGER_V2=true + - php: hhvm - php: hhvm + env: + - SERVICE_MANAGER_V2=true allow_failures: - php: 7 - php: hhvm @@ -60,11 +67,13 @@ 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_V2 == 'true' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:^2.7.2" ; fi + - if [[ $SERVICE_MANAGER_V2 != 'true' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:^3.0" ; fi install: - travis_retry composer install --no-interaction --ignore-platform-reqs - if [[ $PECL_INSTALL_APCU != '' ]]; then echo "yes\nno\n" | pecl install $PECL_INSTALL_APCU || return 0 ; fi - + # see https://pear.php.net/bugs/bug.php?id=21007 # pecl install adds the "extension=*.so" directive on top of php.ini which results in wrong extension order # -> Attach another ini file loading the extension kind of solves the issue. diff --git a/composer.json b/composer.json index ff2960c15..272ddaa88 100644 --- a/composer.json +++ b/composer.json @@ -14,13 +14,13 @@ }, "require": { "php": ">=5.5", - "zendframework/zend-stdlib": "~2.5", - "zendframework/zend-servicemanager": "dev-develop as 2.7.0", - "zendframework/zend-eventmanager": "dev-develop as 2.7.0" + "zendframework/zend-stdlib": "~2.7", + "zendframework/zend-servicemanager": "^2.7.3 || ^3.0", + "zendframework/zend-eventmanager": "^2.6.2 || ^3.0" }, "require-dev": { "zendframework/zend-serializer": "dev-develop as 2.6.0", - "zendframework/zend-session": "~2.5", + "zendframework/zend-session": "dev-develop as 2.6.0", "fabpot/php-cs-fixer": "1.7.*", "phpunit/PHPUnit": "~4.0" }, diff --git a/src/PatternPluginManager.php b/src/PatternPluginManager.php index fdb7c98b8..6377a793a 100644 --- a/src/PatternPluginManager.php +++ b/src/PatternPluginManager.php @@ -11,6 +11,7 @@ use Zend\ServiceManager\AbstractPluginManager; use Zend\ServiceManager\Factory\InvokableFactory; +use Zend\ServiceManager\Exception\InvalidServiceException; /** * Plugin manager implementation for cache pattern adapters @@ -42,7 +43,14 @@ class PatternPluginManager extends AbstractPluginManager /** * Don't share by default * - * @var array + * @var boolean + */ + protected $shareByDefault = false; + + /** + * Don't share by default + * + * @var boolean */ protected $sharedByDefault = false; @@ -50,4 +58,37 @@ class PatternPluginManager extends AbstractPluginManager * @var string */ protected $instanceOf = Pattern\PatternInterface::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) + { + $this->validate($instance); + } } diff --git a/src/Service/StorageCacheAbstractServiceFactory.php b/src/Service/StorageCacheAbstractServiceFactory.php index e028f3c72..d40d4a83b 100644 --- a/src/Service/StorageCacheAbstractServiceFactory.php +++ b/src/Service/StorageCacheAbstractServiceFactory.php @@ -35,7 +35,7 @@ class StorageCacheAbstractServiceFactory implements AbstractFactoryInterface * @param string $requestedName * @return boolean */ - public function canCreateServiceWithName(ContainerInterface $container, $requestedName) + public function canCreate(ContainerInterface $container, $requestedName) { $config = $this->getConfig($container); if (empty($config)) { @@ -44,6 +44,17 @@ public function canCreateServiceWithName(ContainerInterface $container, $request return (isset($config[$requestedName]) && is_array($config[$requestedName])); } + /** + * @param ServiceLocatorInterface $serviceLocator + * @param string $name + * @param string $requestedName + * @return boolean + */ + public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) + { + return $this->canCreate($serviceLocator, $requestedName); + } + /** * Create an object * @@ -58,6 +69,11 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o return StorageFactory::factory($config[$requestedName]); } + public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) + { + return $this($serviceLocator, $requestedName); + } + /** * Retrieve cache configuration, if any * diff --git a/src/Storage/AdapterPluginManager.php b/src/Storage/AdapterPluginManager.php index 5551d199e..9dc075746 100644 --- a/src/Storage/AdapterPluginManager.php +++ b/src/Storage/AdapterPluginManager.php @@ -76,8 +76,48 @@ class AdapterPluginManager extends AbstractPluginManager */ protected $sharedByDefault = false; + /** + * Don't share by default + * + * @var boolean + */ + protected $shareByDefault = false; + /** * @var string */ protected $instanceOf = StorageInterface::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) + { + $this->validate($instance); + } }