Skip to content

Commit 55db0cb

Browse files
committed
[Reference] consistent & complete config examples
1 parent 041105c commit 55db0cb

40 files changed

+576
-319
lines changed

reference/configuration/doctrine.rst

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

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
}

reference/constraints/Currency.rst

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ currency, you could do the following:
2626

2727
.. code-block:: yaml
2828
29-
# src/EcommerceBundle/Resources/config/validation.yml
29+
# src/Acme/EcommerceBundle/Resources/config/validation.yml
3030
Acme\EcommerceBundle\Entity\Order:
3131
properties:
3232
currency:
@@ -50,11 +50,17 @@ currency, you could do the following:
5050
.. code-block:: xml
5151
5252
<!-- src/Acme/EcommerceBundle/Resources/config/validation.xml -->
53-
<class name="Acme\EcommerceBundle\Entity\Order">
54-
<property name="currency">
55-
<constraint name="Currency" />
56-
</property>
57-
</class>
53+
<?xml version="1.0" encoding="UTF-8" ?>
54+
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
55+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
56+
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
57+
58+
<class name="Acme\EcommerceBundle\Entity\Order">
59+
<property name="currency">
60+
<constraint name="Currency" />
61+
</property>
62+
</class>
63+
</constraint-mapping>
5864
5965
.. code-block:: php
6066
@@ -82,4 +88,4 @@ message
8288

8389
This is the message that will be shown if the value is not a valid currency.
8490

85-
.. _`3-letter ISO 4217`: http://en.wikipedia.org/wiki/ISO_4217
91+
.. _`3-letter ISO 4217`: http://en.wikipedia.org/wiki/ISO_4217

reference/constraints/Email.rst

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

2424
.. code-block:: yaml
2525
26-
# src/BlogBundle/Resources/config/validation.yml
26+
# src/Acme/BlogBundle/Resources/config/validation.yml
2727
Acme\BlogBundle\Entity\Author:
2828
properties:
2929
email:
@@ -71,7 +71,7 @@ Basic Usage
7171
7272
// src/Acme/BlogBundle/Entity/Author.php
7373
namespace Acme\BlogBundle\Entity;
74-
74+
7575
use Symfony\Component\Validator\Mapping\ClassMetadata;
7676
use Symfony\Component\Validator\Constraints as Assert;
7777

reference/constraints/EqualTo.rst

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Validates that a value is equal to another value, defined in the options. To
88
force that a value is *not* equal, see :doc:`/reference/constraints/NotEqualTo`.
99

1010
.. caution::
11-
11+
1212
This constraint compares using ``==``, so ``3`` and ``"3"`` are considered
1313
equal. Use :doc:`/reference/constraints/IdenticalTo` to compare with
1414
``===``.
@@ -34,7 +34,7 @@ If you want to ensure that the ``age`` of a ``Person`` class is equal to
3434

3535
.. code-block:: yaml
3636
37-
# src/SocialBundle/Resources/config/validation.yml
37+
# src/Acme/SocialBundle/Resources/config/validation.yml
3838
Acme\SocialBundle\Entity\Person:
3939
properties:
4040
age:
@@ -61,13 +61,19 @@ If you want to ensure that the ``age`` of a ``Person`` class is equal to
6161
.. code-block:: xml
6262
6363
<!-- src/Acme/SocialBundle/Resources/config/validation.xml -->
64-
<class name="Acme\SocialBundle\Entity\Person">
65-
<property name="age">
66-
<constraint name="EqualTo">
67-
<option name="value">20</option>
68-
</constraint>
69-
</property>
70-
</class>
64+
<?xml version="1.0" encoding="UTF-8" ?>
65+
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
66+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
67+
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
68+
69+
<class name="Acme\SocialBundle\Entity\Person">
70+
<property name="age">
71+
<constraint name="EqualTo">
72+
<option name="value">20</option>
73+
</constraint>
74+
</property>
75+
</class>
76+
</constraint-mapping>
7177
7278
.. code-block:: php
7379

reference/constraints/False.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ method returns **false**:
4141

4242
.. code-block:: yaml
4343
44-
# src/BlogBundle/Resources/config/validation.yml
44+
# src/Acme/BlogBundle/Resources/config/validation.yml
4545
Acme\BlogBundle\Entity\Author
4646
getters:
4747
stateInvalid:
48-
- 'False':
48+
- False:
4949
message: You've entered an invalid state.
5050
5151
.. code-block:: php-annotations

reference/constraints/File.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ below a certain file size and a valid PDF, add the following:
7878
maxSize: 1024k
7979
mimeTypes: [application/pdf, application/x-pdf]
8080
mimeTypesMessage: Please upload a valid PDF
81-
8281
8382
.. code-block:: php-annotations
8483

0 commit comments

Comments
 (0)