Intuitive use of MutableCreationOptionsInterface #7
Description
This implementation works in an unintuitive way. For example, if I wire a Form Factory like so:
'form_elements' => [
'factories' => [
ServerForm::class => ServerFormFactory::class,
],
],
Then the expected is true, I can call this on the SL and the options are properly captured in the Factory through MutableCreationOptionsInterface (thanks for the new trait btw, very handy).
$server_form = $this->getServiceLocator()->get( 'FormElementManager' )->get( ServerForm::class, [ 'test' => 123 ] );
With the code above, the factory's creation options are indeed [ 'test' => 123 ].
The problem with intuitive use arises in normal factories, the same rule isn't true (I can pass options to a factory through MCOI as a second Array argument). This wiring produces an unexpected result:
'service_manager' => [
'factories' => [
CartService::class => CartServiceFactory::class,
],
],
class CartServiceFactory implements FactoryInterface, MutableCreationOptionsInterface {
use MutableCreationOptionsTrait;
public function createService( ServiceLocatorInterface $serviceLocator )
{
var_dump( $this->creationOptions );
In the latter case, when I call this in a controller:
$sm = $this->getServiceLocator();
$cs = $sm->get( CartService::class, [ 'test' => 123 ]);
The dump in createService outputs 'null', which goes against what one would expect. It'd sure be convenient if they all worked under a same covenant.
I realize that the second argument to get on the main SM is $usePeeringServiceManagers, but since its use is implicit, it's probably an easier refactor to offer a stable rule in the boilerplate code, favoring the application developer.
I hope this gets considered, it'd be nice to pass array options to Factories... Give factories a chance to respond to controller conditions for example.