This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/HttpKernel
Fabien Potencier 0a5998d996 feature #21771 [FrameworkBundle] Add new "controller.service_arguments" tag to inject services into actions (nicolas-grekas)
This PR was merged into the 3.3-dev branch.

Discussion
----------

[FrameworkBundle] Add new "controller.service_arguments" tag to inject services into actions

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | (no test yet)
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Talking with @simensen and @weaverryan, we wondered if we could leverage the `ArgumentResolver` mechanism to make it inject services on demand, using e.g. autowiring.

```php
class PostController
{
  public function indexAction(Request $request, PostRepository $postRepository)
  {
    // PostRepository comes from the container
    $postRepository->findAll(); // ...
  }
}
```

This PR achieves that, using a new "controller.service_arguments" tag. Typically:
```yaml
services:
    AppBundle\Controller\PostController:
        autowire: true
        tags:
            - name: controller.service_arguments
```

It also supports with explicit wiring (thus doesn't necessarily require autowiring if you don't want to use it):
```yaml
services:
    AppBundle\Controller\PostController:
        tags:
            - name: controller.service_arguments
              action: fooAction
              argument: logger
              id: my_logger
```

~~The attached diff is bigger than strictly required for now, until #21770 is merged.~~

Todo:
- [x] rebase on top of #21770 when merged
- [x] add tests
- [x] add cleaning pass to remove empty service locators

Commits
-------

9c6e672780 [FrameworkBundle] Add new "controller.service_arguments" tag to inject services into actions
2017-03-22 15:24:31 -07:00
..
Bundle [HttpKernel] Fix Bundle name regression 2017-01-27 07:30:57 -08:00
CacheClearer [FrameworkBundle] Allow clearing private cache pools 2016-12-10 11:52:34 +01:00
CacheWarmer Fix PHP 7.1 related failures 2016-07-19 10:44:18 +02:00
Config Conditionally add options to unserialize in PHP 7.0+. 2016-12-29 19:41:55 +01:00
Controller [FrameworkBundle] Add new "controller.service_arguments" tag to inject services into actions 2017-03-22 21:34:42 +01:00
ControllerMetadata [HttpKernel] Clean ArgumentMetadataFactory::getType() 2016-10-06 11:12:13 +02:00
DataCollector [WebProfilerBundle] Improved cookie traffic 2017-03-22 21:55:42 +01:00
Debug Conditionally add options to unserialize in PHP 7.0+. 2016-12-29 19:41:55 +01:00
DependencyInjection [FrameworkBundle] Add new "controller.service_arguments" tag to inject services into actions 2017-03-22 21:34:42 +01:00
Event [HttpKernel] Deprecate X-Status-Code for better alternative 2017-02-23 21:30:09 +00:00
EventListener implement ServiceSubscriberInterface where applicable 2017-03-22 20:26:10 +01:00
Exception fixed CS 2016-06-29 07:42:25 +02:00
Fragment [HttpFoundation] Add $trustedHeaderSet arg to Request::setTrustedProxies() - deprecate not setting it 2017-03-22 21:29:40 +01:00
HttpCache [HttpFoundation] Add $trustedHeaderSet arg to Request::setTrustedProxies() - deprecate not setting it 2017-03-22 21:29:40 +01:00
Log Merge branch '2.3' into 2.7 2015-09-29 14:06:14 +02:00
Profiler Merge branch '2.7' into 2.8 2017-02-16 14:43:37 -08:00
Tests feature #21771 [FrameworkBundle] Add new "controller.service_arguments" tag to inject services into actions (nicolas-grekas) 2017-03-22 15:24:31 -07:00
.gitignore Fix gitignore 2014-03-04 18:06:29 +01:00
CHANGELOG.md implement ServiceSubscriberInterface where applicable 2017-03-22 20:26:10 +01:00
Client.php Merge branch '3.2' 2017-02-16 14:50:29 -08:00
composer.json [VarDumper] Allow seamless use of Data clones 2017-02-27 21:09:01 +01:00
HttpKernel.php [HttpKernel] Deprecate X-Status-Code for better alternative 2017-02-23 21:30:09 +00:00
HttpKernelInterface.php remove api tags from code 2015-09-28 19:11:22 +02:00
Kernel.php Deprecate the special SYMFONY__ environment variables 2017-03-21 08:27:06 -07:00
KernelEvents.php Fix event annotation for arguments resolving event 2016-10-04 15:51:31 -07:00
KernelInterface.php Merge branch '2.8' into 3.0 2016-06-29 07:40:00 +02:00
LICENSE updated LICENSE year 2017-01-02 12:30:00 -08:00
phpunit.xml.dist [Validator] Test DNS Email constraints using checkdnsrr() mock 2016-03-16 16:47:01 +01:00
README.md Updated all the README files 2016-03-04 08:12:06 +01:00
TerminableInterface.php remove api tags from code 2015-09-28 19:11:22 +02:00
UriSigner.php Allow a custom query string parameter 2017-03-05 11:22:32 +00:00

HttpKernel Component

The HttpKernel component provides a structured process for converting a Request into a Response by making use of the EventDispatcher component. It's flexible enough to create a full-stack framework (Symfony), a micro-framework (Silex) or an advanced CMS system (Drupal).

Resources