Skip to content

Commit e9d317a

Browse files
committed
minor #4160 [Reference] consistent & complete config examples (xabbuh)
This PR was merged into the 2.3 branch. Discussion ---------- [Reference] consistent & complete config examples | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | all | Fixed tickets | Make configuration examples in the reference section consistent throughout the different configuration formats. Also fixing several syntax issues. This follow #4114 and #4129. Commits ------- 01dc25c [Reference] consistent & complete config examples
2 parents 4882b99 + 01dc25c commit e9d317a

Some content is hidden

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

41 files changed

+619
-331
lines changed

reference/configuration/doctrine.rst

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -359,32 +359,37 @@ The following block shows all possible configuration keys:
359359
360360
.. code-block:: xml
361361
362-
<!-- xmlns:doctrine="http://symfony.com/schema/dic/doctrine" -->
363-
<!-- xsi:schemaLocation="http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd"> -->
364-
365-
<doctrine:config>
366-
<doctrine:dbal
367-
name="default"
368-
dbname="database"
369-
host="localhost"
370-
port="1234"
371-
user="user"
372-
password="secret"
373-
driver="pdo_mysql"
374-
driver-class="MyNamespace\MyDriverImpl"
375-
path="%kernel.data_dir%/data.sqlite"
376-
memory="true"
377-
unix-socket="/tmp/mysql.sock"
378-
wrapper-class="MyDoctrineDbalConnectionWrapper"
379-
charset="UTF8"
380-
logging="%kernel.debug%"
381-
platform-service="MyOwnDatabasePlatformService"
382-
>
383-
<doctrine:option key="foo">bar</doctrine:option>
384-
<doctrine:mapping-type name="enum">string</doctrine:mapping-type>
385-
<doctrine:type name="custom">Acme\HelloBundle\MyCustomType</doctrine:type>
386-
</doctrine:dbal>
387-
</doctrine:config>
362+
<?xml version="1.0" encoding="UTF-8" ?>
363+
<container xmlns="http://symfony.com/schema/dic/services"
364+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
365+
xmlns:doctrine="http://symfony.com/schema/dic/doctrine"
366+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
367+
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
368+
369+
<doctrine:config>
370+
<doctrine:dbal
371+
name="default"
372+
dbname="database"
373+
host="localhost"
374+
port="1234"
375+
user="user"
376+
password="secret"
377+
driver="pdo_mysql"
378+
driver-class="MyNamespace\MyDriverImpl"
379+
path="%kernel.data_dir%/data.sqlite"
380+
memory="true"
381+
unix-socket="/tmp/mysql.sock"
382+
wrapper-class="MyDoctrineDbalConnectionWrapper"
383+
charset="UTF8"
384+
logging="%kernel.debug%"
385+
platform-service="MyOwnDatabasePlatformService">
386+
387+
<doctrine:option key="foo">bar</doctrine:option>
388+
<doctrine:mapping-type name="enum">string</doctrine:mapping-type>
389+
<doctrine:type name="custom">Acme\HelloBundle\MyCustomType</doctrine:type>
390+
</doctrine:dbal>
391+
</doctrine:config>
392+
</container>
388393
389394
If you want to configure multiple connections in YAML, put them under the
390395
``connections`` key and give them a unique name:

reference/configuration/framework.rst

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,26 @@ have installed `PhpStormOpener`_ and use PHPstorm, you will do something like:
101101

102102
.. code-block:: yaml
103103
104+
# app/config/config.yml
104105
framework:
105106
ide: "pstorm://%%f:%%l"
106107
107108
.. code-block:: xml
108109
109-
<?xml version="1.0" charset="UTF-8" ?>
110-
<container xmlns="http://symfony.com/schema/dic/service"
111-
xmlns:framework="http://symfony.com/schema/dic/symfony">
110+
<!-- app/config/config.xml -->
111+
<?xml version="1.0" encoding="UTF-8" ?>
112+
<container xmlns="http://symfony.com/schema/dic/services"
113+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
114+
xmlns:framework="http://symfony.com/schema/dic/symfony"
115+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
116+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
112117
113118
<framework:config ide="pstorm://%%f:%%l" />
114-
115119
</container>
116120
117121
.. code-block:: php
118122
123+
// app/config/config.php
119124
$container->loadFromExtension('framework', array(
120125
'ide' => 'pstorm://%%f:%%l',
121126
));
@@ -155,17 +160,26 @@ see :doc:`/cookbook/request/load_balancer_reverse_proxy`.
155160

