ControllerAutowire
[DEPRECATED] Use Controller autowiring by default since Symfony 3.3
Install / Use
/learn @deprecated-packages/ControllerAutowireREADME
Controller Autowire - Deprecated, in core of Symfony 3.3+
- https://github.com/symfony/symfony/pull/22157
- https://github.com/symfony/symfony/pull/21289
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.
Related Skills
node-connect
351.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
351.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
351.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
