Skip to content

Commit b4c6abc

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 37253f5 + 907ee0d commit b4c6abc

File tree

217 files changed

+4983
-4139
lines changed

Some content is hidden

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

217 files changed

+4983
-4139
lines changed

best_practices/business-logic.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,13 @@ Coding Standards
326326

327327
The Symfony source code follows the `PSR-1`_ and `PSR-2`_ coding standards that
328328
were defined by the PHP community. You can learn more about
329-
`the Symfony Code Standards`_ and even use the `PHP-CS-Fixer`_, which is
330-
a command-line utility that can fix the coding standards of an entire codebase
331-
in a matter of seconds.
329+
:doc:`the Symfony Coding standards </contributing/code/standards>` and even
330+
use the `PHP-CS-Fixer`_, which is a command-line utility that can fix the
331+
coding standards of an entire codebase in a matter of seconds.
332332

333333
.. _`full definition`: http://en.wikipedia.org/wiki/Business_logic
334334
.. _`Doctrine project`: http://www.doctrine-project.org/
335335
.. _`fixture class`: http://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html#writing-simple-fixtures
336336
.. _`PSR-1`: http://www.php-fig.org/psr/psr-1/
337337
.. _`PSR-2`: http://www.php-fig.org/psr/psr-2/
338-
.. _`the Symfony Code Standards`: http://symfony.com/doc/current/contributing/code/standards.html
339338
.. _`PHP-CS-Fixer`: https://github.com/FriendsOfPHP/PHP-CS-Fixer

best_practices/configuration.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ 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 :doc:`/cookbook/configuration/environments` to another. That's why Symfony
78-
already includes ``app/config/config_dev.yml`` and ``app/config/config_prod.yml``
77+
one :doc:`environment </cookbook/configuration/environments>` to another. That's
78+
why Symfony already includes ``app/config/config_dev.yml`` and ``app/config/config_prod.yml``
7979
files so that you can override specific values for each environment.
8080

8181
Constants vs Configuration Options

