Skip to content

Commit 3e6be25

Browse files
committed
Merge branch '2.0' into 2.1
Conflicts: cookbook/form/create_custom_field_type.rst cookbook/form/create_form_type_extension.rst cookbook/logging/monolog.rst cookbook/security/custom_authentication_provider.rst reference/constraints/Email.rst reference/constraints/Valid.rst
2 parents 725d107 + 35d7bc6 commit 3e6be25

32 files changed

+1374
-348
lines changed

book/doctrine.rst

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,44 @@ information. By convention, this information is usually configured in an
6464
The parameters defined in that file are referenced by the main configuration
6565
file when setting up Doctrine:
6666

67-
.. code-block:: yaml
68-
69-
# app/config/config.yml
70-
doctrine:
71-
dbal:
72-
driver: "%database_driver%"
73-
host: "%database_host%"
74-
dbname: "%database_name%"
75-
user: "%database_user%"
76-
password: "%database_password%"
67+
.. configuration-block::
68+
69+
.. code-block:: yaml
70+
71+
# app/config/config.yml
72+
doctrine:
73+
dbal:
74+
driver: "%database_driver%"
75+
host: "%database_host%"
76+
dbname: "%database_name%"
77+
user: "%database_user%"
78+
password: "%database_password%"
79+
80+
.. code-block:: xml
81+
82+
<!-- app/config/config.xml -->
83+
<doctrine:config>
84+
<doctrine:dbal
85+
driver="%database_driver%"
86+
host="%database_host%"
87+
dbname="%database_name%"
88+
user="%database_user%"
89+
password="%database_password%"
90+
>
91+
</doctrine:config>
92+
93+
.. code-block:: php
94+
95+
// app/config/config.php
96+
$configuration->loadFromExtension('doctrine', array(
97+
'dbal' => array(
98+
'driver' => '%database_driver%',
99+
'host' => '%database_host%',
100+
'dbname' => '%database_name%',
101+
'user' => '%database_user%',
102+
'password' => '%database_password%',
103+
),
104+
));
77105
78106
By separating the database information into a separate file, you can
79107
easily keep different versions of the file on each server. You can also
@@ -911,6 +939,24 @@ To relate the ``Category`` and ``Product`` entities, start by creating a
911939
mappedBy: category
912940
# don't forget to init the collection in entity __construct() method
913941
942+
.. code-block:: xml
943+
944+
<!-- src/Acme/StoreBundle/Resources/config/doctrine/Category.orm.xml -->
945+
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
946+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
947+
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
948+
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
949+
950+
<entity name="Acme\StoreBundle\Entity\Category">
951+
<!-- ... -->
952+
<one-to-many field="products"
953+
target-entity="product"
954+
mapped-by="category"
955+
/>
956+
957+
<!-- don't forget to init the collection in entity __construct() method -->
958+
</entity>
959+
</doctrine-mapping>
914960
915961
First, since a ``Category`` object will relate to many ``Product`` objects,
916962
a ``products`` array property is added to hold those ``Product`` objects.
@@ -968,6 +1014,28 @@ object, you'll want to add a ``$category`` property to the ``Product`` class:
9681014
name: category_id
9691015
referencedColumnName: id
9701016
1017+
.. code-block:: xml
1018+
1019+
<!-- src/Acme/StoreBundle/Resources/config/doctrine/Product.orm.xml -->
1020+
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
1021+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1022+
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
1023+
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
1024+
1025+
<entity name="Acme\StoreBundle\Entity\Product">
1026+
<!-- ... -->
1027+
<many-to-one field="category"
1028+
target-entity="products"
1029+
join-column="category"
1030+
>
1031+
<join-column
1032+
name="category_id"
1033+
referenced-column-name="id"
1034+
/>
1035+
</many-to-one>
1036+
</entity>
1037+
</doctrine-mapping>
1038+
9711039
Finally, now that you've added a new property to both the ``Category`` and
9721040
``Product`` classes, tell Doctrine to generate the missing getter and setter
9731041
methods for you:
@@ -1389,6 +1457,21 @@ and ``nullable``. Take a few examples:
13891457
length: 150
13901458
unique: true
13911459
1460+
.. code-block:: xml
1461+
1462+
<!--
1463+
A string field length 255 that cannot be null
1464+
(reflecting the default values for the "length" and *nullable* options)
1465+
type attribute is necessary in yaml definitions
1466+
-->
1467+
<field name="name" type="string" />
1468+
<field name="email"
1469+
type="string"
1470+
column="email_address"
1471+
length="150"
1472+
unique="true"
1473+
/>
1474+
13921475
.. note::
13931476

