Skip to content

Commit f709035

Browse files
committed
Restored the Assetic tags because they are removed in another PR
1 parent 206bf70 commit f709035

File tree

1 file changed

+183
-0
lines changed

1 file changed

+183
-0
lines changed

reference/dic_tags.rst

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ may also be tags in other bundles you use that aren't listed here.
1515
======================================== ========================================================================
1616
Tag Name Usage
1717
======================================== ========================================================================
18+
`assetic.asset`_ Register an asset to the current asset manager
19+
`assetic.factory_worker`_ Add a factory worker
20+
`assetic.filter`_ Register a filter
21+
`assetic.formula_loader`_ Add a formula loader to the current asset manager
22+
`assetic.formula_resource`_ Adds a resource to the current asset manager
23+
`assetic.templating.php`_ Remove this service if PHP templating is disabled
24+
`assetic.templating.twig`_ Remove this service if Twig templating is disabled
1825
`auto_alias`_ Define aliases based on the value of container parameters
1926
`console.command`_ Add a command
2027
`controller.argument_value_resolver`_ Register a value resolver for controller arguments such as ``Request``
@@ -49,6 +56,182 @@ Tag Name Usage
4956
`validator.initializer`_ Register a service that initializes objects before validation
5057
======================================== ========================================================================
5158

59+
assetic.asset
60+
-------------
61+
62+
**Purpose**: Register an asset with the current asset manager
63+
64+
assetic.factory_worker
65+
----------------------
66+
67+
**Purpose**: Add a factory worker
68+
69+
A Factory worker is a class implementing ``Assetic\Factory\Worker\WorkerInterface``.
70+
Its ``process($asset)`` method is called for each asset after asset creation.
71+
You can modify an asset or even return a new one.
72+
73+
In order to add a new worker, first create a class::
74+
75+
use Assetic\Asset\AssetInterface;
76+
use Assetic\Factory\Worker\WorkerInterface;
77+
78+
class MyWorker implements WorkerInterface
79+
{
80+
public function process(AssetInterface $asset)
81+
{
82+
// ... change $asset or return a new one
83+
}
84+
85+
}
86+
87+
And then register it as a tagged service:
88+
89+
.. configuration-block::
90+
91+
.. code-block:: yaml
92+
93+
services:
94+
App\Assetic\CustomWorker:
95+
tags: [assetic.factory_worker]
96+
97+
.. code-block:: xml
98+
99+
<?xml version="1.0" encoding="UTF-8" ?>
100+
<container xmlns="http://symfony.com/schema/dic/services"
101+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
102+
xsi:schemaLocation="http://symfony.com/schema/dic/services
103+
http://symfony.com/schema/dic/services/services-1.0.xsd">
104+
105+
<services>
106+
<service id="App\Assetic\CustomWorker">
107+
<tag name="assetic.factory_worker" />
108+
</service>
109+
</services>
110+
</container>
111+
112+
.. code-block:: php
113+
114+
use App\Assetic\CustomWorker;
115+
116+
$container
117+
->register(CustomWorker::class)
118+
->addTag('assetic.factory_worker')
119+
;
120+
121+
assetic.filter
122+
--------------
123+
124+
**Purpose**: Register a filter
125+
126+
AsseticBundle uses this tag to register common filters. You can also use
127+
this tag to register your own filters.
128+
129+
First, you need to create a filter::
130+
131+
use Assetic\Asset\AssetInterface;
132+
use Assetic\Filter\FilterInterface;
133+
134+
class MyFilter implements FilterInterface
135+
{
136+
public function filterLoad(AssetInterface $asset)
137+
{
138+
$asset->setContent('alert("yo");' . $asset->getContent());
139+
}
140+
141+
public function filterDump(AssetInterface $asset)
142+
{
143+
// ...
144+
}
145+
}
146+
147+
Second, define a service:
148+
149+
.. configuration-block::
150+
151+
.. code-block:: yaml
152+
153+
services:
154+
App\Assetic\CustomFilter:
155+
tags:
156+
- { name: assetic.filter, alias: my_filter }
157+
158+
.. code-block:: xml
159+
160+
<?xml version="1.0" encoding="UTF-8" ?>
161+
<container xmlns="http://symfony.com/schema/dic/services"
162+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
163+
xsi:schemaLocation="http://symfony.com/schema/dic/services
164+
http://symfony.com/schema/dic/services/services-1.0.xsd">
165+
166+
<services>
167+
<service id="App\Assetic\CustomFilter">
168+
<tag name="assetic.filter" alias="my_filter" />
169+
</service>
170+
</services>
171+
</container>
172+
173+
.. code-block:: php
174+
175+
use App\Assetic\CustomFilter;
176+
177+
$container
178+
->register(CustomFilter::class)
179+
->addTag('assetic.filter', array('alias' => 'my_filter'))
180+
;
181+
182+
Finally, apply the filter:
183+
184+
.. code-block:: twig
185+
186+
{% javascripts
187+
'@AcmeBaseBundle/Resources/public/js/global.js'
188+
filter='my_filter'
189+
%}
190+
<script src="{{ asset_url }}"></script>
191+
{% endjavascripts %}
192+
193+
You can also apply your filter via the ``assetic.filters.my_filter.apply_to``
194+
config option as it's described here: :doc:`/frontend/assetic/apply_to_option`.
195+
In order to do that, you must define your filter service in a separate xml
196+
config file and point to this file's path via the ``assetic.filters.my_filter.resource``
197+
configuration key.
198+
199+
assetic.formula_loader
200+
----------------------
201+
202+
**Purpose**: Add a formula loader to the current asset manager
203+
204+
A Formula loader is a class implementing
205+
``Assetic\\Factory\Loader\\FormulaLoaderInterface`` interface. This class
206+
is responsible for loading assets from a particular kind of resources (for
207+
instance, twig template). Assetic ships loaders for PHP and Twig templates.
208+
209+
An ``alias`` attribute defines the name of the loader.
210+
211+
assetic.formula_resource
212+
------------------------
213+
214+
**Purpose**: Adds a resource to the current asset manager
215+
216+
A resource is something formulae can be loaded from. For instance, Twig
217+
templates are resources.
218+
219+
assetic.templating.php
220+
----------------------
221+
222+
**Purpose**: Remove this service if PHP templating is disabled
223+
224+
The tagged service will be removed from the container if the
225+
``framework.templating.engines`` config section does not contain php.
226+
227+
assetic.templating.twig
228+
-----------------------
229+
230+
**Purpose**: Remove this service if Twig templating is disabled
231+
232+
The tagged service will be removed from the container if
233+
``framework.templating.engines`` config section does not contain ``twig``.
234+
52235
auto_alias
53236
----------
54237

0 commit comments

Comments
 (0)