best_practices/controllers.rst

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ for the homepage of our app:
110110
*/
111111
public function indexAction()
112112
{
113-
$em = $this->getDoctrine()->getManager();
114-
$posts = $em->getRepository('App:Post')->findLatest();
113+
$posts = $this->getDoctrine()
114+
->getRepository('AppBundle:Post')
115+
->findLatest();
115116
116117
return $this->render('default/index.html.twig', array(
117118
'posts' => $posts
@@ -136,6 +137,9 @@ For example:
136137

137138
.. code-block:: php
138139
140+
use AppBundle\Entity\Post;
141+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
142+
139143
/**
140144
* @Route("/{id}", name="admin_post_show")
141145
*/
@@ -144,7 +148,7 @@ For example:
144148
$deleteForm = $this->createDeleteForm($post);
145149
146150
return $this->render('admin/post/show.html.twig', array(
147-
'post' => $post,
151+
'post' => $post,
148152
'delete_form' => $deleteForm->createView(),
149153
));
150154
}
@@ -186,8 +190,10 @@ flexible:
186190

187191
.. code-block:: php
188192
193+
use AppBundle\Entity\Post;
189194
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
190195
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
196+
use Symfony\Component\HttpFoundation\Request;
191197
192198
/**
193199
* @Route("/comment/{postSlug}/new", name = "comment_new")
@@ -206,6 +212,7 @@ Pre and Post Hooks
206212
------------------
207213

208214
If you need to execute some code before or after the execution of your controllers,
209-
you can use the EventDispatcher component to :doc:`/cookbook/event_dispatcher/before_after_filters`.
215+
you can use the EventDispatcher component to
216+
:doc:`set up before and after filters </cookbook/event_dispatcher/before_after_filters>`.
210217

211218
.. _`ParamConverter`: http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html

best_practices/creating-the-project.rst

Lines changed: 31 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,39 @@ Creating the Project
44
Installing Symfony
55
------------------
66

7-
There is only one recommended way to install Symfony:
7+
In the past, Symfony projects were created with `Composer`_, the dependency manager
8+
for PHP applications. However, the current recommendation is to use the **Symfony
9+
Installer**, which has to be installed before creating your first project.
810

9-
.. best-practice::
10-
11-
Always use `Composer`_ to install Symfony.
12-
13-
Composer is the dependency manager used by modern PHP applications. Adding or
14-
removing requirements for your project and updating the third-party libraries
15-
used by your code is a breeze thanks to Composer.
16-
17-
Dependency Management with Composer
18-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11+
Linux and Mac OS X Systems
12+
~~~~~~~~~~~~~~~~~~~~~~~~~~
1913

20-
Before installing Symfony, you need to make sure that you have Composer installed
21-
globally. Open your terminal (also called *command console*) and run the following
22-
command:
14+
Open your command console and execute the following:
2315

2416
.. code-block:: bash
2517
26-
$ composer --version
27-
Composer version 1e27ff5e22df81e3cd0cd36e5fdd4a3c5a031f4a 2014-08-11 15:46:48
18+
$ curl -LsS http://symfony.com/installer > symfony.phar
19+
$ sudo mv symfony.phar /usr/local/bin/symfony
20+
$ chmod a+x /usr/local/bin/symfony
2821
29-
You'll probably see a different version identifier. Never mind because Composer
30-
is updated on a continuous basis and its specific version doesn't matter.
22+
Now you can execute the Symfony Installer as a global system command called
23+
``symfony``.
3124

32-
Installing Composer Globally
33-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25+
Windows Systems
26+
~~~~~~~~~~~~~~~
3427

35-
In case you don't have Composer installed globally, execute the following two
36-
commands if you use Linux or Mac OS X (the second command will ask for your
37-
user password):
28+
Open your command console and execute the following:
3829

3930
.. code-block:: bash
4031
41-
$ curl -sS https://getcomposer.org/installer | php
42-
$ sudo mv composer.phar /usr/local/bin/composer
32+
c:\> php -r "readfile('http://symfony.com/installer');" > symfony.phar
4333
44-
.. note::
34+
Then, move the downloaded ``symfony.phar`` file to your projects directory and
35+
execute it as follows:
4536

46-
Depending on your Linux distribution, you may need to execute ``su`` command
47-
instead of ``sudo``.
37+
.. code-block:: bash
4838
49-
If you use a Windows system, download the executable installer from the
50-
`Composer download page`_ and follow the steps to install it.
39+
c:\> php symfony.phar
5140
5241
Creating the Blog Application
5342
-----------------------------
@@ -58,64 +47,19 @@ to create files and execute the following commands:
5847

5948
.. code-block:: bash
6049
50+
# Linux, Mac OS X
6151
$ cd projects/
62-
$ composer create-project symfony/framework-standard-edition blog/
63-
64-
This command will create a new directory called ``blog`` that will contain
65-
a fresh new project based on the most recent stable Symfony version available.
66-
67-
Checking the Symfony Installation
68-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69-
70-
Once the installation is finished, enter the ``blog/`` directory and check that
71-
Symfony is correctly installed by executing the following command:
72-
73-
.. code-block:: bash
74-
75-
$ cd blog/
76-
$ php app/console --version
77-
78-
Symfony version 2.6.* - app/dev/debug
79-
80-
If you see the installed Symfony version, everything worked as expected. If not,
81-
you can execute the following *script* to check what does prevent your system
82-
from correctly executing Symfony applications:
83-
84-
.. code-block:: bash
85-
86-
$ php app/check.php
87-
88-
Depending on your system, you can see up to two different lists when executing the
89-
`check.php` script. The first one shows the mandatory requirements which your
90-
system must meet to execute Symfony applications. The second list shows the
91-
optional requirements suggested for an optimal execution of Symfony applications:
92-
93-
.. code-block:: bash
94-
95-
Symfony2 Requirements Checker
96-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
97-
98-
> PHP is using the following php.ini file:
99-
/usr/local/zend/etc/php.ini
100-
101-
> Checking Symfony requirements:
102-
.....E.........................W.....
103-
104-
[ERROR]
105-
Your system is not ready to run Symfony2 projects
106-
107-
Fix the following mandatory requirements
108-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109-
110-
* date.timezone setting must be set
111-
> Set the "date.timezone" setting in php.ini* (like Europe/Paris).
112-
113-
Optional recommendations to improve your setup
114-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
52+
$ symfony new blog
11553
116-
* short_open_tag should be disabled in php.ini
117-
> Set short_open_tag to off in php.ini*.
54+
# Windows
55+
c:\> cd projects/
56+
c:\projects\> php symfony.phar new blog
11857
58+
This command creates a new directory called ``blog`` that contains a fresh new
59+
project based on the most recent stable Symfony version available. In addition,
60+
the installer checks if your system meets the technical requirements to execute
61+
Symfony applications. If not, you'll see the list of changes needed to meet those
62+
requirements.
11963

12064
.. tip::
12165

@@ -208,8 +152,7 @@ that follows these best practices:
208152
209153
.. tip::
210154

211-
If you are using Symfony 2.6 or a newer version, the ``AppBundle`` bundle
212-
is already generated for you. If you are using an older Symfony version,
155+
If your Symfony installation doesn't come with a pre-generated ``AppBundle``,
213156
you can generate it by hand executing this command:
214157

215158
.. code-block:: bash
@@ -243,7 +186,7 @@ it's released:
243186
└─ web/
244187
245188
The changes are pretty superficial, but for now, we recommend that you use
246-
the Symfony2 directory structure.
189+
the Symfony directory structure.
247190

248191
.. _`Composer`: https://getcomposer.org/
249192
.. _`Get Started`: https://getcomposer.org/doc/00-intro.md

best_practices/forms.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Building Forms
1313
Define your forms as PHP classes.
1414

1515
The Form component allows you to build forms right inside your controller
16-
code. Honestly, unless you need to reuse the form somewhere else, that's
17-
totally fine. But for organize and reuse, we recommend that you define each
16+
code. This is perfectly fine if you don't need to reuse the form somewhere else.
17+
But for organization and reuse, we recommend that you define each
1818
form in its own PHP class::
1919

2020
namespace AppBundle\Form;
@@ -165,8 +165,9 @@ fields:
165165

166166
If you need more control over how your fields are rendered, then you should
167167
remove the ``form_widget(form)`` function and render your fields individually.
168-
See :doc:`/cookbook/form/form_customization` for more information on this and how
169-
you can control *how* the form renders at a global level using form theming.
168+
See the :doc:`/cookbook/form/form_customization` article for more information
169+
on this and how you can control *how* the form renders at a global level
170+
using form theming.
170171

171172
Handling Form Submits
172173
---------------------

best_practices/security.rst

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ which uses a login form to load users from the database:
4343

4444
.. code-block:: yaml
4545
46+
# app/config/security.yml
4647
security:
4748
encoders:
4849
AppBundle\Entity\User: bcrypt
@@ -73,16 +74,16 @@ Authorization (i.e. Denying Access)
7374
-----------------------------------
7475

7576
Symfony gives you several ways to enforce authorization, including the ``access_control``
76-
configuration in :doc:`security.yml </reference/configuration/security>` the
77+
configuration in :doc:`security.yml </reference/configuration/security>`, the
7778
:ref:`@Security annotation <best-practices-security-annotation>` and using
78-
:ref:`isGranted <best-practices-directly-isGranted>` on the ``security.context``
79+
:ref:`isGranted <best-practices-directly-isGranted>` on the ``security.authorization_checker``
7980
service directly.
8081

8182
.. best-practice::
8283

8384
* For protecting broad URL patterns, use ``access_control``;
8485
* Whenever possible, use the ``@Security`` annotation;
85-
* Check security directly on the ``security.context`` service whenever
86+
* Check security directly on the ``security.authorization_checker`` service whenever
8687
you have a more complex situation.
8788

8889
There are also different ways to centralize your authorization logic, like
@@ -207,6 +208,8 @@ Now you can reuse this method both in the template and in the security expressio
207208
{% endif %}
208209

209210
.. _best-practices-directly-isGranted:
211+
.. _checking-permissions-without-security:
212+
.. _manually-checking-permissions:
210213

211214
Checking Permissions without @Security
212215
--------------------------------------
@@ -315,7 +318,7 @@ Now, you can use the voter with the ``@Security`` annotation:
315318
// ...
316319
}
317320
318-
You can also use this directly with the ``security.context`` service, or
321+
You can also use this directly with the ``security.authorization_checker`` service or
319322
via the even easier shortcut in a controller:
320323

321324
.. code-block:: php
@@ -327,16 +330,20 @@ via the even easier shortcut in a controller:
327330
{
328331
$post = // query for the post ...
329332
330-
if (!$this->get('security.context')->isGranted('edit', $post)) {
331-
throw $this->createAccessDeniedException();
332-
}
333+
$this->denyAccessUnlessGranted('edit', $post);
334+
335+
// or without the shortcut:
336+
//
337+
// if (!$this->get('security.authorization_checker')->isGranted('edit', $post)) {
338+
// throw $this->createAccessDeniedException();
339+
// }
333340
}
334341
335342
Learn More
336343
----------
337344

338345
The `FOSUserBundle`_, developed by the Symfony community, adds support for a
339-
database-backed user system in Symfony2. It also handles common tasks like
346+
database-backed user system in Symfony. It also handles common tasks like
340347
user registration and forgotten password functionality.
341348

342349
Enable the :doc:`Remember Me feature </cookbook/security/remember_me>` to
@@ -350,11 +357,7 @@ If your company uses a user login method not supported by Symfony, you can
350357
develop :doc:`your own user provider </cookbook/security/custom_provider>` and
351358
:doc:`your own authentication provider </cookbook/security/custom_authentication_provider>`.
352359

353-
.. _`Security Cookbook Section`: http://symfony.com/doc/current/cookbook/security/index.html
354-
.. _`security.yml`: http://symfony.com/doc/current/reference/configuration/security.html
355360
.. _`ParamConverter`: http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html
356361
.. _`@Security annotation`: http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/security.html
357-
.. _`security voter`: http://symfony.com/doc/current/cookbook/security/voters_data_permission.html
358-
.. _`ACL's`: http://symfony.com/doc/current/cookbook/security/acl.html
359362
.. _`expression`: http://symfony.com/doc/current/components/expression_language/introduction.html
360363
.. _`FOSUserBundle`: https://github.com/FriendsOfSymfony/FOSUserBundle

best_practices/templates.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ languages - like `Twig`_ - were created to make templating even better.
99

1010
Use Twig templating format for your templates.
1111

12-
Generally speaking, PHP templates are much more verbose than in Twig because
12+
Generally speaking, PHP templates are much more verbose than Twig templates because
1313
they lack native support for lots of modern features needed by templates,
1414
like inheritance, automatic escaping and named arguments for filters and
1515
functions.
@@ -153,6 +153,7 @@ name is irrelevant because you never use it in your own code):
153153
app.twig.app_extension:
154154
class: AppBundle\Twig\AppExtension
155155
arguments: ["@markdown"]
156+
public: false
156157
tags:
157158
- { name: twig.extension }
158159

0 commit comments

Comments
 (0)