Skip to content

Commit b48b4c4

Browse files
mpdudejaviereguiluz
authored andcommitted
Twig Extensions Reference minor brush-up
1 parent 4e7ae43 commit b48b4c4

File tree

183 files changed

+3069
-1344
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+3069
-1344
lines changed

.platform.app.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ hooks:
5656
# Platform.sh currently sets PIP_USER=1.
5757
export PIP_USER=
5858
pip install pip==9.0.1 wheel==0.29.0
59-
pip install -r requirements.txt
59+
pip install -r _build/.requirements.txt
6060
make -C _build html
File renamed without changes.

_build/make.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ REM Command file for Sphinx documentation
55
if "%SPHINXBUILD%" == "" (
66
set SPHINXBUILD=sphinx-build
77
)
8-
set BUILDDIR=_build
9-
set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
8+
set BUILDDIR=.
9+
set ALLSPHINXOPTS=-c %BUILDDIR% -d %BUILDDIR%/doctrees %SPHINXOPTS% ..
1010
set I18NSPHINXOPTS=%SPHINXOPTS% .
1111
if NOT "%PAPER%" == "" (
1212
set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%

_build/redirection_map

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,5 @@
332332
/deployment/tools /deployment
333333
/install/bundles /setup/bundles
334334
/form /forms
335+
/testing/simulating_authentication /testing/http_authentication
336+
/components/dependency_injection/autowiring /service_container/autowiring
-12 KB
Loading

_images/security/anonymous_wdt.png

-1.9 KB
Loading
-3.56 KB
Loading

assetic/apply_to_option.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,9 @@ In this case you can specify that the ``coffee`` filter is applied to all
163163
name="coffee"
164164
bin="/usr/bin/coffee"
165165
node="/usr/bin/node"
166-
apply_to="\.coffee$" />
167-
<assetic:node-paths>/usr/lib/node_modules/</assetic:node-path>
166+
apply-to="\.coffee$">
167+
<assetic:node-path>/usr/lib/node_modules/</assetic:node-path>
168+
</assetic:filter>
168169
</assetic:config>
169170
</container>
170171
@@ -174,10 +175,10 @@ In this case you can specify that the ``coffee`` filter is applied to all
174175
$container->loadFromExtension('assetic', array(
175176
'filters' => array(
176177
'coffee' => array(
177-
'bin' => '/usr/bin/coffee',
178-
'node' => '/usr/bin/node',
178+
'bin' => '/usr/bin/coffee',
179+
'node' => '/usr/bin/node',
179180
'node_paths' => array('/usr/lib/node_modules/'),
180-
'apply_to' => '\.coffee$',
181+
'apply_to' => '\.coffee$',
181182
),
182183
),
183184
));

assetic/asset_management.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ configuration under the ``assetic`` section. Read more in the
411411
),
412412
),
413413
),
414-
);
414+
));
415415
416416
After you have defined the named assets, you can reference them in your templates
417417
with the ``@named_asset`` notation:

assetic/jpeg_optimize.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ to ``true``:
113113
<assetic:filter
114114
name="jpegoptim"
115115
bin="path/to/jpegoptim"
116-
strip_all="true" />
116+
strip-all="true" />
117117
</assetic:config>
118118
</container>
119119
@@ -217,7 +217,7 @@ following configuration:
217217
name="jpegoptim"
218218
bin="path/to/jpegoptim" />
219219
<assetic:twig>
220-
<assetic:twig_function
220+
<assetic:function
221221
name="jpegoptim" />
222222
</assetic:twig>
223223
</assetic:config>
@@ -234,7 +234,6 @@ following configuration:
234234
),
235235
'twig' => array(
236236
'functions' => array('jpegoptim'),
237-
),
238237
),
239238
));
240239
@@ -277,7 +276,7 @@ file:
277276
name="jpegoptim"
278277
bin="path/to/jpegoptim" />
279278
<assetic:twig>
280-
<assetic:twig_function
279+
<assetic:function
281280
name="jpegoptim"
282281
output="images/*.jpg" />
283282
</assetic:twig>
@@ -296,7 +295,7 @@ file:
296295
'twig' => array(
297296
'functions' => array(
298297
'jpegoptim' => array(
299-
output => 'images/*.jpg'
298+
'output' => 'images/*.jpg',
300299
),
301300
),
302301
),
@@ -308,4 +307,4 @@ file:
308307
`LiipImagineBundle`_ community bundle.
309308

