/ControllerAutowire

Use controller's constructor to get dependencies with ease

Primary LanguagePHPMIT LicenseMIT

Controller Autowire

Build Status Quality Score Code Coverage Downloads Latest stable

This bundle does only 2 things. But does them well:

  • 1. registers controllers as services and
  • 2. enables contstructor autowiring for them

Still wondering why use controller as services? Check this and this article.

Note: If you look for controller method autowiring, see ActionAutowire bundle.

Install

composer require symplify/controller-autowire

Add bundle to AppKernel.php:

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            new Symplify\ControllerAutowire\SymplifyControllerAutowireBundle(),
            // ...
        ];
    }
}

Usage

class SomeController
{
    private $someClass;

    public function __construct(SomeClass $someClass)
    {
        $this->someClass = $someClass;
    }
}

That's all :)

Testing

vendor/bin/symplify-cs check src tests
vendor/bin/phpunit

Contributing

Rules are simple:

  • new feature needs tests
  • all tests must pass
  • 1 feature per PR

I'd be happy to merge your feature then.