Skip to content

Commit 8bca8c2

Browse files
committed
Merge remote-tracking branch 'upstream/2.6'
2 parents 0c92fab + a2ea256 commit 8bca8c2

File tree

104 files changed

+1892
-1536
lines changed

Some content is hidden

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

104 files changed

+1892
-1536
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ language: python
33
python:
44
- "2.7"
55

6+
sudo: false
7+
68
install:
79
- "pip install -q -r requirements.txt --use-mirrors"
810

best_practices/business-logic.rst

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Inside here, you can create whatever directories you want to organize things:
1515

1616
.. code-block:: text
1717
18-
symfoy2-project/
18+
symfony2-project/
1919
├─ app/
2020
├─ src/
2121
│ └─ AppBundle/
@@ -33,7 +33,7 @@ and put things there:
3333

3434
.. code-block:: text
3535
36-
symfoy2-project/
36+
symfony2-project/
3737
├─ app/
3838
├─ src/
3939
│ ├─ Acme/
@@ -81,7 +81,7 @@ Next, define a new service for that class.
8181
# app/config/services.yml
8282
services:
8383
# keep your service names short
84-
slugger:
84+
app.slugger:
8585
class: AppBundle\Utils\Slugger
8686
8787
Traditionally, the naming convention for a service involved following the
@@ -92,7 +92,8 @@ your code will be easier to read and use.
9292
.. best-practice::
9393

9494
The name of your application's services should be as short as possible,
95-
ideally just one simple word.
95+
but unique enough that you can search your project for the service if
96+
you ever need to.
9697

9798
Now you can use the custom slugger in any controller class, such as the
9899
``AdminController``:
@@ -104,7 +105,7 @@ Now you can use the custom slugger in any controller class, such as the
104105
// ...
105106
106107
if ($form->isSubmitted() && $form->isValid()) {
107-
$slug = $this->get('slugger')->slugify($post->getTitle());
108+
$slug = $this->get('app.slugger')->slugify($post->getTitle());
108109
$post->setSlug($slug);
109110
110111
// ...
@@ -139,12 +140,9 @@ the class namespace as a parameter:
139140
# app/config/services.yml
140141
141142
# service definition with class namespace as parameter
142-
parameters:
143-
slugger.class: AppBundle\Utils\Slugger
144-
145143
services:
146-
slugger:
147-
class: "%slugger.class%"
144+
app.slugger:
145+
class: AppBundle\Utils\Slugger
148146
149147
This practice is cumbersome and completely unnecessary for your own services:
150148

@@ -299,7 +297,7 @@ Then, enable the bundle in ``AppKernel.php``, but only for the ``dev`` and
299297
300298
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
301299
// ...
302-
$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
300+
$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
303301
}
304302
305303
return $bundles;
@@ -334,8 +332,8 @@ in a matter of seconds.
334332

335333
.. _`full definition`: http://en.wikipedia.org/wiki/Business_logic
336334
.. _`Doctrine project`: http://www.doctrine-project.org/
337-
.. _`fixture class`: http://symfony.com/doc/master/bundles/DoctrineFixturesBundle/index.html#writing-simple-fixtures
335+
.. _`fixture class`: http://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html#writing-simple-fixtures
338336
.. _`PSR-1`: http://www.php-fig.org/psr/psr-1/
339337
.. _`PSR-2`: http://www.php-fig.org/psr/psr-2/
340338
.. _`the Symfony Code Standards`: http://symfony.com/doc/current/contributing/code/standards.html
341-
.. _`PHP-CS-Fixer`: https://github.com/fabpot/PHP-CS-Fixer
339+
.. _`PHP-CS-Fixer`: https://github.com/FriendsOfPHP/PHP-CS-Fixer

best_practices/configuration.rst

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ add an extra layer of configuration that's not needed because you don't need
7474
or want these configuration values to change on each server.
7575

7676
The configuration options defined in the ``config.yml`` file usually vary from
77-
one `execution environment`_ to another. That's why Symfony already includes
78-
``app/config/config_dev.yml`` and ``app/config/config_prod.yml`` files so
79-
that you can override specific values for each environment.
77+
one :doc:`/cookbook/configuration/environments` to another. That's why Symfony
78+
already includes ``app/config/config_dev.yml`` and ``app/config/config_prod.yml``
79+
files so that you can override specific values for each environment.
8080

8181
Constants vs Configuration Options
8282
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -158,10 +158,10 @@ Semantic Configuration: Don't Do It
158158

159159
Don't define a semantic dependency injection configuration for your bundles.
160160

161-
As explained in `How to Expose a semantic Configuration for a Bundle`_ article,
162-
Symfony bundles have two choices on how to handle configuration: normal service
163-
configuration through the ``services.yml`` file and semantic configuration
164-
through a special ``*Extension`` class.
161+
As explained in :doc:`/cookbook/bundles/extension` article, Symfony bundles
162+
have two choices on how to handle configuration: normal service configuration
163+
through the ``services.yml`` file and semantic configuration through a special
164+
``*Extension`` class.
165165