156161
.. code-block:: yaml
157162
163+
# app/config/config.yml
158164
framework:
159165
trusted_proxies: [192.0.0.1, 10.0.0.0/8]
160166
161167
.. code-block:: xml
162168
163-
<framework:config trusted-proxies="192.0.0.1, 10.0.0.0/8">
164-
<!-- ... -->
165-
</framework>
169+
<!-- app/config/config.xml -->
170+
<?xml version="1.0" encoding="UTF-8" ?>
171+
<container xmlns="http://symfony.com/schema/dic/services"
172+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
173+
xmlns:framework="http://symfony.com/schema/dic/symfony"
174+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
175+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
176+
177+
<framework:config trusted-proxies="192.0.0.1, 10.0.0.0/8" />
178+
</container>
166179
167180
.. code-block:: php
168181
182+
// app/config/config.php
169183
$container->loadFromExtension('framework', array(
170184
'trusted_proxies' => array('192.0.0.1', '10.0.0.0/8'),
171185
));
@@ -282,9 +296,17 @@ the value to ``null``:
282296
.. code-block:: xml
283297
284298
<!-- app/config/config.xml -->
285-
<framework:config>
286-
<framework:session save-path="null" />
287-
</framework:config>
299+
<?xml version="1.0" encoding="UTF-8" ?>
300+
<container xmlns="http://symfony.com/schema/dic/services"
301+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
302+
xmlns:framework="http://symfony.com/schema/dic/symfony"
303+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
304+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
305+
306+
<framework:config>
307+
<framework:session save-path="null" />
308+
</framework:config>
309+
</container>
288310
289311
.. code-block:: php
290312
@@ -370,15 +392,24 @@ Now, activate the ``assets_version`` option:
370392
.. code-block:: xml
371393
372394
<!-- app/config/config.xml -->
373-
<framework:templating assets-version="v2">
374-
<framework:engine id="twig" />
375-
</framework:templating>
395+
<?xml version="1.0" encoding="UTF-8" ?>
396+
<container xmlns="http://symfony.com/schema/dic/services"
397+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
398+
xmlns:framework="http://symfony.com/schema/dic/symfony"
399+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
400+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
401+
402+
<framework:templating assets-version="v2">
403+
<!-- ... -->
404+
<framework:engine>twig</framework:engine>
405+
</framework:templating>
406+
</container>
376407
377408
.. code-block:: php
378409
379410
// app/config/config.php
380411
$container->loadFromExtension('framework', array(
381-
...,
412+
// ...
382413
'templating' => array(
383414
'engines' => array('twig'),
384415
'assets_version' => 'v2',

reference/configuration/swiftmailer.rst

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -200,29 +200,35 @@ Full default Configuration
200200
201201
.. code-block:: xml
202202
203-
<swiftmailer:config
204-
transport="smtp"
205-
username=""
206-
password=""
207-
host="localhost"
208-
port="false"
209-
encryption=""
210-
auth_mode=""
211-
sender_address=""
212-
delivery_address=""
213-
disable_delivery=""
214-
logging="%kernel.debug%"
215-
>
216-
<swiftmailer:spool
217-
path="%kernel.cache_dir%/swiftmailer/spool"
218-
type="file"
219-
/>
220-
221-
<swiftmailer:antiflood
222-
sleep="0"
223-
threshold="99"
224-
/>
225-
</swiftmailer:config>
203+
<?xml version="1.0" encoding="UTF-8" ?>
204+
<container xmlns="http://symfony.com/schema/dic/services"
205+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
206+
xmlns:swiftmailer="http://symfony.com/schema/dic/swiftmailer"
207+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
208+
http://symfony.com/schema/dic/swiftmailer http://symfony.com/schema/dic/swiftmailer/swiftmailer-1.0.xsd">
209+
210+
<swiftmailer:config
211+
transport="smtp"
212+
username=""
213+
password=""
214+
host="localhost"
215+
port="false"
216+
encryption=""
217+
auth_mode=""
218+
sender_address=""
219+
delivery_address=""
220+
disable_delivery=""
221+
logging="%kernel.debug%"
222+
>
223+
<swiftmailer:spool
224+
path="%kernel.cache_dir%/swiftmailer/spool"
225+
type="file" />
226+
227+
<swiftmailer:antiflood
228+
sleep="0"
229+
threshold="99" />
230+
</swiftmailer:config>
231+
</container>
226232
227233
Using multiple Mailers
228234
----------------------

reference/constraints/All.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ entry in that array:
2424

2525
.. code-block:: yaml
2626
27-
# src/UserBundle/Resources/config/validation.yml
27+
# src/Acme/UserBundle/Resources/config/validation.yml
2828
Acme\UserBundle\Entity\User:
2929
properties:
3030
favoriteColors:
@@ -37,15 +37,15 @@ entry in that array:
3737
3838
// src/Acme/UserBundle/Entity/User.php
3939
namespace Acme\UserBundle\Entity;
40-
40+
4141
use Symfony\Component\Validator\Constraints as Assert;
42-
42+
4343
class User
4444
{
4545
/**
4646
* @Assert\All({
4747
* @Assert\NotBlank,
48-
* @Assert\Length(min = "5")
48+
* @Assert\Length(min = 5)
4949
* })
5050
*/
5151
protected $favoriteColors = array();
@@ -77,7 +77,7 @@ entry in that array:
7777
7878
// src/Acme/UserBundle/Entity/User.php
7979
namespace Acme\UserBundle\Entity;
80-
80+
8181
use Symfony\Component\Validator\Mapping\ClassMetadata;
8282
use Symfony\Component\Validator\Constraints as Assert;
8383

reference/constraints/Blank.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ of an ``Author`` class were blank, you could do the following:
2626

2727
.. code-block:: yaml
2828
29-
# src/BlogBundle/Resources/config/validation.yml
29+
# src/Acme/BlogBundle/Resources/config/validation.yml
3030
Acme\BlogBundle\Entity\Author:
3131
properties:
3232
firstName:

reference/constraints/Callback.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,17 @@ those errors should be attributed::
9898

9999
// ...
100100
use Symfony\Component\Validator\ExecutionContextInterface;
101-
101+
102102
class Author
103103
{
104104
// ...
105105
private $firstName;
106-
106+
107107
public function isAuthorValid(ExecutionContextInterface $context)
108108
{
109109
// somehow you have an array of "fake names"
110110
$fakeNames = array();
111-
111+
112112
// check if the name is actually a fake name
113113
if (in_array($this->getFirstName(), $fakeNames)) {
114114
$context->addViolationAt('firstname', 'This name sounds totally fake!', array(), null);
@@ -155,7 +155,7 @@ process. Each method can be one of the following formats:
155155
156156
/**
157157
* @Assert\Callback(methods={
158-
* { "Acme\BlogBundle\MyStaticValidatorClass", "isAuthorValid"}
158+
* { "Acme\BlogBundle\MyStaticValidatorClass", "isAuthorValid" }
159159
* })
160160
*/
161161
class Author
@@ -208,10 +208,10 @@ process. Each method can be one of the following formats:
208208
object being validated (e.g. ``Author``) as well as the ``ExecutionContextInterface``::
209209

210210
namespace Acme\BlogBundle;
211-
211+
212212
use Symfony\Component\Validator\ExecutionContextInterface;
213213
use Acme\BlogBundle\Entity\Author;
214-
214+
215215
class MyStaticValidatorClass
216216
{
217217
public static function isAuthorValid(Author $author, ExecutionContextInterface $context)

reference/constraints/Collection.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ blank but is no longer than 100 characters in length, you would do the following
8585
* @Assert\NotBlank(),
8686
* @Assert\Length(
8787
* max = 100,
88-
* maxMessage = "Your bio is too long!"
88+
* maxMessage = "Your short bio is too long!"
8989
* )
9090
* }
9191
* },
@@ -117,7 +117,7 @@ blank but is no longer than 100 characters in length, you would do the following
117117
<constraint name="NotBlank" />
118118
<constraint name="Length">
119119
<option name="max">100</option>
120-
<option name="maxMessage">Your bio is too long!</option>
120+
<option name="maxMessage">Your short bio is too long!</option>
121121
</constraint>
122122
</value>
123123
</option>
@@ -146,7 +146,10 @@ blank but is no longer than 100 characters in length, you would do the following
146146
'personal_email' => new Assert\Email(),
147147
'lastName' => array(
148148
new Assert\NotBlank(),
149-
new Assert\Length(array("max" => 100)),
149+
new Assert\Length(array(
150+
'max' => 100,
151+
'maxMessage' => 'Your short bio is too long!',
152+
)),
150153
),
151154
),
152155
'allowMissingFields' => true,
@@ -215,13 +218,11 @@ field is optional but must be a valid email if supplied, you can do the followin
215218
* @Assert\Collection(
216219
* fields={
217220
* "personal_email" = @Assert\Required({@Assert\NotBlank, @Assert\Email}),
218-
* "alternate_email" = @Assert\Optional(@Assert\Email),
221+
* "alternate_email" = @Assert\Optional(@Assert\Email)
219222
* }
220223
* )
221224
*/
222-
protected $profileData = array(
223-
'personal_email',
224-
);
225+
protected $profileData = array('personal_email');
225226
}
226227
227228
.. code-block:: xml

reference/constraints/Country.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Basic Usage
2020

2121
.. code-block:: yaml
2222
23-
# src/UserBundle/Resources/config/validation.yml
23+
# src/Acme/UserBundle/Resources/config/validation.yml
2424
Acme\UserBundle\Entity\User:
2525
properties:
2626
country:
@@ -36,7 +36,7 @@ Basic Usage
3636
class User
3737
{
3838
/**
39-
* @Assert\Country
39+
* @Assert\Country()
4040
*/
4141
protected $country;
4242
}

0 commit comments

Comments
 (0)