13941477
There are a few more options not listed here. For more details, see

cookbook/configuration/apache_router.rst

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,33 @@ Change Router Configuration Parameters
1313
To dump Apache routes you must first tweak some configuration parameters to tell
1414
Symfony2 to use the ``ApacheUrlMatcher`` instead of the default one:
1515

16-
.. code-block:: yaml
16+
.. configuration-block::
1717

18-
# app/config/config_prod.yml
19-
parameters:
20-
router.options.matcher.cache_class: ~ # disable router cache
21-
router.options.matcher_class: Symfony\Component\Routing\Matcher\ApacheUrlMatcher
18+
.. code-block:: yaml
19+
20+
# app/config/config_prod.yml
21+
parameters:
22+
router.options.matcher.cache_class: ~ # disable router cache
23+
router.options.matcher_class: Symfony\Component\Routing\Matcher\ApacheUrlMatcher
24+
25+
.. code-block:: xml
26+
27+
<!-- app/config/config_prod.xml -->
28+
<parameters>
29+
<parameter key="router.options.matcher.cache_class">null</parameter> <!-- disable router cache -->
30+
<parameter key="router.options.matcher_class">
31+
Symfony\Component\Routing\Matcher\ApacheUrlMatcher
32+
</parameter>
33+
</parameters>
34+
35+
.. code-block:: php
36+
37+
// app/config/config_prod.php
38+
$container->setParameter('router.options.matcher.cache_class', null); // disable router cache
39+
$container->setParameter(
40+
'router.options.matcher_class',
41+
'Symfony\Component\Routing\Matcher\ApacheUrlMatcher'
42+
);
2243
2344
.. tip::
2445

@@ -33,13 +54,28 @@ Generating mod_rewrite rules
3354

3455
To test that it's working, let's create a very basic route for demo bundle:
3556

36-
.. code-block:: yaml
57+
.. configuration-block::
58+
59+
.. code-block:: yaml
60+
61+
# app/config/routing.yml
62+
hello:
63+
pattern: /hello/{name}
64+
defaults: { _controller: AcmeDemoBundle:Demo:hello }
65+
66+
.. code-block:: xml
67+
68+
<!-- app/config/routing.xml -->
69+
<route id="hello" pattern="/hello/{name}">
70+
<default key="_controller">AcmeDemoBundle:Demo:hello</default>
71+
</route>
3772
38-
# app/config/routing.yml
39-
hello:
40-
pattern: /hello/{name}
41-
defaults: { _controller: AcmeDemoBundle:Demo:hello }
73+
.. code-block:: php
4274
75+
// app/config/routing.php
76+
$collection->add('hello', new Route('/hello/{name}', array(
77+
'_controller' => 'AcmeDemoBundle:Demo:hello',
78+
)));
4379
4480
Now generate **url_rewrite** rules:
4581

cookbook/configuration/external_parameters.rst

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,19 @@ key, and define the type as ``constant``.
119119
This only works for XML configuration. If you're *not* using XML, simply
120120
import an XML file to take advantage of this functionality:
121121

122-
.. code-block:: yaml
122+
.. configuration-block::
123+
124+
.. code-block:: yaml
125+
126+
# app/config/config.yml
127+
imports:
128+
- { resource: parameters.xml }
129+
130+
.. code-block:: php
131+
132+
// app/config/config.php
133+
$loader->import('parameters.xml');
123134
124-
# app/config/config.yml
125-
imports:
126-
- { resource: parameters.xml }
127135
128136
Miscellaneous Configuration
129137
---------------------------

cookbook/configuration/override_dir_structure.rst

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,33 @@ may need to modify the paths inside these files::
105105
If you use the AsseticBundle you need to configure this, so it can use
106106
the correct ``web`` directory:
107107

108-
.. code-block:: yaml
108+
.. configuration-block::
109109

110-
# app/config/config.yml
110+
.. code-block:: yaml
111+
112+
# app/config/config.yml
111113
112-
# ...
113-
assetic:
114114
# ...
115-
read_from: "%kernel.root_dir%/../../public_html"
115+
assetic:
116+
# ...
117+
read_from: "%kernel.root_dir%/../../public_html"
118+
119+
.. code-block:: xml
120+
121+
<!-- app/config/config.xml -->
122+
123+
<!-- ... -->
124+
<assetic:config read-from="%kernel.root_dir%/../../public_html" />
125+
126+
.. code-block:: php
127+
128+
// app/config/config.php
129+
130+
// ...
131+
$container->loadFromExtension('assetic', array(
132+
// ...
133+
'read_from' => '%kernel.root_dir%/../../public_html',
134+
));
116135
117136
Now you just need to dump the assets again and your application should
118137
work:

cookbook/doctrine/dbal.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ To get started, configure the database connection parameters:
3838
3939
.. code-block:: xml
4040
41-
// app/config/config.xml
41+
<!-- app/config/config.xml -->
4242
<doctrine:config>
4343
<doctrine:dbal
4444
name="default"
@@ -64,9 +64,7 @@ To get started, configure the database connection parameters:
6464
For full DBAL configuration options, see :ref:`reference-dbal-configuration`.
6565

6666
You can then access the Doctrine DBAL connection by accessing the
67-
``database_connection`` service:
68-
69-
.. code-block:: php
67+
``database_connection`` service::
7068

7169
class UserController extends Controller
7270
{
@@ -186,4 +184,4 @@ mapping type:
186184
.. _`PDO`: http://www.php.net/pdo
187185
.. _`Doctrine`: http://www.doctrine-project.org
188186
.. _`DBAL Documentation`: http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/index.html
189-
.. _`Custom Mapping Types`: http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#custom-mapping-types
187+
.. _`Custom Mapping Types`: http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#custom-mapping-types

cookbook/doctrine/event_listeners_subscribers.rst

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,44 @@ managers that use this connection.
7777
</services>
7878
</container>
7979
80+
.. code-block:: php
81+
82+
use Symfony\Component\DependencyInjection\Definition;
83+
84+
$container->loadFromExtension('doctrine', array(
85+
'dbal' => array(
86+
'default_connection' => 'default',
87+
'connections' => array(
88+
'default' => array(
89+
'driver' => 'pdo_sqlite',
90+
'memory' => true,
91+
),
92+
),
93+
),
94+
));
95+
96+
$container
97+
->setDefinition(
98+
'my.listener',
99+
new Definition('Acme\SearchBundle\EventListener\SearchIndexer')
100+
)
101+
->addTag('doctrine.event_listener', array('event' => 'postPersist'))
102+
;
103+
$container
104+
->setDefinition(
105+
'my.listener2',
106+
new Definition('Acme\SearchBundle\EventListener\SearchIndexer2')
107+
)
108+
->addTag('doctrine.event_listener', array('event' => 'postPersist', 'connection' => 'default'))
109+
;
110+
$container
111+
->setDefinition(
112+
'my.subscriber',
113+
new Definition('Acme\SearchBundle\EventListener\SearchIndexerSubscriber')
114+
)
115+
->addTag('doctrine.event_subscriber', array('connection' => 'default'))
116+
;
117+
80118
Creating the Listener Class
81119
---------------------------
82120

@@ -99,7 +137,7 @@ a ``postPersist`` method, which will be called when the event is thrown::
99137

100138
// perhaps you only want to act on some "Product" entity
101139
if ($entity instanceof Product) {
102-
// do something with the Product
140+
// ... do something with the Product
103141
}
104142
}
105143
}

0 commit comments

Comments
 (0)