This repository was archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Code refactor to support SM v2 + v3 #10
Merged
Merged
Changes from 2 commits
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
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
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 decorators. | ||
|
@@ -40,4 +41,37 @@ class DecoratorPluginManager extends AbstractPluginManager | |
]; | ||
|
||
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) | ||
{ | ||
$this->validate($instance); | ||
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. Take a look at zendframework/zend-servicemanager#93 — the author details having We don't 100% need to do that, but it would ensure that if users are doing try/catch around calls to the plugin manager, those don't break. 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. @weierophinney I really like the idea to throw exception on validatePlugin(), I'm changing this, thanks! |
||
} | ||
} |
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
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.
I wonder if we should finish up zend-stdlib and tag it before merging this; would make things simpler. :)
Same goes for zend-config, below.
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.
@weierophinney I think we can tag 2.8 of zend-stdlib and 2.6 of zend-config, we have a ton of usage around with "dev-develop as".