Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LazyControllerAbstractFactory doesn't look in FormManager #17

Open
weierophinney opened this issue Dec 31, 2019 · 1 comment
Open

LazyControllerAbstractFactory doesn't look in FormManager #17

weierophinney opened this issue Dec 31, 2019 · 1 comment

Comments

@weierophinney
Copy link
Member

The extremely convenient LazyControllerAbstractFactory only checks ServiceManager when making objects for the controller's constructor.

This means that I have to move any forms without a factory from the 'form_elements' config array to 'service_manager'... and odd delineation.


Originally posted by @bitwombat at zendframework/zend-mvc#255

@froschdesign
Copy link
Member

The form element manager is registered with the class name Laminas\Form\FormElementManager in laminas-form and this can be used via the registered module in a laminas-mvc based application.

Example

class ExampleController extends Laminas\Mvc\Controller\AbstractActionController
{
    public function __construct(
        FilterPluginManager $filterPluginManager,
        FormElementManager $formElementManager,
        HydratorPluginManager $hydratorPluginManager,
        InputFilterPluginManager $inputFilterPluginManager,
        ValidatorPluginManager $validatorPluginManager
    ) {
        $this->filterPluginManager      = $filterPluginManager;
        $this->formElementManager       = $formElementManager;
        $this->hydratorPluginManager    = $hydratorPluginManager;
        $this->inputFilterPluginManager = $inputFilterPluginManager;
        $this->validatorPluginManager   = $validatorPluginManager;
    }
}
'controllers' => [
    'factories' => [
        ExampleController::class  => Laminas\Mvc\Controller\LazyControllerAbstractFactory::class,
    ],
],

Reflection Factory of laminas-servicemanager

If the following features are not needed in a controller constructor:

  • A parameter named $config typehinted as an array will receive the
    application "config" service (i.e., the merged configuration).
  • Parameters typehinted against array, but not named $config, will
    be injected with an empty array.
  • Scalar parameters will be resolved as null values.

…then the laminas-servicemanager's reflection factory can be used:

'controllers'     => [
    'factories' => [
        ExampleController::class  => Laminas\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory::class,
    ],
],

Conclusion

All aliases can be removed from the lazy controller factory:

protected $aliases = [
ConsoleAdapterInterface::class => 'ConsoleAdapter',
FilterPluginManager::class => 'FilterManager',
HydratorPluginManager::class => 'HydratorManager',
InputFilterPluginManager::class => 'InputFilterManager',
LogFilterManager::class => 'LogFilterManager',
LogFormatterManager::class => 'LogFormatterManager',
LogProcessorManager::class => 'LogProcessorManager',
LogWriterManager::class => 'LogWriterManager',
SerializerAdapterManager::class => 'SerializerAdapterManager',
ValidatorPluginManager::class => 'ValidatorManager',
];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants