https://github.com/deprecated-packages/controllerautowire
[DEPRECATED] Use Controller autowiring by default since Symfony 3.3
https://github.com/deprecated-packages/controllerautowire
autowiring controller dependency-injection php php71 symfony symplify
Last synced: 10 months ago
JSON representation
[DEPRECATED] Use Controller autowiring by default since Symfony 3.3
- Host: GitHub
- URL: https://github.com/deprecated-packages/controllerautowire
- Owner: deprecated-packages
- License: mit
- Created: 2015-11-30T13:27:13.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2022-01-17T10:33:10.000Z (about 4 years ago)
- Last Synced: 2025-04-09T20:04:37.676Z (10 months ago)
- Topics: autowiring, controller, dependency-injection, php, php71, symfony, symplify
- Language: PHP
- Homepage: https://github.com/Symplify/Symplify/pull/155
- Size: 181 KB
- Stars: 24
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Controller Autowire - Deprecated, in core of Symfony 3.3+
- https://github.com/symfony/symfony/pull/22157
- https://github.com/symfony/symfony/pull/21289
---
[](https://travis-ci.org/Symplify/ControllerAutowire)
[](https://scrutinizer-ci.com/g/Symplify/ControllerAutowire)
[](https://packagist.org/packages/symplify/controller-autowire)
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](http://richardmiller.co.uk/2011/04/15/symfony2-controller-as-service) and
[this](http://php-and-symfony.matthiasnoback.nl/2014/06/how-to-create-framework-independent-controllers/) article.
## Install
```bash
composer require symplify/controller-autowire
```
Add bundle to `AppKernel.php`:
```php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
new Symplify\ControllerAutowire\SymplifyControllerAutowireBundle(),
// ...
];
}
}
```
## Usage
```php
class SomeController
{
private $someClass;
public function __construct(SomeClass $someClass)
{
$this->someClass = $someClass;
}
}
```
## Used to FrameworkBundle's controller? Use helpers traits!
Inspired by [pull](https://github.com/symfony/symfony/pull/18193) [requests](https://github.com/symfony/symfony/pull/20493) to Symfony and setter injection that are currently on-hold, **here are the traits you can use right now**:
```php
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?
```php
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](https://github.com/Symplify/Symplify/issues) or [pull-request](https://github.com/Symplify/Symplify/pulls) to main repository.