Skip to content

Commit 378ad68

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents f7587f0 + 10ea5e9 commit 378ad68

File tree

394 files changed

+9586
-6474
lines changed

Some content is hidden

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

394 files changed

+9586
-6474
lines changed

best_practices/business-logic.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Inside here, you can create whatever directories you want to organize things:
2121
│ └─ AppBundle/
2222
│ └─ Utils/
2323
│ └─ MyClass.php
24+
├─ tests/
25+
├─ var/
2426
├─ vendor/
2527
└─ web/
2628
@@ -40,6 +42,8 @@ and put things there:
4042
│ │ └─ Utils/
4143
│ │ └─ MyClass.php
4244
│ └─ AppBundle/
45+
├─ tests/
46+
├─ var/
4347
├─ vendor/
4448
└─ web/
4549
@@ -145,7 +149,7 @@ the class namespace as a parameter:
145149
146150
services:
147151
app.slugger:
148-
class: "%slugger.class%"
152+
class: '%slugger.class%'
149153
150154
This practice is cumbersome and completely unnecessary for your own services:
151155

@@ -193,7 +197,7 @@ The three entities defined by our sample blog application are a good example:
193197
Doctrine Mapping Information
194198
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
195199

196-
Doctrine Entities are plain PHP objects that you store in some "database".
200+
Doctrine entities are plain PHP objects that you store in some "database".
197201
Doctrine only knows about your entities through the mapping metadata configured
198202
for your model classes. Doctrine supports four metadata formats: YAML, XML,
199203
PHP and annotations.
@@ -318,7 +322,7 @@ command:
318322

319323
.. code-block:: bash
320324
321-
$ php app/console doctrine:fixtures:load
325+
$ php bin/console doctrine:fixtures:load
322326
323327
Careful, database will be purged. Do you want to continue Y/N ? Y
324328
> purging database

best_practices/configuration.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ Canonical Parameters
5252
Define all your application's parameters in the
5353
``app/config/parameters.yml.dist`` file.
5454

55-
Since version 2.3, Symfony includes a configuration file called ``parameters.yml.dist``,
56-
which stores the canonical list of configuration parameters for the application.
55+
Symfony includes a configuration file called ``parameters.yml.dist``, which
56+
stores the canonical list of configuration parameters for the application.
5757

5858
Whenever a new configuration parameter is defined for the application, you
5959
should also add it to this file and submit the changes to your version control
@@ -107,9 +107,7 @@ If you've done something like this in the past, it's likely that you've in fact
107107
*never* actually needed to change that value. Creating a configuration
108108
option for a value that you are never going to configure just isn't necessary.
109109
Our recommendation is to define these values as constants in your application.
110-
You could, for example, define a ``NUM_ITEMS`` constant in the ``Post`` entity:
111-
112-
.. code-block:: php
110+
You could, for example, define a ``NUM_ITEMS`` constant in the ``Post`` entity::
113111

114112
// src/AppBundle/Entity/Post.php
115113
namespace AppBundle\Entity;
@@ -128,7 +126,7 @@ from places with access to the Symfony container.
128126
Constants can be used for example in your Twig templates thanks to the
129127
`constant() function`_:
130128

131-
.. code-block:: html+jinja
129+
.. code-block:: html+twig
132130

133131
<p>
134132
Displaying the {{ constant('NUM_ITEMS', post) }} most recent results.

best_practices/controllers.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ configuration to the main routing configuration file:
4343
4444
# app/config/routing.yml
4545
app:
46-
resource: "@AppBundle/Controller/"
46+
resource: '@AppBundle/Controller/'
4747
type: annotation
4848
4949
This configuration will load annotations from any controller stored inside the
@@ -73,7 +73,7 @@ Template Configuration
7373

7474
.. best-practice::
7575

76-
Don't use the ``@Template()`` annotation to configure the template used by
76+
Don't use the ``@Template`` annotation to configure the template used by
7777
the controller.
7878

7979
The ``@Template`` annotation is useful, but also involves some magic. We
@@ -148,7 +148,7 @@ For example:
148148
));
149149
}
150150
151-
Normally, you'd expect a ``$id`` argument to ``showAction``. Instead, by
151+
Normally, you'd expect a ``$id`` argument to ``showAction()``. Instead, by
152152
creating a new argument (``$post``) and type-hinting it with the ``Post``
153153
class (which is a Doctrine entity), the ParamConverter automatically queries
154154
for an object whose ``$id`` property matches the ``{id}`` value. It will
@@ -157,7 +157,7 @@ also show a 404 page if no ``Post`` can be found.
157157
When Things Get More Advanced
158158
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
159159

160-
This works without any configuration because the wildcard name ``{id}`` matches
160+
The above example works without any configuration because the wildcard name ``{id}`` matches
161161
the name of the property on the entity. If this isn't true, or if you have
162162
even more complex logic, the easiest thing to do is just query for the entity
163163
manually. In our application, we have this situation in ``CommentController``:

best_practices/creating-the-project.rst

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ to create files and execute the following commands:
2727

2828
.. code-block:: bash
2929
30-
# Linux, Mac OS X
3130
$ cd projects/
3231
$ symfony new blog
3332
3433
# Windows
3534
c:\> cd projects/
36-
c:\projects\> php symfony.phar new blog
35+
c:\projects\> php symfony new blog
36+
37+
.. note::
38+
39+
If the installer doesn't work for you or doesn't output anything, make sure
40+
that the `Phar extension`_ is installed and enabled on your computer.
3741