310309
.. _`Jpegoptim`: http://www.kokkonen.net/tjko/projects.html
311-
.. _`LiipImagineBundle`: http://knpbundles.com/liip/LiipImagineBundle
310+
.. _`LiipImagineBundle`: https://github.com/liip/LiipImagineBundle

assetic/php.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ First, configure a new ``scssphp`` Assetic filter:
9999
http://symfony.com/schema/dic/assetic/assetic-1.0.xsd">
100100
101101
<assetic:config>
102-
<filter name="scssphp" formatter="Leafo\ScssPhp\Formatter\Compressed" />
102+
<assetic:filter name="scssphp" formatter="Leafo\ScssPhp\Formatter\Compressed" />
103103
<!-- ... -->
104104
</assetic:config>
105105
</container>
@@ -172,7 +172,7 @@ First, configure a new ``jsqueeze`` Assetic filter as follows:
172172
http://symfony.com/schema/dic/assetic/assetic-1.0.xsd">
173173
174174
<assetic:config>
175-
<filter name="jsqueeze" />
175+
<assetic:filter name="jsqueeze" />
176176
<!-- ... -->
177177
</assetic:config>
178178
</container>

assetic/uglifyjs.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ can configure its location using the ``node`` key:
170170
171171
// app/config/config.php
172172
$container->loadFromExtension('assetic', array(
173-
'node' => '/usr/bin/nodejs',
173+
'node' => '/usr/bin/nodejs',
174174
'uglifyjs2' => array(
175-
// the path to the uglifyjs executable
176-
'bin' => '/usr/local/bin/uglifyjs',
177-
),
175+
// the path to the uglifyjs executable
176+
'bin' => '/usr/local/bin/uglifyjs',
177+
),
178178
));
179179
180180
Minify your Assets

assetic/yuicompressor.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ stylesheets:
3838
# java: '/usr/bin/java'
3939
filters:
4040
yui_css:
41-
jar: '%kernel.root_dir%/Resources/java/yuicompressor.jar'
41+
jar: '%kernel.project_dir%/app/Resources/java/yuicompressor.jar'
4242
yui_js:
43-
jar: '%kernel.root_dir%/Resources/java/yuicompressor.jar'
43+
jar: '%kernel.project_dir%/app/Resources/java/yuicompressor.jar'
4444
4545
.. code-block:: xml
4646
@@ -57,10 +57,10 @@ stylesheets:
5757
<assetic:config>
5858
<assetic:filter
5959
name="yui_css"
60-
jar="%kernel.root_dir%/Resources/java/yuicompressor.jar" />
60+
jar="%kernel.project_dir%/app/Resources/java/yuicompressor.jar" />
6161
<assetic:filter
6262
name="yui_js"
63-
jar="%kernel.root_dir%/Resources/java/yuicompressor.jar" />
63+
jar="%kernel.project_dir%/app/Resources/java/yuicompressor.jar" />
6464
</assetic:config>
6565
</container>
6666
@@ -71,10 +71,10 @@ stylesheets:
7171
// 'java' => '/usr/bin/java',
7272
'filters' => array(
7373
'yui_css' => array(
74-
'jar' => '%kernel.root_dir%/Resources/java/yuicompressor.jar',
74+
'jar' => '%kernel.project_dir%/app/Resources/java/yuicompressor.jar',
7575
),
7676
'yui_js' => array(
77-
'jar' => '%kernel.root_dir%/Resources/java/yuicompressor.jar',
77+
'jar' => '%kernel.project_dir%/app/Resources/java/yuicompressor.jar',
7878
),
7979
),
8080
));

best_practices/configuration.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,31 @@ whereas they cannot access the container parameters:
153153
The only notable disadvantage of using constants for this kind of configuration
154154
values is that you cannot redefine them easily in your tests.
155155

