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

fix delegators to allow usage in plugin managers #5175

Closed

Conversation

stefanotorresi
Copy link
Contributor

see #5172

  • move delegator logic from create() to separate method
  • remove automatic invokable service for delegator factories
  • add delegator factory class validation
  • add callback support for delegator factories
  • tests

* @return mixed
* @throws Exception\ServiceNotCreatedException
*/
protected function createDelegatorFromFactory($canonicalName, $requestedName)
Copy link
Member

Choose a reason for hiding this comment

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

While this is indeed clean, consider that I inlined the code for performance reasons

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmmm but it's 40 lines of code now, plus there are separated methods for each service type. this way it's not only cleaner, it's more consistent too.

are you sure the performance gain is worth it? maybe there is even another way to improve that aspect?

Copy link
Member

Choose a reason for hiding this comment

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

Hrm... it's probably ok to keep the method separate then, yep.

@Ocramius
Copy link
Member

on add callback support for DelegatorFactories - are you sure you want callback support there?

Should be trivial though:

  1. change the check on

    if (!$delegatorFactory instanceof DelegatorFactoryInterface) {

    to

    if (!$delegatorFactory instanceof DelegatorFactoryInterface && !is_callable($delegatorFactory)) {
  2. change

    return $delegatorFactory->createDelegatorWithName($serviceManager, $cName, $rName, $creationCallback);

    to

    return $delegatorFactory instanceof DelegatorFactoryInterface 
        ? $delegatorFactory->createDelegatorWithName($serviceManager, $cName, $rName, $creationCallback)
        : $delegatorFactory($serviceManager, $cName, $rName, $creationCallback);

@stefanotorresi
Copy link
Contributor Author

yep, why not, this way we can keep delegator usage in line with the other service types :)

@ghost ghost assigned weierophinney Oct 23, 2013
weierophinney added a commit that referenced this pull request Oct 23, 2013
fix delegators to allow usage in plugin managers

Conflicts:
	tests/ZendTest/ServiceManager/ServiceManagerTest.php
weierophinney added a commit that referenced this pull request Oct 23, 2013
weierophinney added a commit to zendframework/zend-servicemanager that referenced this pull request May 15, 2015
…si/fix/pm-delegators

fix delegators to allow usage in plugin managers

Conflicts:
	tests/ZendTest/ServiceManager/ServiceManagerTest.php
weierophinney added a commit to zendframework/zend-servicemanager that referenced this pull request May 15, 2015
weierophinney added a commit to zendframework/zend-servicemanager 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants