This repository was archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
[WIP] Migrate to ZF3 components #86
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
74c99ae
Migrate to ZF3 components
9d94040
Changed $shareByDefault to $sharedByDefault
kynx 6c66a9f
Merge pull request #1 from kynx/feature/zf3-improvement
35a6179
Made initialiser v2-v3 compatible
kynx 8b2d008
Merge pull request #2 from kynx/feature/zf3-improvement
6e2b154
Moved population of factory plugin managers from Factory to InputFilt…
kynx da7a19c
Proxied InputFilterAbstractServiceFactory::canCreateServiceWithName()
kynx e29eedd
Final test fix!
kynx 4ff1e96
CS fixes
kynx 843e7dd
composer dependencies and travis setup
kynx 436c027
v2 BC fixes
kynx 2cd3c02
Backing out travis changes until zend-filter and zend-validator are BC
kynx 6efd7e0
Merge pull request #3 from kynx/zf3-zf2-compatibility
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -9,9 +9,9 @@ | |
|
||
namespace Zend\InputFilter; | ||
|
||
use Interop\Container\ContainerInterface; | ||
use Zend\ServiceManager\AbstractPluginManager; | ||
use Zend\ServiceManager\ConfigInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
use Zend\ServiceManager\Factory\InvokableFactory; | ||
use Zend\Stdlib\InitializableInterface; | ||
|
||
/** | ||
|
@@ -22,55 +22,89 @@ | |
class InputFilterPluginManager extends AbstractPluginManager | ||
{ | ||
/** | ||
* Default set of plugins | ||
* Default alias of plugins | ||
* | ||
* @var string[] | ||
*/ | ||
protected $invokableClasses = [ | ||
protected $aliases = [ | ||
'inputfilter' => InputFilter::class, | ||
'inputFilter' => InputFilter::class, | ||
'InputFilter' => InputFilter::class, | ||
'collection' => CollectionInputFilter::class, | ||
'Collection' => CollectionInputFilter::class, | ||
]; | ||
|
||
/** | ||
* Default set of plugins | ||
* | ||
* @var string[] | ||
*/ | ||
protected $factories = [ | ||
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. Please add a docblock or inheritdoc |
||
InputFilter::class => InvokableFactory::class, | ||
CollectionInputFilter::class => InvokableFactory::class, | ||
]; | ||
|
||
/** | ||
* Whether or not to share by default | ||
* | ||
* @var bool | ||
*/ | ||
protected $shareByDefault = false; | ||
protected $sharedByDefault = false; | ||
|
||
/** | ||
* @param ConfigInterface $configuration | ||
* @param ContainerInterface $parentLocator | ||
* @param array $config | ||
*/ | ||
public function __construct(ConfigInterface $configuration = null) | ||
public function __construct(ContainerInterface $parentLocator, array $config = []) | ||
{ | ||
parent::__construct($configuration); | ||
|
||
parent::__construct($parentLocator, $config); | ||
$this->addInitializer([$this, 'populateFactory']); | ||
} | ||
|
||
/** | ||
* Inject this and populate the factory with filter chain and validator chain | ||
* | ||
* @param $inputFilter | ||
* @param mixed $first | ||
* @param mixed $second | ||
*/ | ||
public function populateFactory($inputFilter) | ||
public function populateFactory($first, $second) | ||
{ | ||
if ($first instanceof ContainerInterface) { | ||
$container = $first; | ||
$inputFilter = $second; | ||
} else { | ||
$container = $second; | ||
$inputFilter = $first; | ||
} | ||
if ($inputFilter instanceof InputFilter) { | ||
$factory = $inputFilter->getFactory(); | ||
|
||
$factory->setInputFilterManager($this); | ||
} | ||
} | ||
|
||
if ($this->serviceLocator instanceof ServiceLocatorInterface) { | ||
$factory->getDefaultFilterChain()->setPluginManager($this->serviceLocator->get('FilterManager')); | ||
$factory->getDefaultValidatorChain()->setPluginManager($this->serviceLocator->get('ValidatorManager')); | ||
} | ||
public function populateFactoryPluginManagers(Factory $factory) | ||
{ | ||
if (property_exists($this, 'creationContext')) { | ||
// v3 | ||
$container = $this->creationContext; | ||
} else { | ||
// v2 | ||
$container = $this->serviceLocator; | ||
} | ||
|
||
if ($container && $container->has('FilterManager')) { | ||
$factory->getDefaultFilterChain()->setPluginManager($container->get('FilterManager')); | ||
} | ||
if ($container && $container->has('ValidatorManager')) { | ||
$factory->getDefaultValidatorChain()->setPluginManager($container->get('ValidatorManager')); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* {@inheritDoc} (v3) | ||
*/ | ||
public function validatePlugin($plugin) | ||
public function validate($plugin) | ||
{ | ||
if ($plugin instanceof InputFilterInterface || $plugin instanceof InputInterface) { | ||
// Hook to perform various initialization, when the inputFilter is not created through the factory | ||
|
@@ -89,4 +123,24 @@ public function validatePlugin($plugin) | |
InputInterface::class | ||
)); | ||
} | ||
|
||
/** | ||
* Validate the plugin (v2) | ||
* | ||
* Checks that the filter loaded is either a valid callback or an instance | ||
* of FilterInterface. | ||
* | ||
* @param mixed $plugin | ||
* @return void | ||
* @throws Exception\RuntimeException if invalid | ||
*/ | ||
public function validatePlugin($plugin) | ||
{ | ||
$this->validate($plugin); | ||
} | ||
|
||
public function shareByDefault() | ||
{ | ||
return $this->sharedByDefault; | ||
} | ||
} |
Oops, something went wrong.
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.
Please undo this. What feature exists only in 2.8?
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.
The SM updates for that component exist on the develop branch.
As you have not been involved on the other component migrations, I respectfully request that you refrain from further review of this PR; @ezimuel and I will complete this review, as we've been involved with all other component updates to date, and know the changes required intimately.
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 After SMv3 release composer should pick the most recent stdlib version automatically without any explicit requirement. This is important because if SM has a problem with the stdlib version then should be fixes on SM composer and don't in each component, application, ...