Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Add various plugin manager #4319

Merged
merged 10 commits into from
Apr 26, 2013

Conversation

bakura10
Copy link
Contributor

Hi,

This PR adds two plugin managers: one for hydrators and one for input filters. It also fixes a bug for the Serializer adapter (I introduced another way than adding all the listener in the ModuleManagerFactory but in fact my approach did not work at all, so until we find a cleanest way, I've just added another new listenenr in the ModuleManagerFactory).

Those plugin managers would be really useful for one module I'm working on, and this continue to make the framework more uniform with same logic.

I'd like this to be merged for 2.2 if that's possible =).

(PS: for ZF 3, we'd like to find a better solution, I think that adding so much listeners will lower performance, at some point...)

@danizord
Copy link
Contributor

👍

* @var array
*/
protected $invokableClasses = array(
'arrayserializable' => 'Zend\Stdlib\Hydrator\ArraySerializable',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bakura10 maybe use aliases instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ocramius Why? Other plugin managers use invokables as shortname/classname pairs...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Furthremore all plugin managers are configured to autoadd any invokables classes.

@weierophinney
Copy link
Member

@bakura10 It looks good. A few comments:

@bakura10
Copy link
Contributor Author

I'm thinking about that but do we really need those listeners and co ? Can't the factories simply read the config ? Like we do in modules.

(I'm going to make the changes)

* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Form
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove @package

@danizord
Copy link
Contributor

Why InputFilter doesn't implement InitializableInterface like Zend\Form\Element?

$factory = $element->getFactory();
$factory->getDefaultFilterChain()->setPluginManager($this->serviceLocator->get('FilterManager'));
$factory->getDefaultValidatorChain()->setPluginManager($this->serviceLocator->get('ValidatorManager'));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably check that $this->serviceLocator is indeed an instance before calling get() on it. You could do it in the initial conditional:

if ($element instanceof InputFilter && $this->serviceLocator instanceof ServiceLocatorInterface) {
    /* ... */
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it always the case ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's always a remote possibility that somebody will instantiate it themselves. :)

@bakura10
Copy link
Contributor Author

Done.

@danizord
Copy link
Contributor

What about the InputFilter\Factory use InputFilterManager to construct InputFilters? This will allow developers to easly add custom InputFilters.

@weierophinney
Copy link
Member

What about the InputFilter\Factory use InputFilterManager to construct InputFilters? This will allow developers to easly add custom InputFilters.

@danizord See https://github.com/zendframework/zf2/pull/4319/files#L2R38 -- this is already covered, as the default InputFilter class already composes a factory; those lines there will inject the validator and filter chains on creation. :)

* Plugin manager implementation for input filters.
*/
class InputFilterPluginManager extends AbstractPluginManager
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized this one should be marked sharedByDefault == false as well (as input filters are rarely if ever shared). I'll do that on merge.

@ghost ghost assigned weierophinney Apr 26, 2013
weierophinney added a commit that referenced this pull request Apr 26, 2013
weierophinney added a commit that referenced this pull request Apr 26, 2013
- Intention changed mid-PR, but tests were not updated; demonstrate that Factory
  composes a default filter chain and validator chain by default.
weierophinney added a commit that referenced this pull request Apr 26, 2013
@weierophinney weierophinney merged commit 0aaefd4 into zendframework:develop Apr 26, 2013
weierophinney added a commit to zendframework/zend-modulemanager that referenced this pull request May 15, 2015
…rator-plugin-manager

Add various plugin manager
weierophinney added a commit to zendframework/zend-modulemanager that referenced this pull request May 15, 2015
weierophinney added a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
…rator-plugin-manager

Add various plugin manager
weierophinney added a commit to zendframework/zend-stdlib that referenced this pull request May 15, 2015
weierophinney added a commit to zendframework/zend-inputfilter that referenced this pull request May 15, 2015
…rator-plugin-manager

Add various plugin manager
weierophinney added a commit to zendframework/zend-inputfilter that referenced this pull request May 15, 2015
- Intention changed mid-PR, but tests were not updated; demonstrate that Factory
  composes a default filter chain and validator chain by default.
weierophinney added a commit to zendframework/zend-inputfilter that referenced this pull request May 15, 2015
weierophinney added a commit to zendframework/zend-inputfilter that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants