Skip to content

[Reference] consistent & complete config examples #4160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 31 additions & 26 deletions reference/configuration/doctrine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -356,32 +356,37 @@ The following block shows all possible configuration keys:

.. code-block:: xml

<!-- xmlns:doctrine="http://symfony.com/schema/dic/doctrine" -->
<!-- xsi:schemaLocation="http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd"> -->

<doctrine:config>
<doctrine:dbal
name="default"
dbname="database"
host="localhost"
port="1234"
user="user"
password="secret"
driver="pdo_mysql"
driver-class="MyNamespace\MyDriverImpl"
path="%kernel.data_dir%/data.sqlite"
memory="true"
unix-socket="/tmp/mysql.sock"
wrapper-class="MyDoctrineDbalConnectionWrapper"
charset="UTF8"
logging="%kernel.debug%"
platform-service="MyOwnDatabasePlatformService"
>
<doctrine:option key="foo">bar</doctrine:option>
<doctrine:mapping-type name="enum">string</doctrine:mapping-type>
<doctrine:type name="custom">Acme\HelloBundle\MyCustomType</doctrine:type>
</doctrine:dbal>
</doctrine:config>
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:doctrine="http://symfony.com/schema/dic/doctrine"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">

<doctrine:config>
<doctrine:dbal
name="default"
dbname="database"
host="localhost"
port="1234"
user="user"
password="secret"
driver="pdo_mysql"
driver-class="MyNamespace\MyDriverImpl"
path="%kernel.data_dir%/data.sqlite"
memory="true"
unix-socket="/tmp/mysql.sock"
wrapper-class="MyDoctrineDbalConnectionWrapper"
charset="UTF8"
logging="%kernel.debug%"
platform-service="MyOwnDatabasePlatformService">

<doctrine:option key="foo">bar</doctrine:option>
<doctrine:mapping-type name="enum">string</doctrine:mapping-type>
<doctrine:type name="custom">Acme\HelloBundle\MyCustomType</doctrine:type>
</doctrine:dbal>
</doctrine:config>
</container>

If you want to configure multiple connections in YAML, put them under the
``connections`` key and give them a unique name:
Expand Down
59 changes: 45 additions & 14 deletions reference/configuration/framework.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,26 @@ have installed `PhpStormOpener`_ and use PHPstorm, you will do something like:

.. code-block:: yaml

# app/config/config.yml
framework:
ide: "pstorm://%%f:%%l"

.. code-block:: xml

<?xml version="1.0" charset="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/service"
xmlns:framework="http://symfony.com/schema/dic/symfony">
<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config ide="pstorm://%%f:%%l" />

</container>

.. code-block:: php

// app/config/config.php
$container->loadFromExtension('framework', array(
'ide' => 'pstorm://%%f:%%l',
));
Expand Down Expand Up @@ -155,17 +160,26 @@ see :doc:`/cookbook/request/load_balancer_reverse_proxy`.

.. code-block:: yaml

# app/config/config.yml
framework:
trusted_proxies: [192.0.0.1, 10.0.0.0/8]

.. code-block:: xml

<framework:config trusted-proxies="192.0.0.1, 10.0.0.0/8">
<!-- ... -->
</framework>
<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config trusted-proxies="192.0.0.1, 10.0.0.0/8" />
</container>

.. code-block:: php

// app/config/config.php
$container->loadFromExtension('framework', array(
'trusted_proxies' => array('192.0.0.1', '10.0.0.0/8'),
));
Expand Down Expand Up @@ -282,9 +296,17 @@ the value to ``null``:
.. code-block:: xml

<!-- app/config/config.xml -->
<framework:config>
<framework:session save-path="null" />
</framework:config>
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:session save-path="null" />
</framework:config>
</container>

.. code-block:: php

Expand Down Expand Up @@ -370,15 +392,24 @@ Now, activate the ``assets_version`` option:
.. code-block:: xml

<!-- app/config/config.xml -->
<framework:templating assets-version="v2">
<framework:engine id="twig" />
</framework:templating>
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:templating assets-version="v2">
<!-- ... -->
<framework:engine>twig</framework:engine>
</framework:templating>
</container>

.. code-block:: php

