[FrameworkBundle] Adding a option to debug services by tag
[FrameworkBundle] more verbose output about service tags in container:debug command and display all tag attributes as columns in normal container:debug output
merged branch SamsonIT/tag-support-in-container-debug (PR #4937)

This PR was merged into the master branch.

Commits
-------

34b60f7 [FrameworkBundle] more verbose output about service tags in container:debug command and display all tag attributes as columns in normal container:debug output
2a9805e [FrameworkBundle] Adding a option to debug services by tag

Discussion
----------

[2.2] [FrameworkBundle] Tag support in container debug

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: n/a
License of the code: MIT

This PR allows finding all services with a specified tag in the container:

```
> app/console container:debug --tag=form.type
[container] Public services
Service Id           Scope     Class Name
form.type.birthday   container Symfony\Component\Form\Extension\Core\Type\BirthdayType
form.type.checkbox   container Symfony\Component\Form\Extension\Core\Type\CheckboxType
form.type.choice     container Symfony\Component\Form\Extension\Core\Type\ChoiceType
form.type.collection container Symfony\Component\Form\Extension\Core\Type\CollectionType
form.type.country    container Symfony\Component\Form\Extension\Core\Type\CountryType
[ ... ]
```

Also, it adds more info on used tags when requesting info of a service:

Before:

```
> app/console container:debug data_collector.request
[container] Information for service data_collector.request

Service Id       data_collector.request
Class            Symfony\Bundle\FrameworkBundle\DataCollector\RequestDataCollector
Tags             kernel.event_listener, data_collector
Scope            container
Public           yes
Synthetic        no
Required File    -
```

After:
```
> app/console container:debug data_collector.request
[container] Information for service data_collector.request

Service Id       data_collector.request
Class            Symfony\Bundle\FrameworkBundle\DataCollector\RequestDataCollector
Tags
    - kernel.event_listener          (event: kernel.controller, method: onKernelController)
    - data_collector                 (template: WebProfilerBundle:Collector:request, id: request, priority: 255)
Scope            container
Public           yes
Synthetic        no
Required File    -
```

---------------------------------------------------------------------------

by Burgov at 2012-07-15T21:00:46Z

thanks @stof :)

---------------------------------------------------------------------------

by stof at 2012-10-13T17:50:23Z

@Burgov @richardmiller any news on this PR ? Is there any feature to port from #5522 or is it ready to be merged as is ?

---------------------------------------------------------------------------

by Burgov at 2012-10-14T11:17:51Z

@stof, I've merged richardmiller's branch and rebased it so that everything is now in one command (the original container:debug), so technically, this is now ready to be merged. Still there's two things that might be discussed:

1) when using --tags, all other options and arguments are ignored. Perhaps an exception should be thrown when other parameters are passed?

2) I'm not completely satisfied with the way the output of the command with the --tag argument looks, perhaps someone can share his ideas about it?

---------------------------------------------------------------------------

by Burgov at 2012-10-15T07:19:29Z

@richardmiller any suggestions? I've tried to stay as close as possible to the normal output of this command, when using the --tag option, so using the output format you used couldn't really be done...

---------------------------------------------------------------------------

by fabpot at 2012-10-16T06:50:12Z

For the `--tag` output, and because the number of attributes is most of the time very limited, I would just add one new column per attribute:

```
~/ $ ./app/console container:debug --tag=form.type
[container] Public services with tag form.type
Service Id           Alias     Scope     Class Name
form.type.birthday   birthday  container Symfony\Component\Form\Extension\Core\Type\BirthdayType
form.type.checkbox   checkbox  container Symfony\Component\Form\Extension\Core\Type\CheckboxType
form.type.choice     choice    container Symfony\Component\Form\Extension\Core\Type\ChoiceType
```

---------------------------------------------------------------------------

by fabpot at 2012-10-16T06:51:04Z

When using ``--tags``, an exception should indeed be thrown if other incompatible options are passed.

---------------------------------------------------------------------------

by fabpot at 2012-10-16T06:51:20Z

The last missing piece is a PR on the documentation. Thanks.

---------------------------------------------------------------------------

by Burgov at 2012-10-16T08:17:25Z

@fabpot I've added the tag attributes as columns to the normal output. Since services can have more of the same tag, I had to create an extra loop to represent this. For example, when debugging the kernel.event_listener tag, this is now the output:

```
> app/console container:debug --tag=kernel.event_listener
[container] Public services with tag kernel.event_listener
Service Id                                 event             method             priority Scope     Class Name
acme.demo.listener                         kernel.controller onKernelController          container Acme\DemoBundle\EventListener\ControllerListener
assetic.request_listener                   kernel.request    onKernelRequest             container Symfony\Bundle\AsseticBundle\EventListener\RequestListener
data_collector.router                      kernel.controller onKernelController          container Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector
monolog.handler.firephp                    kernel.response   onKernelResponse            container Symfony\Bridge\Monolog\Handler\FirePHPHandler
security.firewall                          kernel.request    onKernelRequest    8        container Symfony\Component\Security\Http\Firewall
security.rememberme.response_listener      kernel.response   onKernelResponse            container Symfony\Component\Security\Http\RememberMe\ResponseListener
sensio_framework_extra.cache.listener      kernel.response   onKernelResponse            container Sensio\Bundle\FrameworkExtraBundle\EventListener\CacheListener
sensio_framework_extra.controller.listener kernel.controller onKernelController          container Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener
sensio_framework_extra.converter.listener  kernel.controller onKernelController          container Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener
sensio_framework_extra.view.listener       kernel.controller onKernelController          container Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener
  "                                        kernel.view       onKernelView
```

At this moment the " denotes that the same service as the line above is referenced.

---------------------------------------------------------------------------

by fabpot at 2012-10-16T08:37:38Z

@Burgov Looks good to me. Ping me when this is ready to be merged.

---------------------------------------------------------------------------

by Burgov at 2012-10-16T09:09:46Z

ping @fabpot I've rebased and I think it should be ready to go