-
Notifications
You must be signed in to change notification settings - Fork 53
[WIP] ServiceManager v2 + v3 compatibility #64
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to future selves: we'll want to update this to a tagged version once we've tagged a version containing the SM/EM updates. |
||
"fabpot/php-cs-fixer": "1.7.*", | ||
"phpunit/PHPUnit": "~4.0" | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,12 +43,52 @@ class PatternPluginManager extends AbstractPluginManager | |
/** | ||
* Don't share by default | ||
* | ||
* @var array | ||
* @var boolean | ||
*/ | ||
protected $shareByDefault = false; | ||
|
||
/** | ||
* Don't share by default | ||
* | ||
* @var boolean | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ezimuel can you please write in the doc-block which property belongs to which service manager version as for me this looks like a mistake. |
||
*/ | ||
protected $sharedByDefault = false; | ||
|
||
/** | ||
* @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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an empty line following this new method. (CS) |
||
|
||
/** | ||
* 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 | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,8 +76,48 @@ class AdapterPluginManager extends AbstractPluginManager | |
*/ | ||
protected $sharedByDefault = false; | ||
|
||
/** | ||
* Don't share by default | ||
* | ||
* @var boolean | ||
*/ | ||
protected $shareByDefault = false; | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
* @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); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
w00t! we can use tagged versions!