166166
Although semantic configuration is much more powerful and provides nice features
167167
such as configuration validation, the amount of work needed to define that
@@ -174,10 +174,7 @@ Moving Sensitive Options Outside of Symfony Entirely
174174
When dealing with sensitive options, like database credentials, we also recommend
175175
that you store them outside the Symfony project and make them available
176176
through environment variables. Learn how to do it in the following article:
177-
`How to Set external Parameters in the Service Container`_
177+
:doc:`/cookbook/configuration/external_parameters`
178178

179179
.. _`feature toggles`: http://en.wikipedia.org/wiki/Feature_toggle
180-
.. _`execution environment`: http://symfony.com/doc/current/cookbook/configuration/environments.html
181180
.. _`constant() function`: http://twig.sensiolabs.org/doc/functions/constant.html
182-
.. _`How to Expose a semantic Configuration for a Bundle`: http://symfony.com/doc/current/cookbook/bundles/extension.html
183-
.. _`How to Set external Parameters in the Service Container`: http://symfony.com/doc/current/cookbook/configuration/external_parameters.html

best_practices/controllers.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ Pre and Post Hooks
206206
------------------
207207

208208
If you need to execute some code before or after the execution of your controllers,
209-
you can use the EventDispatcher component to `set up before/after filters`_.
209+
you can use the EventDispatcher component to :doc:`/cookbook/event_dispatcher/before_after_filters`.
210210

211211
.. _`ParamConverter`: http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html
212-
.. _`set up before/after filters`: http://symfony.com/doc/current/cookbook/event_dispatcher/before_after_filters.html

best_practices/creating-the-project.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ Extending the Directory Structure
220220
---------------------------------
221221

222222
If your project or infrastructure requires some changes to the default directory
223-
structure of Symfony, you can `override the location of the main directories`_:
223+
structure of Symfony, you can
224+
:doc:`override the location of the main directories </cookbook/configuration/override_dir_structure>`:
224225
``cache/``, ``logs/`` and ``web/``.
225226

226227
In addition, Symfony3 will use a slightly different directory structure when
@@ -247,6 +248,5 @@ the Symfony2 directory structure.
247248
.. _`Composer`: https://getcomposer.org/
248249
.. _`Get Started`: https://getcomposer.org/doc/00-intro.md
249250
.. _`Composer download page`: https://getcomposer.org/download/
250-
.. _`override the location of the main directories`: http://symfony.com/doc/current/cookbook/configuration/override_dir_structure.html
251251
.. _`public checksums repository`: https://github.com/sensiolabs/checksums
252252
.. _`these steps`: http://fabien.potencier.org/article/73/signing-project-releases

best_practices/forms.rst

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ Building Forms
1515
The Form component allows you to build forms right inside your controller
1616
code. Honestly, unless you need to reuse the form somewhere else, that's
1717
totally fine. But for organize and reuse, we recommend that you define each
18-
form in its own PHP class:
19-
20-
.. code-block:: php
18+
form in its own PHP class::
2119

2220
namespace AppBundle\Form;
2321

@@ -51,9 +49,7 @@ form in its own PHP class:
5149
}
5250
}
5351

54-
To use the class, use ``createForm`` and instantiate the new class:
55-
56-
.. code-block:: php
52+
To use the class, use ``createForm`` and instantiate the new class::
5753

5854
use AppBundle\Form\PostType;
5955
// ...
@@ -69,9 +65,11 @@ To use the class, use ``createForm`` and instantiate the new class:
6965
Registering Forms as Services
7066
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7167

72-
You can also `register your form type as a service`_. But this is *not* recommended
73-
unless you plan to reuse the new form type in many places or embed it in
74-
other forms directly or via the `collection type`_.
68+
You can also
69+
:ref:`register your form type as a service <form-cookbook-form-field-service>`.
70+
But this is *not* recommended unless you plan to reuse the new form type in many
71+
places or embed it in other forms directly or via the
72+
:doc:`collection type </reference/forms/types/collection>`.
7573

7674
For most forms that are used only to edit or create something, registering
7775
the form as a service is over-kill, and makes it more difficult to figure
@@ -108,9 +106,7 @@ directly in your form class, this would effectively limit the scope of that form
108106
109107
This form *may* have been designed for creating posts, but if you wanted
110108
to reuse it for editing posts, the button label would be wrong. Instead,
111-
some developers configure form buttons in the controller:
112-
113-
.. code-block:: php
109+
some developers configure form buttons in the controller::
114110

115111
namespace AppBundle\Controller\Admin;
116112

@@ -143,12 +139,12 @@ view layer:
143139

144140
.. code-block:: html+jinja
145141

146-
<form method="POST" {{ form_enctype(form) }}>
142+
{{ form_start(form) }}
147143
{{ form_widget(form) }}
148144

149145
<input type="submit" value="Create"
150146
class="btn btn-default pull-right" />
151-
</form>
147+
{{ form_end(form) }}
152148

153149
Rendering the Form
154150
------------------
@@ -157,33 +153,19 @@ There are a lot of ways to render your form, ranging from rendering the entire
157153
thing in one line to rendering each part of each field independently. The
158154
best way depends on how much customization you need.
159155

160-
The simplest way - which is especially useful during development - is to render
161-
the form tags manually and then use ``form_widget()`` to render all of the fields:
156+
One of the simplest ways - which is especially useful during development -
157+
is to render the form tags and use ``form_widget()`` to render all of the
158+
fields:
162159

163160
.. code-block:: html+jinja
164161

165-
<form method="POST" {{ form_enctype(form) }}>
162+
{{ form_start(form, {'attr': {'class': 'my-form-class'} }) }}
166163
{{ form_widget(form) }}
167-
</form>
168-
169-
.. best-practice::
170-
171-
Don't use the ``form()`` or ``form_start()`` functions to render the
172-
starting and ending form tags.
173-
174-
Experienced Symfony developers will recognize that we're rendering the ``<form>``
175-
tags manually instead of using the ``form_start()`` or ``form()`` functions.
176-
While those are convenient, they take away from some clarity with little
177-
benefit.
178-
179-
.. tip::
180-
181-
The exception is a delete form because it's really just one button and
182-
so benefits from some of these extra shortcuts.
164+
{{ form_end(form) }}
183165

184166
If you need more control over how your fields are rendered, then you should
185167
remove the ``form_widget(form)`` function and render your fields individually.
186-
See `How to Customize Form Rendering`_ for more information on this and how
168+
See :doc:`/cookbook/form/form_customization` for more information on this and how
187169
you can control *how* the form renders at a global level using form theming.
188170

189171
Handling Form Submits
@@ -224,8 +206,3 @@ Second, we recommend using ``$form->isSubmitted()`` in the ``if`` statement
224206
for clarity. This isn't technically needed, since ``isValid()`` first calls
225207
``isSubmitted()``. But without this, the flow doesn't read well as it *looks*
226208
like the form is *always* processed (even on the GET request).
227-
228-
.. _`register your form type as a service`: http://symfony.com/doc/current/cookbook/form/create_custom_field_type.html#creating-your-field-type-as-a-service
229-
.. _`collection type`: http://symfony.com/doc/current/reference/forms/types/collection.html
230-
.. _`How to Customize Form Rendering`: http://symfony.com/doc/current/cookbook/form/form_customization.html
231-
.. _`form event system`: http://symfony.com/doc/current/cookbook/form/dynamic_form_modification.html

best_practices/i18n.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ English in the application would be:
8383
<!-- app/Resources/translations/messages.en.xliff -->
8484
<?xml version="1.0"?>
8585
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
86-
<file source-language="en" target-language="en" datatype="plaintext">
86+
<file source-language="en" target-language="en" datatype="plaintext" original="file.ext">
8787
<body>
8888
<trans-unit id="1">
8989
<source>title.post_list</source>

