Skip to content
Prev Previous commit
Next Next commit
More changes
  • Loading branch information
weaverryan committed May 14, 2017
commit f7f9178d6a0610c4a45774caf295b2428ceee322
2 changes: 1 addition & 1 deletion controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ controller's service config:
AppBundle\Controller\LuckyController:
public: true
tags:
# add multiple tags to controller multiple args
# add multiple tags to control multiple args
- name: controller.service_arguments
action: numberAction
argument: logger
Expand Down
104 changes: 17 additions & 87 deletions profiler/data_collector.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,49 +82,14 @@ The getters are added to give the template access to the collected information.
Enabling Custom Data Collectors
-------------------------------

To enable a data collector, define it as a regular service and tag it as
``data_collector``:
If you're using the :ref:`default services.yml configuration <service-container-services-load-example>`
with ``autoconfigure``, then Symfony will automatically see your new data collector!
Your ``collect()`` method should be called next time your refresh.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you


.. configuration-block::

.. code-block:: yaml

# app/config/services.yml
services:
app.request_collector:
class: AppBundle\DataCollector\RequestCollector
public: false
tags: [data_collector]
.. note::

.. code-block:: xml

<!-- app/config/services.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd"
>
<services>
<service id="app.request_collector"
class="AppBundle\DataCollector\RequestCollector"
public="false"
>
<tag name="data_collector" />
</service>
</services>
</container>

.. code-block:: php

// app/config/services.php
use AppBundle\DataCollector\RequestCollector;

$container
->register('app.request_collector', RequestCollector::class)
->setPublic(false)
->addTag('data_collector')
;
If you're not using ``autoconfigure``, you can also :ref:`manually wire your service <services-explicitly-configure-wire-services>`
and :doc:`tag </service_container/tags` it with ``data_collector``.

Adding Web Profiler Templates
-----------------------------
Expand Down Expand Up @@ -242,22 +207,24 @@ The ``menu`` and ``panel`` blocks are the only required blocks to define the
contents displayed in the web profiler panel associated with this data collector.
All blocks have access to the ``collector`` object.

Finally, to enable the data collector template, add a ``template`` attribute to
the ``data_collector`` tag in your service configuration:
Finally, to enable the data collector template, override your service configuration
to specify a tag that contains the template:

.. configuration-block::

.. code-block:: yaml

# app/config/services.yml
services:
app.request_collector:
class: AppBundle\DataCollector\RequestCollector
AppBundle\DataCollector\RequestCollector:
tags:
-
name: data_collector
template: 'data_collector/template.html.twig'
# must match the value returned by the getName() method
id: 'app.request_collector'
# optional priority
# priority: 300
public: false

.. code-block:: xml
Expand All @@ -270,13 +237,11 @@ the ``data_collector`` tag in your service configuration:
http://symfony.com/schema/dic/services/services-1.0.xsd"
>
<services>
<service id="app.request_collector"
class="AppBundle\DataCollector\RequestCollector"
public="false"
>
<service id="AppBundle\DataCollector\RequestCollector" public="false">
<tag name="data_collector"
template="data_collector/template.html.twig"
id="app.request_collector"
<!-- priority="300" -->
/>
</service>
</services>
Expand All @@ -288,50 +253,15 @@ the ``data_collector`` tag in your service configuration:
use AppBundle\DataCollector\RequestCollector;

$container
->register('app.request_collector', RequestCollector::class)
->autowire(RequestCollector::class)
->setPublic(false)
->addTag('data_collector', array(
'template' => 'data_collector/template.html.twig',
'id' => 'app.request_collector',
// 'priority' => 300,
))
;

.. caution::

The ``id`` attribute must match the value returned by the ``getName()`` method.

The position of each panel in the toolbar is determined by the priority defined
by each collector. Most built-in collectors use ``255`` as their priority. If you
want your collector to be displayed before them, use a higher value:

.. configuration-block::

.. code-block:: yaml

# app/config/services.yml
services:
app.request_collector:
class: AppBundle\DataCollector\RequestCollector
tags:
- { name: data_collector, template: '...', id: '...', priority: 300 }

.. code-block:: xml

<!-- app/config/services.xml -->
<service id="app.request_collector" class="AppBundle\DataCollector\RequestCollector">
<tag name="data_collector" template="..." id="..." priority="300" />
</service>

.. code-block:: php

// app/config/services.php
use AppBundle\DataCollector\RequestCollector;

$container
->register('app.request_collector', RequestCollector::class)
->addTag('data_collector', array(
'template' => '...',
'id' => '...',
'priority' => 300,
))
;
want your collector to be displayed before them, use a higher value (like 300).
44 changes: 8 additions & 36 deletions profiler/matchers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,39 +106,9 @@ matcher::
}
}

Then, configure a new service and set it as ``private`` because the application
won't use it directly:

.. configuration-block::

.. code-block:: yaml

# app/config/services.yml
services:
app.super_admin_matcher:
class: AppBundle\Profiler\SuperAdminMatcher
arguments: ['@security.authorization_checker']
public: false

.. code-block:: xml

<!-- app/config/services.xml -->
<services>
<service id="app.profiler.matcher.super_admin"
class="AppBundle\Profiler\SuperAdminMatcher" public="false">
<argument type="service" id="security.authorization_checker" />
</service>
</services>

.. code-block:: php

// app/config/services.php
use AppBundle\Profiler\SuperAdminMatcher;
use Symfony\Component\DependencyInjection\Reference;

$container->register('app.super_admin_matcher', SuperAdminMatcher::class)
->addArgument(new Reference('security.authorization_checker'))
->setPublic(false);
Then, you'll need to make sure your class is defined as as service. If you're using
the :ref:`default services.yml configuration <service-container-services-load-example>`,
you don't need to do anything!

Once the service is registered, the only thing left to do is configure the
profiler to use this service as the matcher:
Expand All @@ -152,7 +122,7 @@ profiler to use this service as the matcher:
# ...
profiler:
matcher:
service: app.super_admin_matcher
service: AppBundle\Profiler\SuperAdminMatcher

.. code-block:: xml

Expand All @@ -170,19 +140,21 @@ profiler to use this service as the matcher:
<framework:config>
<!-- ... -->
<framework:profiler>
<framework:matcher service="app.super_admin_matcher" />
<framework:matcher service="AppBundle\Profiler\SuperAdminMatcher" />
</framework:profiler>
</framework:config>
</container>

.. code-block:: php

// app/config/config.php
use AppBundle\Profiler\SuperAdminMatcher;

$container->loadFromExtension('framework', array(
// ...
'profiler' => array(
'matcher' => array(
'service' => 'app.super_admin_matcher',
'service' => SuperAdminMatcher::class,
)
),
));
4 changes: 3 additions & 1 deletion service_container.rst
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,9 @@ key. For example, the default Symfony configuration contains this:
This can be used to quickly make many classes available as services and apply some
default configuration. The ``id`` of each service is its fully-qualified class name.
You can override any service that's imported by using its id (class name) below
(e.g. see :ref:`services-manually-wire-args`).
(e.g. see :ref:`services-manually-wire-args`). If you override a service, none of
the options (e.g. ``public``) are inherited from the import (but the overridden
service *does* still inherit from ``_defaults``).

.. note::

Expand Down