156+
Parameter Naming
157+
----------------
158+
159+
.. best-practice::
160+
161+
The name of your configuration parameters should be as short as possible and
162+
should include a common prefix for the entire application.
163+
164+
Using ``app.`` as the prefix of your parameters is a common practice to avoid
165+
collisions with Symfony and third-party bundles/libraries parameters. Then, use
166+
just one or two words to describe the purpose of the parameter:
167+
168+
.. code-block:: yaml
169+
170+
# app/config/config.yml
171+
parameters:
172+
# don't do this: 'dir' is too generic and it doesn't convey any meaning
173+
app.dir: '...'
174+
# do this: short but easy to understand names
175+
app.contents_dir: '...'
176+
# it's OK to use dots, underscores, dashes or nothing, but always
177+
# be consistent and use the same format for all the parameters
178+
app.dir.contents: '...'
179+
app.contents-dir: '...'
180+
156181
Semantic Configuration: Don't Do It
157182
-----------------------------------
158183

best_practices/security.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ To enable the security voter in the application, define a new service:
335335
# app/config/services.yml
336336
services:
337337
# ...
338-
post_voter:
338+
app.post_voter:
339339
class: AppBundle\Security\PostVoter
340340
arguments: ['@security.access.decision_manager']
341341
public: false

bundles.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ of the most common elements of a bundle:
154154
Houses configuration, including routing configuration (e.g. ``routing.yml``).
155155

156156
``Resources/views/``
157-
Holds templates organized by controller name (e.g. ``Hello/index.html.twig``).
157+
Holds templates organized by controller name (e.g. ``Random/index.html.twig``).
158158

159159
``Resources/public/``
160160
Contains web assets (images, stylesheets, etc) and is copied or symbolically
@@ -181,4 +181,4 @@ Learn more
181181

182182
bundles/*
183183

184-
_`third-party bundles`: http://knpbundles.com
184+
_`third-party bundles`: https://github.com/search?q=topic%3Asymfony-bundle&type=Repositories

bundles/configuration.rst

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ bundle configuration would look like:
8181
8282
<!-- app/config/config.xml -->
8383
<?xml version="1.0" ?>
84-
8584
<container xmlns="http://symfony.com/schema/dic/services"
85+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8686
xmlns:acme-social="http://example.org/schema/dic/acme_social"
8787
xsi:schemaLocation="http://symfony.com/schema/dic/services
8888
http://symfony.com/schema/dic/services/services-1.0.xsd">
@@ -218,18 +218,64 @@ This class can now be used in your ``load()`` method to merge configurations and
218218
force validation (e.g. if an additional option was passed, an exception will be
219219
thrown)::
220220

221+
// src/Acme/SocialBundle/DependencyInjection/AcmeSocialExtension.php
222+
221223
public function load(array $configs, ContainerBuilder $container)
222224
{
223225
$configuration = new Configuration();
224226

225227
$config = $this->processConfiguration($configuration, $configs);
226-
// ...
228+
229+
// you now have these 2 config keys
230+
// $config['twitter']['client_id'] and $config['twitter']['client_secret']
227231
}
228232

229233
The ``processConfiguration()`` method uses the configuration tree you've defined
230234
in the ``Configuration`` class to validate, normalize and merge all the
231235
configuration arrays together.
232236

237+
Now, you can use the ``$config`` variable to modify a service provided by your bundle.
238+
For example, imagine your bundle has the following example config:
239+
240+
.. code-block:: xml
241+
242+
<!-- src/Acme/SocialBundle/Resources/config/services.xml -->
243+
<?xml version="1.0" encoding="UTF-8" ?>
244+
<container xmlns="http://symfony.com/schema/dic/services"
245+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
246+
xsi:schemaLocation="http://symfony.com/schema/dic/services
247+
http://symfony.com/schema/dic/services/services-1.0.xsd">
248+
249+
<services>
250+
<service id="acme.social.twitter_client" class="Acme\SocialBundle\TwitterClient">
251+
<argument></argument> <!-- will be filled in with client_id dynamically -->
252+
<argument></argument> <!-- will be filled in with client_secret dynamically -->
253+
</service>
254+
</services>
255+
</container>
256+
257+
In your extension, you can load this and dynamically set its arguments::
258+
259+
// src/Acme/SocialBundle/DependencyInjection/AcmeSocialExtension.php
260+
// ...
261+
262+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
263+
use Symfony\Component\Config\FileLocator;
264+
265+
public function load(array $configs, ContainerBuilder $container)
266+
{
267+
$loader = new XmlFileLoader($container, new FileLocator(dirname(__DIR__).'/Resources/config'));
268+
$loader->load('services.xml');
269+
270+
$configuration = new Configuration();
271+
$config = $this->processConfiguration($configuration, $configs);
272+
273+
$def = $container->getDefinition('acme.social.twitter_client');
274+
$def->replaceArgument(0, $config['twitter']['client_id']);
275+
$def->replaceArgument(1, $config['twitter']['client_secret']);
276+
}
277+
278+
233279
.. tip::
234280

235281
Instead of calling ``processConfiguration()`` in your extension each time you
@@ -253,9 +299,7 @@ configuration arrays together.
253299
}
254300

255301
This class uses the ``getConfiguration()`` method to get the Configuration
256-
instance. You should override it if your Configuration class is not called
257-
``Configuration`` or if it is not placed in the same namespace as the
258-
extension.
302+
instance.
259303

260304
.. sidebar:: Processing the Configuration yourself
261305

bundles/inheritance.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ The same goes for routing files and some other resources.
9393

9494
The overriding of resources only works when you refer to resources with
9595
the ``@FOSUserBundle/Resources/config/routing/security.xml`` method.
96-
If you refer to resources without using the ``@BundleName`` shortcut, they
97-
can't be overridden in this way.
96+
You need to use the ``@BundleName`` shortcut when referring to resources
97+
so they can be successfully overridden (except templates, which are
98+
overridden in a different way, as explained in :doc:`/templating/overriding`).
9899

99100
.. caution::
100101

bundles/installation.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ the bundle on the `Packagist.org`_ site.
2626

2727
.. tip::
2828

29-
Looking for bundles? Try searching at `KnpBundles.com`_: the unofficial
30-
archive of Symfony Bundles.
29+
Looking for bundles? Try searching for `symfony-bundle topic on GitHub`_.
3130

3231
2) Install the Bundle via Composer
3332
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -49,7 +48,7 @@ version, include it as the second argument of the `composer require`_ command:
4948
B) Enable the Bundle
5049
--------------------
5150

52-
At this point, the bundle is installed in your Symfony project (in
51+
At this point, the bundle is installed in your Symfony project (e.g.
5352
``vendor/friendsofsymfony/``) and the autoloader recognizes its classes.
5453
The only thing you need to do now is register the bundle in ``AppKernel``::
5554

@@ -119,14 +118,14 @@ of the bundle's configuration:
119118
120119
The output will look like this:
121120

122-
.. code-block:: text
121+
.. code-block:: yaml
123122
124123
assetic:
125124
debug: '%kernel.debug%'
126125
use_controller:
127126
enabled: '%kernel.debug%'
128127
profiler: false
129-
read_from: '%kernel.root_dir%/../web'
128+
read_from: '%kernel.project_dir%/web'
130129
write_to: '%assetic.read_from%'
131130
java: /usr/bin/java
132131
node: /usr/local/bin/node
@@ -157,5 +156,5 @@ what to do next. Have fun!
157156
.. _their documentation: https://getcomposer.org/doc/00-intro.md
158157
.. _Packagist.org: https://packagist.org
159158
.. _FOSUserBundle: https://github.com/FriendsOfSymfony/FOSUserBundle
160-
.. _KnpBundles.com: http://knpbundles.com/
161159
.. _`composer require`: https://getcomposer.org/doc/03-cli.md#require
160+
.. _`symfony-bundle topic on GitHub`: https://github.com/search?q=topic%3Asymfony-bundle&type=Repositories

0 commit comments

Comments
 (0)