Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laminas Mvc Laravel Package

laminas/laminas-mvc

Laminas MVC is a modular, event-driven MVC framework for PHP applications. It provides routing, controllers, view integration, dependency injection, and configuration management, helping you build scalable, maintainable web apps and APIs on top of Laminas components.

View on GitHub
Deep Wiki
Context7

Automating Controller Factories

Writing a factory class for each and every controller that has dependencies can be tedious, particularly in early development as you are still sorting out dependencies.

As of version 3.0.1, laminas-mvc ships with Laminas\Mvc\Controller\LazyControllerAbstractFactory, which provides a reflection-based approach to controller instantiation, resolving constructor dependencies to the relevant services. The factory may be used as either an abstract factory, or mapped to specific controller names as a factory:

use Laminas\Mvc\Controller\LazyControllerAbstractFactory;

return [
    /* ... */
    'controllers' => [
        'abstract_factories' => [
            LazyControllerAbstractFactory::class,
        ],
        'factories' => [
            'MyModule\Controller\FooController' => LazyControllerAbstractFactory::class,
        ],
    ],
    /* ... */
];

Mapping controllers to the factory is more explicit and performant.

The factory operates with the following constraints/features:

  • 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.
  • If a service cannot be found for a given typehint, the factory will raise an exception detailing this.
  • Some services provided by Laminas components do not have entries based on their class name (for historical reasons); the factory contains a map of these class/interface names to the corresponding service name to allow them to resolve. These include:
    • Laminas\Console\Adapter\AdapterInterface maps to ConsoleAdapter,
    • Laminas\Filter\FilterPluginManager maps to FilterManager,
    • Laminas\Hydrator\HydratorPluginManager maps to HydratorManager,
    • Laminas\InputFilter\InputFilterPluginManager maps to InputFilterManager,
    • Laminas\Log\FilterPluginManager maps to LogFilterManager,
    • Laminas\Log\FormatterPluginManager maps to LogFormatterManager,
    • Laminas\Log\ProcessorPluginManager maps to LogProcessorManager,
    • Laminas\Log\WriterPluginManager maps to LogWriterManager,
    • Laminas\Serializer\AdapterPluginManager maps to SerializerAdapterManager,
    • Laminas\Validator\ValidatorPluginManager maps to ValidatorManager,

$options passed to the factory are ignored in all cases, as we cannot make assumptions about which argument(s) they might replace.

Once your dependencies have stabilized, we recommend writing a dedicated factory, as reflection can introduce performance overhead.

References

This feature was inspired by a blog post by Alexandre Lemaire.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation