ZF2-24: "static function factory" & PluginBroker


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.

$pluginLoader = self::getAdapterLoader();
$adapterClassName = $pluginLoader->load($adapter);
return new self(new $adapterClassName($data));

$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.

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.


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

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.

Add code tags.

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