Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Intuitive use of MutableCreationOptionsInterface #7

Closed
@Saeven

Description

@Saeven

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions