symplify/controller-autowire

This package is abandoned and no longer maintained. The author suggests using the symfony/dependency-injection package instead.
There is no license information available for the latest version (v2.0.0-RC2) of this package.

Adds support to autowire controller constructor without pain.

Maintainers

👁 TomasVotruba

Package info

github.com/deprecated-packages/ControllerAutowire

pkg:composer/symplify/controller-autowire

Statistics

Installs: 21 002

Dependents: 0

Suggesters: 0

Stars: 24

v2.0.0-RC2 2017-04-27 14:57 UTC

Suggests

None

Provides

None

Conflicts

None

Replaces

None

Unknown License 1ba0eab1df2459961c47b0066a0b62292ec9a5c9


README

👁 Build Status
👁 Code Coverage
👁 Downloads

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

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

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

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;
 }
}

Used to FrameworkBundle's controller? Use helpers traits!

Inspired by pull requests to Symfony and setter injection that are currently on-hold, here are the traits you can use right now:

use Symplify\ControllerAutowire\Controller\Routing\ControllerAwareTrait;

final class SomeController
{
 use ControllerAwareTrait;

 public function someAction()
 {
 $productRepository = $this->getDoctrine()->getRepository(Product::class);
 // ...

 return $this->redirectToRoute('my_route');
 }
}

Do you prefer only traits you use?

use Symplify\ControllerAutowire\Controller\Routing\ControllerRoutingTrait;

final class SomeController
{
 use ControllerRoutingTrait;

 public function someAction()
 {
 return $this->redirectToRoute('my_route');
 }
}

Just type Controller*Trait in your IDE to autocomplete any of these traits.

That's all :)

Contributing

Send issue or pull-request to main repository.