Skip to content

Commit e9ef6a4

Browse files
committed
Merge branch '2.3' into 2.6
* 2.3: Adding one more note about why we're in config.yml [#5302] Re-reading sections after moving them, and tweaking some things that did not make sense anymore Update doctrine.rst Place DQL in front of QueryBuilder Slight re-wording of new paragraph with the goal of being as short as possible Fix formatting error Created a new section for rotating log files and explained the max_files configuration option Fixes after review Applied comments [BestPractices] restructured text format for the installation instructions template Fix typo Added new recipe on upgrading a major version Fix little title case mistake Created 'upgrade' cookbook section Added XML and PHP configuration samples Added a note about the rotating_file monolog handler Changing back to config.yml and fixing some code block mistakes thanks to Wouter Making the channel handler more useful by showing it on the prod environment
2 parents 5a34577 + 9fb296d commit e9ef6a4

16 files changed

+473
-248
lines changed

book/doctrine.rst

+44-39
Original file line numberDiff line numberDiff line change
@@ -722,27 +722,30 @@ instead of querying for rows on a table (e.g. ``product``).
722722
When querying in Doctrine, you have two options: writing pure Doctrine queries
723723
or using Doctrine's Query Builder.
724724

725-
Querying for Objects Using Doctrine's Query Builder
726-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
725+
Querying for Objects with DQL
726+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
727727

728728
Imagine that you want to query for products, but only return products that
729729
cost more than ``19.99``, ordered from cheapest to most expensive. You can use
730-
Doctrine's ``QueryBuilder`` for this::
730+
Doctrine's native SQL-like language called DQL to make a query for this::
731731

732-
$repository = $this->getDoctrine()
733-
->getRepository('AppBundle:Product');
734-
735-
$query = $repository->createQueryBuilder('p')
736-
->where('p.price > :price')
737-
->setParameter('price', '19.99')
738-
->orderBy('p.price', 'ASC')
739-
->getQuery();
732+
$em = $this->getDoctrine()->getManager();
733+
$query = $em->createQuery(
734+
'SELECT p
735+
FROM AppBundle:Product p
736+
WHERE p.price > :price
737+
ORDER BY p.price ASC'
738+
)->setParameter('price', '19.99');
740739

741740
$products = $query->getResult();
741+
// to get just one result:
742+
// $product = $query->setMaxResults(1)->getOneOrNullResult();
742743

743-
The ``QueryBuilder`` object contains every method necessary to build your
744-
query. By calling the ``getQuery()`` method, the query builder returns a
745-
normal ``Query`` object, which can be used to get the result of the query.
744+
If you're comfortable with SQL, then DQL should feel very natural. The biggest
745+
difference is that you need to think in terms of "objects" instead of rows
746+
in a database. For this reason, you select *from* the ``AppBundle:Product``
747+
*object* (an optional shortcut for ``AppBundle\Entity\Product``) and then
748+
alias it as ``p``.
746749

747750
.. tip::
748751

@@ -751,40 +754,42 @@ normal ``Query`` object, which can be used to get the result of the query.
751754
(``:price`` in the example above) as it prevents SQL injection attacks.
752755

753756
The ``getResult()`` method returns an array of results. To get only one
754-
result, you can use ``getSingleResult()`` (which throws an exception if there
755-
is no result) or ``getOneOrNullResult()``::
757+
result, you can use ``getOneOrNullResult()``::
756758

757-
$product = $query->getOneOrNullResult();
759+
$product = $query->setMaxResults(1)->getOneOrNullResult();
758760

759-
For more information on Doctrine's Query Builder, consult Doctrine's
760-
`Query Builder`_ documentation.
761+
The DQL syntax is incredibly powerful, allowing you to easily join between
762+
entities (the topic of :ref:`relations <book-doctrine-relations>` will be
763+
covered later), group, etc. For more information, see the official
764+
`Doctrine Query Language`_ documentation.
761765

762-
Querying for Objects with DQL
763-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
766+
Querying for Objects Using Doctrine's Query Builder
767+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
764768

765-
Instead of using the ``QueryBuilder``, you can alternatively write the queries
766-
directly using DQL::
769+
Instead of writing a DQL string, you can alternatively use a helpful object called
770+
the ``QueryBuilder`` to build that string for you::
767771

768-
$em = $this->getDoctrine()->getManager();
769-
$query = $em->createQuery(
770-
'SELECT p
771-
FROM AppBundle:Product p
772-
WHERE p.price > :price
773-
ORDER BY p.price ASC'
774-
)->setParameter('price', '19.99');
772+
$repository = $this->getDoctrine()
773+
->getRepository('AppBundle:Product');
774+
775+
// createQueryBuilder automatically selects FROM AppBundle:Product
776+
// and aliases it to "p"
777+
$query = $repository->createQueryBuilder('p')
778+
->where('p.price > :price')
779+
->setParameter('price', '19.99')
780+
->orderBy('p.price', 'ASC')
781+
->getQuery();
775782

776783
$products = $query->getResult();
784+
// to get just one result:
785+
// $product = $query->setMaxResults(1)->getOneOrNullResult();
777786

778-
If you're comfortable with SQL, then DQL should feel very natural. The biggest
779-
difference is that you need to think in terms of "objects" instead of rows
780-
in a database. For this reason, you select *from* the ``AppBundle:Product``
781-
*object* and then alias it as ``p`` (as you see, this is equal to what you
782-
already did in the previous section).
787+
The ``QueryBuilder`` object contains every method necessary to build your
788+
query. By calling the ``getQuery()`` method, the query builder returns a
789+
normal ``Query`` object, which can be used to get the result of the query.
783790

784-
The DQL syntax is incredibly powerful, allowing you to easily join between
785-
entities (the topic of :ref:`relations <book-doctrine-relations>` will be
786-
covered later), group, etc. For more information, see the official
787-
`Doctrine Query Language`_ documentation.
791+
For more information on Doctrine's Query Builder, consult Doctrine's
792+
`Query Builder`_ documentation.
788793

789794
.. _book-doctrine-custom-repository-classes:
790795

conf.py

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
# adding PhpLexer
2424
from sphinx.highlighting import lexers
2525
from pygments.lexers.compiled import CLexer
26+
from pygments.lexers.special import TextLexer
27+
from pygments.lexers.text import RstLexer
2628
from pygments.lexers.web import PhpLexer
2729

2830
# -- General configuration -----------------------------------------------------
@@ -97,14 +99,18 @@
9799
# -- Settings for symfony doc extension ---------------------------------------------------
98100

99101
# enable highlighting for PHP code not between ``<?php ... ?>`` by default
102+
lexers['markdown'] = TextLexer()
100103
lexers['php'] = PhpLexer(startinline=True)
101104
lexers['php-annotations'] = PhpLexer(startinline=True)
102105
lexers['php-standalone'] = PhpLexer(startinline=True)
103106
lexers['php-symfony'] = PhpLexer(startinline=True)
107+
lexers['rst'] = RstLexer()
104108
lexers['varnish3'] = CLexer()
105109
lexers['varnish4'] = CLexer()
106110

107111
config_block = {
112+
'markdown': 'Markdown',
113+
'rst': 'reStructuredText',
108114
'varnish3': 'Varnish 3',
109115
'varnish4': 'Varnish 4'
110116
}

contributing/code/bc.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Our backwards Compatibility Promise
1+
Our Backwards Compatibility Promise
22
===================================
33

44
Ensuring smooth upgrades of your projects is our first priority. That's why

cookbook/bundles/best_practices.rst

+81-31
Original file line numberDiff line numberDiff line change
@@ -209,52 +209,102 @@ Installation Instructions
209209
In order to ease the installation of third-party bundles, consider using the
210210
following standardized instructions in your ``README.md`` file.
211211

212-
.. code-block:: text
212+
.. configuration-block::
213213

214-
Installation
215-
============
214+
.. code-block:: markdown
216215
217-
Step 1: Download the Bundle
218-
---------------------------
216+
Installation
217+
============
219218
220-
Open a command console, enter your project directory and execute the
221-
following command to download the latest stable version of this bundle:
219+
Step 1: Download the Bundle
220+
---------------------------
222221
223-
```bash
224-
$ composer require <package-name> "~1"
225-
```
222+
Open a command console, enter your project directory and execute the
223+
following command to download the latest stable version of this bundle:
226224
227-
This command requires you to have Composer installed globally, as explained
228-
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
229-
of the Composer documentation.
225+
```bash
226+
$ composer require <package-name> "~1"
227+
```
230228
231-
Step 2: Enable the Bundle
232-
-------------------------
229+
This command requires you to have Composer installed globally, as explained
230+
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
231+
of the Composer documentation.
233232
234-
Then, enable the bundle by adding the following line in the `app/AppKernel.php`
235-
file of your project:
233+
Step 2: Enable the Bundle
234+
-------------------------
236235
237-
```php
238-
<?php
239-
// app/AppKernel.php
236+
Then, enable the bundle by adding the following line in the `app/AppKernel.php`
237+
file of your project:
240238
241-
// ...
242-
class AppKernel extends Kernel
243-
{
244-
public function registerBundles()
239+
```php
240+
<?php
241+
// app/AppKernel.php
242+
243+
// ...
244+
class AppKernel extends Kernel
245245
{
246-
$bundles = array(
247-
// ...
246+
public function registerBundles()
247+
{
248+
$bundles = array(
249+
// ...
250+
251+
new <vendor>\<bundle-name>\<bundle-long-name>(),
252+
);
248253
249-
new <vendor>\<bundle-name>\<bundle-long-name>(),
250-
);
254+
// ...
255+
}
251256
252257
// ...
253258
}
259+
```
254260
255-
// ...
256-
}
257-
```
261+
.. code-block:: rst
262+
263+
Installation
264+
============
265+
266+
Step 1: Download the Bundle
267+
---------------------------
268+
269+
Open a command console, enter your project directory and execute the
270+
following command to download the latest stable version of this bundle:
271+
272+
.. code-block:: bash
273+
274+
$ composer require <package-name> "~1"
275+
276+
This command requires you to have Composer installed globally, as explained
277+
in the `installation chapter`_ of the Composer documentation.
278+
279+
Step 2: Enable the Bundle
280+
-------------------------
281+
282+
Then, enable the bundle by adding the following line in the ``app/AppKernel.php``
283+
file of your project:
284+
285+
.. code-block:: php
286+
287+
<?php
288+
// app/AppKernel.php
289+
290+
// ...
291+
class AppKernel extends Kernel
292+
{
293+
public function registerBundles()
294+
{
295+
$bundles = array(
296+
// ...
297+
298+
new <vendor>\<bundle-name>\<bundle-long-name>(),
299+
);
300+
301+
// ...
302+
}
303+
304+
// ...
305+
}
306+
307+
.. _`installation chapter`: https://getcomposer.org/doc/00-intro.md
258308
259309
This template assumes that your bundle is in its ``1.x`` version. If not, change
260310
the ``"~1"`` installation version accordingly (``"~2"``, ``"~3"``, etc.)

cookbook/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The Cookbook
3030
symfony1
3131
templating/index
3232
testing/index
33-
upgrading
33+
upgrade/index
3434
validation/index
3535
web_server/index
3636
web_services/index

cookbook/logging/channels_handlers.rst

+37-26
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,29 @@
44
How to Log Messages to different Files
55
======================================
66

7-
The Symfony Standard Edition contains a bunch of channels for logging: ``doctrine``,
8-
``event``, ``security`` and ``request``. Each channel corresponds to a logger
9-
service (``monolog.logger.XXX``) in the container and is injected to the
10-
concerned service. The purpose of channels is to be able to organize different
11-
types of log messages.
7+
The Symfony Framework organizes log messages into channels. By default, there
8+
are several channels, including ``doctrine``, ``event``, ``security``, ``request``
9+
and more. The channel is printed in the log message and can also be used
10+
to direct different channels to different places/files.
1211

1312
By default, Symfony logs every message into a single file (regardless of
1413
the channel).
1514

15+
.. note::
16+
17+
Each channel corresponds to a logger service (``monolog.logger.XXX``)
18+
in the container (use the ``container:debug`` command to see a full list)
19+
and those are injected into different services.
20+
21+
.. _logging-channel-handler:
22+
1623
Switching a Channel to a different Handler
1724
------------------------------------------
1825

19-
Now, suppose you want to log the ``doctrine`` channel to a different file.
20-
21-
To do so, just create a new handler and configure it like this:
26+
Now, suppose you want to log the ``security`` channel to a different file.
27+
To do this, just create a new handler and configure it to log only messages
28+
from the ``security`` channel. You might add this in ``config.yml`` to log
29+
in all environments, or just ``config_prod.yml`` to happen only in ``prod``:
2230

2331
.. configuration-block::
2432

@@ -27,14 +35,17 @@ To do so, just create a new handler and configure it like this:
2735
# app/config/config.yml
2836
monolog:
2937
handlers:
30-
main:
31-
type: stream
32-
path: /var/log/symfony.log
33-
channels: ["!doctrine"]
34-
doctrine:
38+
security:
39+
# log all messages (since debug is the lowest level)
40+
level: debug
3541
type: stream
36-
path: /var/log/doctrine.log
37-
channels: [doctrine]
42+
path: "%kernel.logs_dir%/security.log"
43+
channels: [security]
44+
45+
# an example of *not* logging security channel messages for this handler
46+
main:
47+
# ...
48+
# channels: ["!security"]
3849
3950
.. code-block:: xml
4051
@@ -48,15 +59,16 @@ To do so, just create a new handler and configure it like this:
4859
http://symfony.com/schema/dic/monolog/monolog-1.0.xsd"
4960
>
5061
<monolog:config>
51-
<monolog:handler name="main" type="stream" path="/var/log/symfony.log">
62+
<monolog:handler name="security" type="stream" path="%kernel.logs_dir%/security.log">
5263
<monolog:channels>
53-
<monolog:channel>!doctrine</monolog:channel>
64+
<monolog:channel>security</monolog:channel>
5465
</monolog:channels>
5566
</monolog:handler>
5667
57-
<monolog:handler name="doctrine" type="stream" path="/var/log/doctrine.log">
68+
<monolog:handler name="main" type="stream" path="%kernel.logs_dir%/main.log">
69+
<!-- ... -->
5870
<monolog:channels>
59-
<monolog:channel>doctrine</monolog:channel>
71+
<monolog:channel>!security</monolog:channel>
6072
</monolog:channels>
6173
</monolog:handler>
6274
</monolog:config>
@@ -67,18 +79,17 @@ To do so, just create a new handler and configure it like this:
6779
// app/config/config.php
6880
$container->loadFromExtension('monolog', array(
6981
'handlers' => array(
70-
'main' => array(
82+
'security' => array(
7183
'type' => 'stream',
72-
'path' => '/var/log/symfony.log',
84+
'path' => '%kernel.logs_dir%/security.log',
7385
'channels' => array(
74-
'!doctrine',
86+
'security',
7587
),
7688
),
77-
'doctrine' => array(
78-
'type' => 'stream',
79-
'path' => '/var/log/doctrine.log',
89+
'main' => array(
90+
// ...
8091
'channels' => array(
81-
'doctrine',
92+
'!security',
8293
),
8394
),
8495
),

0 commit comments

Comments
 (0)