best_practices/introduction.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Who this Book Is for (Hint: It's not a Tutorial)
5959
Any Symfony developer, whether you are an expert or a newcomer, can read this
6060
guide. But since this isn't a tutorial, you'll need some basic knowledge of
6161
Symfony to follow everything. If you are totally new to Symfony, welcome!
62-
Start with `The Quick Tour`_ tutorial first.
62+
Start with :doc:`The Quick Tour </quick_tour/the_big_picture>` tutorial first.
6363

6464
We've deliberately kept this guide short. We won't repeat explanations that
6565
you can find in the vast Symfony documentation, like discussions about dependency
@@ -95,7 +95,3 @@ practices**. The reasons for not doing it are various:
9595
your tests or adding features that provide real value to the end users.
9696

9797
.. _`Fabien Potencier`: https://connect.sensiolabs.com/profile/fabpot
98-
.. _`The Quick Tour`: http://symfony.com/doc/current/quick_tour/the_big_picture.html
99-
.. _`The Official Symfony Book`: http://symfony.com/doc/current/book/index.html
100-
.. _`The Symfony Cookbook`: http://symfony.com/doc/current/cookbook/index.html
101-
.. _`github.com/.../...`: http://github.com/.../...

best_practices/security.rst

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Authentication and Firewalls (i.e. Getting the User's Credentials)
66

77
You can configure Symfony to authenticate your users using any method you
88
want and to load user information from any source. This is a complex topic,
9-
but the `Security Cookbook Section`_ has a lot of information about this.
9+
but the :doc:`Security Cookbook Section </cookbook/security/index>` has a
10+
lot of information about this.
1011

1112
Regardless of your needs, authentication is configured in ``security.yml``,
1213
primarily under the ``firewalls`` key.
@@ -72,8 +73,9 @@ Authorization (i.e. Denying Access)
7273
-----------------------------------
7374

7475
Symfony gives you several ways to enforce authorization, including the ``access_control``
75-
configuration in `security.yml`_, the :ref:`@Security annotation <best-practices-security-annotation>`
76-
and using :ref:`isGranted <best-practices-directy-isGranted>` on the ``security.context``
76+
configuration in :doc:`security.yml </reference/configuration/security>` the
77+
:ref:`@Security annotation <best-practices-security-annotation>` and using
78+
:ref:`isGranted <best-practices-directly-isGranted>` on the ``security.context``
7779
service directly.
7880

7981
.. best-practice::
@@ -204,7 +206,7 @@ Now you can reuse this method both in the template and in the security expressio
204206
<a href=""> ... </a>
205207
{% endif %}
206208

207-
.. _best-practices-directy-isGranted:
209+
.. _best-practices-directly-isGranted:
208210

209211
Checking Permissions without @Security
210212
--------------------------------------
@@ -240,8 +242,8 @@ Security Voters
240242

241243
If your security logic is complex and can't be centralized into a method
242244
like ``isAuthor()``, you should leverage custom voters. These are an order
243-
of magnitude easier than `ACL's`_ and will give you the flexibility you need
244-
in almost all cases.
245+
of magnitude easier than :doc:`ACL's </cookbook/security/acl>` and will give
246+
you the flexibility you need in almost all cases.
245247

246248
First, create a voter class. The following example shows a voter that implements
247249
the same ``getAuthorEmail`` logic you used above:
@@ -337,27 +339,22 @@ The `FOSUserBundle`_, developed by the Symfony community, adds support for a
337339
database-backed user system in Symfony2. It also handles common tasks like
338340
user registration and forgotten password functionality.
339341

340-
Enable the `Remember Me feature`_ to allow your users to stay logged in for
341-
a long period of time.
342+
Enable the :doc:`Remember Me feature </cookbook/security/remember_me>` to
343+
allow your users to stay logged in for a long period of time.
342344

343345
When providing customer support, sometimes it's necessary to access the application
344346
as some *other* user so that you can reproduce the problem. Symfony provides
345-
the ability to `impersonate users`_.
347+
the ability to :doc:`impersonate users </cookbook/security/impersonating_user>`.
346348

347349
If your company uses a user login method not supported by Symfony, you can
348-
develop `your own user provider`_ and `your own authentication provider`_.
350+
develop :doc:`your own user provider </cookbook/security/custom_provider>` and
351+
:doc:`your own authentication provider </cookbook/security/custom_authentication_provider>`.
349352

350353
.. _`Security Cookbook Section`: http://symfony.com/doc/current/cookbook/security/index.html
351354
.. _`security.yml`: http://symfony.com/doc/current/reference/configuration/security.html
352355
.. _`ParamConverter`: http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html
353356
.. _`@Security annotation`: http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/security.html
354-
.. _`security.yml`: http://symfony.com/doc/current/reference/configuration/security.html
355357
.. _`security voter`: http://symfony.com/doc/current/cookbook/security/voters_data_permission.html
356-
.. _`Acces Control List`: http://symfony.com/doc/current/cookbook/security/acl.html
357358
.. _`ACL's`: http://symfony.com/doc/current/cookbook/security/acl.html
358359
.. _`expression`: http://symfony.com/doc/current/components/expression_language/introduction.html
359360
.. _`FOSUserBundle`: https://github.com/FriendsOfSymfony/FOSUserBundle
360-
.. _`Remember Me feature`: http://symfony.com/doc/current/cookbook/security/remember_me.html
361-
.. _`impersonate users`: http://symfony.com/doc/current/cookbook/security/impersonating_user.html
362-
.. _`your own user provider`: http://symfony.com/doc/current/cookbook/security/custom_provider.html
363-
.. _`your own authentication provider`: http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html

best_practices/templates.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,5 @@ name is irrelevant because you never use it in your own code):
156156
tags:
157157
- { name: twig.extension }
158158
159-
160159
.. _`Twig`: http://twig.sensiolabs.org/
161160
.. _`Parsedown`: http://parsedown.org/
162-
.. _`Twig global variables`: http://symfony.com/doc/master/cookbook/templating/global_variables.html
163-
.. _`override error pages`: http://symfony.com/doc/current/cookbook/controller/error_pages.html
164-
.. _`render a template without using a controller`: http://symfony.com/doc/current/cookbook/templating/render_without_controller.html

0 commit comments

Comments
 (0)