3842
This command creates a new directory called ``blog`` that contains a fresh new
3943
project based on the most recent stable Symfony version available. In addition,
@@ -58,27 +62,35 @@ number of files and directories generated automatically:
5862
5963
blog/
6064
├─ app/
61-
│ ├─ console
62-
│ ├─ cache/
6365
│ ├─ config/
64-
│ ├─ logs/
6566
│ └─ Resources/
67+
├─ bin
68+
│ └─ console
6669
├─ src/
6770
│ └─ AppBundle/
71+
├─ var/
72+
│ ├─ cache/
73+
│ ├─ logs/
74+
│ └─ sessions/
75+
├─ tests/
76+
│ └─ AppBundle/
6877
├─ vendor/
6978
└─ web/
7079
7180
This file and directory hierarchy is the convention proposed by Symfony to
7281
structure your applications. The recommended purpose of each directory is the
7382
following:
7483

75-
* ``app/cache/``, stores all the cache files generated by the application;
7684
* ``app/config/``, stores all the configuration defined for any environment;
77-
* ``app/logs/``, stores all the log files generated by the application;
7885
* ``app/Resources/``, stores all the templates and the translation files for the
7986
application;
8087
* ``src/AppBundle/``, stores the Symfony specific code (controllers and routes),
8188
your domain code (e.g. Doctrine classes) and all your business logic;
89+
* ``var/cache/``, stores all the cache files generated by the application;
90+
* ``var/logs/``, stores all the log files generated by the application;
91+
* ``var/sessions/``, stores all the session files generated by the application;
92+
* ``tests/AppBundle/``, stores the automatic tests (e.g. Unit tests) of the
93+
application.
8294
* ``vendor/``, this is the directory where Composer installs the application's
8395
dependencies and you should never modify any of its contents;
8496
* ``web/``, stores all the front controller files and all the web assets, such
@@ -99,21 +111,20 @@ ProductBundle, then there's no advantage to having two separate bundles.
99111

100112
.. best-practice::
101113

102-
Create only one bundle called AppBundle for your application logic
114+
Create only one bundle called AppBundle for your application logic.
103115

104116
Implementing a single AppBundle bundle in your projects will make your code
105-
more concise and easier to understand. Starting in Symfony 2.6, the official
106-
Symfony documentation uses the AppBundle name.
117+
more concise and easier to understand.
107118

108119
.. note::
109120

110121
There is no need to prefix the AppBundle with your own vendor (e.g.
111122
AcmeAppBundle), because this application bundle is never going to be
112123
shared.
113-
124+
114125
.. note::
115-
116-
Another reason to create a new bundle is when you're overriding something
126+
127+
Another reason to create a new bundle is when you're overriding something
117128
in a vendor's bundle (e.g. a controller). See :doc:`/cookbook/bundles/inheritance`.
118129

119130
All in all, this is the typical directory structure of a Symfony application
@@ -123,13 +134,18 @@ that follows these best practices:
123134
124135
blog/
125136
├─ app/
126-
│ ├─ console
127-
│ ├─ cache/
128137
│ ├─ config/
129-
│ ├─ logs/
130138
│ └─ Resources/
139+
├─ bin/
140+
│ └─ console
131141
├─ src/
132142
│ └─ AppBundle/
143+
├─ tests/
144+
│ └─ AppBundle/
145+
├─ var/
146+
│ ├─ cache/
147+
│ ├─ logs/
148+
└─ sessions/
133149
├─ vendor/
134150
└─ web/
135151
├─ app.php
@@ -142,7 +158,7 @@ that follows these best practices:
142158

143159
.. code-block:: bash
144160
145-
$ php app/console generate:bundle --namespace=AppBundle --dir=src --format=annotation --no-interaction
161+
$ php bin/console generate:bundle --namespace=AppBundle --dir=src --format=annotation --no-interaction
146162
147163
Extending the Directory Structure
148164
---------------------------------
@@ -152,29 +168,7 @@ structure of Symfony, you can
152168
:doc:`override the location of the main directories </cookbook/configuration/override_dir_structure>`:
153169
``cache/``, ``logs/`` and ``web/``.
154170

155-
In addition, Symfony3 will use a slightly different directory structure when
156-
it's released:
157-
158-
.. code-block:: text
159-
160-
blog-symfony3/
161-
├─ app/
162-
│ ├─ config/
163-
│ └─ Resources/
164-
├─ bin/
165-
│ └─ console
166-
├─ src/
167-
├─ var/
168-
│ ├─ cache/
169-
│ └─ logs/
170-
├─ vendor/
171-
└─ web/
172-
173-
The changes are pretty superficial, but for now, we recommend that you use
174-
the Symfony directory structure.
175-
176171
.. _`Composer`: https://getcomposer.org/
177-
.. _`Get Started`: https://getcomposer.org/doc/00-intro.md
178-
.. _`Composer download page`: https://getcomposer.org/download/
172+
.. _`Phar extension`: http://php.net/manual/en/intro.phar.php
179173
.. _`public checksums repository`: https://github.com/sensiolabs/checksums
180-
.. _`these steps`: http://fabien.potencier.org/signing-project-releases.html
174+
.. _`these steps`: http://fabien.potencier.org/signing-project-releases.html

0 commit comments

Comments
 (0)