// app/config/config.php
$container->loadFromExtension('framework', array(
...,
// ...
'templating' => array(
'engines' => array('twig'),
'assets_version' => 'v2',
Expand Down
52 changes: 29 additions & 23 deletions reference/configuration/swiftmailer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,29 +200,35 @@ Full default Configuration

.. code-block:: xml

<swiftmailer:config
transport="smtp"
username=""
password=""
host="localhost"
port="false"
encryption=""
auth_mode=""
sender_address=""
delivery_address=""
disable_delivery=""
logging="%kernel.debug%"
>
<swiftmailer:spool
path="%kernel.cache_dir%/swiftmailer/spool"
type="file"
/>

<swiftmailer:antiflood
sleep="0"
threshold="99"
/>
</swiftmailer:config>
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:swiftmailer="http://symfony.com/schema/dic/swiftmailer"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/swiftmailer http://symfony.com/schema/dic/swiftmailer/swiftmailer-1.0.xsd">

<swiftmailer:config
transport="smtp"
username=""
password=""
host="localhost"
port="false"
encryption=""
auth_mode=""
sender_address=""
delivery_address=""
disable_delivery=""
logging="%kernel.debug%"
>
<swiftmailer:spool
path="%kernel.cache_dir%/swiftmailer/spool"
type="file" />

<swiftmailer:antiflood
sleep="0"
threshold="99" />
</swiftmailer:config>
</container>

Using multiple Mailers
----------------------
Expand Down
10 changes: 5 additions & 5 deletions reference/constraints/All.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ entry in that array:

.. code-block:: yaml

# src/UserBundle/Resources/config/validation.yml
# src/Acme/UserBundle/Resources/config/validation.yml
Acme\UserBundle\Entity\User:
properties:
favoriteColors:
Expand All @@ -37,15 +37,15 @@ entry in that array:

// src/Acme/UserBundle/Entity/User.php
namespace Acme\UserBundle\Entity;

use Symfony\Component\Validator\Constraints as Assert;

class User
{
/**
* @Assert\All({
* @Assert\NotBlank,
* @Assert\Length(min = "5")
* @Assert\Length(min = 5)
* })
*/
protected $favoriteColors = array();
Expand Down Expand Up @@ -77,7 +77,7 @@ entry in that array:

// src/Acme/UserBundle/Entity/User.php
namespace Acme\UserBundle\Entity;

use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;

Expand Down
2 changes: 1 addition & 1 deletion reference/constraints/Blank.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ of an ``Author`` class were blank, you could do the following:

.. code-block:: yaml

# src/BlogBundle/Resources/config/validation.yml
# src/Acme/BlogBundle/Resources/config/validation.yml
Acme\BlogBundle\Entity\Author:
properties:
firstName:
Expand Down
12 changes: 6 additions & 6 deletions reference/constraints/Callback.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,17 @@ those errors should be attributed::

// ...
use Symfony\Component\Validator\ExecutionContextInterface;

class Author
{
// ...
private $firstName;

public function isAuthorValid(ExecutionContextInterface $context)
{
// somehow you have an array of "fake names"
$fakeNames = array();

// check if the name is actually a fake name
if (in_array($this->getFirstName(), $fakeNames)) {
$context->addViolationAt('firstname', 'This name sounds totally fake!', array(), null);
Expand Down Expand Up @@ -155,7 +155,7 @@ process. Each method can be one of the following formats:

/**
* @Assert\Callback(methods={
* { "Acme\BlogBundle\MyStaticValidatorClass", "isAuthorValid"}
* { "Acme\BlogBundle\MyStaticValidatorClass", "isAuthorValid" }
* })
*/
class Author
Expand Down Expand Up @@ -208,10 +208,10 @@ process. Each method can be one of the following formats:
object being validated (e.g. ``Author``) as well as the ``ExecutionContextInterface``::

namespace Acme\BlogBundle;

use Symfony\Component\Validator\ExecutionContextInterface;
use Acme\BlogBundle\Entity\Author;

class MyStaticValidatorClass
{
public static function isAuthorValid(Author $author, ExecutionContextInterface $context)
Expand Down
15 changes: 8 additions & 7 deletions reference/constraints/Collection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ blank but is no longer than 100 characters in length, you would do the following
* @Assert\NotBlank(),
* @Assert\Length(
* max = 100,
* maxMessage = "Your bio is too long!"
* maxMessage = "Your short bio is too long!"
* )
* }
* },
Expand Down Expand Up @@ -117,7 +117,7 @@ blank but is no longer than 100 characters in length, you would do the following
<constraint name="NotBlank" />
<constraint name="Length">
<option name="max">100</option>
<option name="maxMessage">Your bio is too long!</option>
<option name="maxMessage">Your short bio is too long!</option>
</constraint>
</value>
</option>
Expand Down Expand Up @@ -146,7 +146,10 @@ blank but is no longer than 100 characters in length, you would do the following
'personal_email' => new Assert\Email(),
'lastName' => array(
new Assert\NotBlank(),
new Assert\Length(array("max" => 100)),
new Assert\Length(array(
'max' => 100,
'maxMessage' => 'Your short bio is too long!',
)),
),
),
'allowMissingFields' => true,
Expand Down Expand Up @@ -215,13 +218,11 @@ field is optional but must be a valid email if supplied, you can do the followin
* @Assert\Collection(
* fields={
* "personal_email" = @Assert\Required({@Assert\NotBlank, @Assert\Email}),
* "alternate_email" = @Assert\Optional(@Assert\Email),
* "alternate_email" = @Assert\Optional(@Assert\Email)
* }
* )
*/
protected $profileData = array(
'personal_email',
);
protected $profileData = array('personal_email');
}

.. code-block:: xml
Expand Down
4 changes: 2 additions & 2 deletions reference/constraints/Country.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Basic Usage

.. code-block:: yaml

# src/UserBundle/Resources/config/validation.yml
# src/Acme/UserBundle/Resources/config/validation.yml
Acme\UserBundle\Entity\User:
properties:
country:
Expand All @@ -36,7 +36,7 @@ Basic Usage
class User
{
/**
* @Assert\Country
* @Assert\Country()
*/
protected $country;
}
Expand Down
Loading