ZF2-24: "static function factory" & PluginBroker

Issue Type: Bug Created: 2011-06-30T13:57:08.000+0000 Last Updated: 2012-06-06T22:43:47.000+0000 Status: Resolved Fix version(s): Reporter: Kazusuke Sasezaki (sasezaki) Assignee: Ralph Schindler (ralph) Tags: - Zend\Paginator

  • zf-crteam-padraic
  • zf-crteam-priority

Related issues: Attachments:


I found a issue about ZF2's plugin architecture.

At present, some components provides the static factory method, of course, these are upgraded ​​by upgrade of the loader, (From ZF1's pluingLoader to ZF2's PluginBroker)

For example, at Paginator.

<pre class="highlight">
$pluginLoader = self::getAdapterLoader();
$adapterClassName = $pluginLoader->load($adapter);
return new self(new $adapterClassName($data));

<pre class="highlight">
$broker = self::getAdapterBroker();
$adapter = $broker->load($adapter, array($data));
return new self($adapter);

Had making change above. However, in the case of this ZF2,


Loaded the adapter object at the point of above.

So, adapter name object which once loaded will use the first data with or without cause those data is different.

<pre class="highlight">
var_dump(count(Paginator\Paginator::factory(5)->getAdapter())); // 5
var_dump(count(Paginator\Paginator::factory(6)->getAdapter())); // 5

If you run Paginator's unittest-code, you can find where it fails actually.

Point to be a problem is,"static function factory()" would use an adapter object that is generated first.I think, the Object generated by "factory" method are considered to be absolutely new.


Posted by Kazusuke Sasezaki (sasezaki) on 2011-06-30T14:04:45.000+0000

If only to pass the existing tests,… applying modify such as. But, this will not good.

Posted by Matthew Weier O'Phinney (matthew) on 2011-06-30T15:03:16.000+0000

This has been marked as a todo item for some time. Ralph was able to find a workable solution within the DI component that I hope to adapt for the PluginBroker as well. If you would like to look at that solution (it's in the InstanceManager) and try and apply it, I'd be happy to review your work.

The main reason we haven't prioritized it is that it's actually relatively rare to need to pull the same class with different arguments from the same broker. However, clearly, it is a use case, so if we can address it, we should.

Posted by Benoît Durand (intiilapa) on 2011-09-03T08:16:37.000+0000

Add code tags.

Posted by Maks 3w (maks3w) on 2012-06-06T22:43:47.000+0000

Seems to be fixed. I tested the code and works fine.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.