This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
[WIP] ServiceManager v2 + v3 compatibility #64
Closed
ezimuel
wants to merge
4
commits into
zendframework:develop
from
ezimuel:feature/servicemanager-v2-v3
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,16 @@ 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 +68,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 | ||
* | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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!