Skip to content

Commit

Permalink
Updated Constraint reference with best practices
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Aug 20, 2015
1 parent dd20bbb commit fe7aa8b
Show file tree
Hide file tree
Showing 43 changed files with 450 additions and 450 deletions.
16 changes: 8 additions & 8 deletions reference/constraints/All.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ entry in that array:

.. code-block:: php-annotations
// src/Acme/UserBundle/Entity/User.php
namespace Acme\UserBundle\Entity;
// src/AppBundle/Entity/User.php
namespace AppBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
Expand All @@ -42,8 +42,8 @@ entry in that array:
.. code-block:: yaml
# src/Acme/UserBundle/Resources/config/validation.yml
Acme\UserBundle\Entity\User:
# src/AppBundle/Resources/config/validation.yml
AppBundle\Entity\User:
properties:
favoriteColors:
- All:
Expand All @@ -53,13 +53,13 @@ entry in that array:
.. code-block:: xml
<!-- src/Acme/UserBundle/Resources/config/validation.xml -->
<!-- src/AppBundle/Resources/config/validation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
<class name="Acme\UserBundle\Entity\User">
<class name="AppBundle\Entity\User">
<property name="favoriteColors">
<constraint name="All">
<option name="constraints">
Expand All @@ -75,8 +75,8 @@ entry in that array:
.. code-block:: php
// src/Acme/UserBundle/Entity/User.php
namespace Acme\UserBundle\Entity;
// src/AppBundle/Entity/User.php
namespace AppBundle\Entity;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;
Expand Down
16 changes: 8 additions & 8 deletions reference/constraints/Blank.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ of an ``Author`` class were blank, you could do the following:

.. code-block:: php-annotations
// src/Acme/BlogBundle/Entity/Author.php
namespace Acme\BlogBundle\Entity;
// src/AppBundle/Entity/Author.php
namespace AppBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
Expand All @@ -41,21 +41,21 @@ of an ``Author`` class were blank, you could do the following:
.. code-block:: yaml
# src/Acme/BlogBundle/Resources/config/validation.yml
Acme\BlogBundle\Entity\Author:
# src/AppBundle/Resources/config/validation.yml
AppBundle\Entity\Author:
properties:
firstName:
- Blank: ~
.. code-block:: xml
<!-- src/Acme/BlogBundle/Resources/config/validation.xml -->
<!-- src/AppBundle/Resources/config/validation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
<class name="Acme\BlogBundle\Entity\Author">
<class name="AppBundle\Entity\Author">
<property name="firstName">
<constraint name="Blank" />
</property>
Expand All @@ -64,8 +64,8 @@ of an ``Author`` class were blank, you could do the following:
.. code-block:: php
// src/Acme/BlogBundle/Entity/Author.php
namespace Acme\BlogBundle\Entity;
// src/AppBundle/Entity/Author.php
namespace AppBundle\Entity;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;
Expand Down
42 changes: 21 additions & 21 deletions reference/constraints/Callback.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ Setup

.. code-block:: php-annotations
// src/Acme/BlogBundle/Entity/Author.php
namespace Acme\BlogBundle\Entity;
// src/AppBundle/Entity/Author.php
namespace AppBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
Expand All @@ -48,21 +48,21 @@ Setup
.. code-block:: yaml
# src/Acme/BlogBundle/Resources/config/validation.yml
Acme\BlogBundle\Entity\Author:
# src/AppBundle/Resources/config/validation.yml
AppBundle\Entity\Author:
constraints:
- Callback:
methods: [isAuthorValid]
.. code-block:: xml
<!-- src/Acme/BlogBundle/Resources/config/validation.xml -->
<!-- src/AppBundle/Resources/config/validation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
<class name="Acme\BlogBundle\Entity\Author">
<class name="AppBundle\Entity\Author">
<constraint name="Callback">
<option name="methods">
<value>isAuthorValid</value>
Expand All @@ -73,8 +73,8 @@ Setup
.. code-block:: php
// src/Acme/BlogBundle/Entity/Author.php
namespace Acme\BlogBundle\Entity;
// src/AppBundle/Entity/Author.php
namespace AppBundle\Entity;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;
Expand Down Expand Up @@ -147,12 +147,12 @@ process. Each method can be one of the following formats:

.. code-block:: php-annotations
// src/Acme/BlogBundle/Entity/Author.php
// src/AppBundle/Entity/Author.php
use Symfony\Component\Validator\Constraints as Assert;
/**
* @Assert\Callback(methods={
* { "Acme\BlogBundle\MyStaticValidatorClass", "isAuthorValid" }
* { "AppBundle\MyStaticValidatorClass", "isAuthorValid" }
* })
*/
class Author
Expand All @@ -161,26 +161,26 @@ process. Each method can be one of the following formats:
.. code-block:: yaml
# src/Acme/BlogBundle/Resources/config/validation.yml
Acme\BlogBundle\Entity\Author:
# src/AppBundle/Resources/config/validation.yml
AppBundle\Entity\Author:
constraints:
- Callback:
methods:
- [Acme\BlogBundle\MyStaticValidatorClass, isAuthorValid]
- [AppBundle\MyStaticValidatorClass, isAuthorValid]
.. code-block:: xml
<!-- src/Acme/BlogBundle/Resources/config/validation.xml -->
<!-- src/AppBundle/Resources/config/validation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
<class name="Acme\BlogBundle\Entity\Author">
<class name="AppBundle\Entity\Author">
<constraint name="Callback">
<option name="methods">
<value>
<value>Acme\BlogBundle\MyStaticValidatorClass</value>
<value>AppBundle\MyStaticValidatorClass</value>
<value>isAuthorValid</value>
</value>
</option>
Expand All @@ -190,7 +190,7 @@ process. Each method can be one of the following formats:
.. code-block:: php
// src/Acme/BlogBundle/Entity/Author.php
// src/AppBundle/Entity/Author.php
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints\Callback;
Expand All @@ -204,7 +204,7 @@ process. Each method can be one of the following formats:
$metadata->addConstraint(new Callback(array(
'methods' => array(
array(
'Acme\BlogBundle\MyStaticValidatorClass',
'AppBundle\MyStaticValidatorClass',
'isAuthorValid',
),
),
Expand All @@ -213,14 +213,14 @@ process. Each method can be one of the following formats:
}
In this case, the static method ``isAuthorValid`` will be called on
the ``Acme\BlogBundle\MyStaticValidatorClass`` class. It's passed both
the ``AppBundle\MyStaticValidatorClass`` class. It's passed both
the original object being validated (e.g. ``Author``) as well as the
``ExecutionContextInterface``::

namespace Acme\BlogBundle;
namespace AppBundle;

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

class MyStaticValidatorClass
{
Expand Down
16 changes: 8 additions & 8 deletions reference/constraints/CardScheme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ on an object that will contain a credit card number.

.. code-block:: php-annotations
// src/Acme/SubscriptionBundle/Entity/Transaction.php
namespace Acme\SubscriptionBundle\Entity\Transaction;
// src/AppBundle/Entity/Transaction.php
namespace AppBundle\Entity\Transaction;
use Symfony\Component\Validator\Constraints as Assert;
Expand All @@ -47,8 +47,8 @@ on an object that will contain a credit card number.
.. code-block:: yaml
# src/Acme/SubscriptionBundle/Resources/config/validation.yml
Acme\SubscriptionBundle\Entity\Transaction:
# src/AppBundle/Resources/config/validation.yml
AppBundle\Entity\Transaction:
properties:
cardNumber:
- CardScheme:
Expand All @@ -57,13 +57,13 @@ on an object that will contain a credit card number.
.. code-block:: xml
<!-- src/Acme/SubscriptionBundle/Resources/config/validation.xml -->
<!-- src/AppBundle/Resources/config/validation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
<class name="Acme\SubscriptionBundle\Entity\Transaction">
<class name="AppBundle\Entity\Transaction">
<property name="cardNumber">
<constraint name="CardScheme">
<option name="schemes">
Expand All @@ -77,8 +77,8 @@ on an object that will contain a credit card number.
.. code-block:: php
// src/Acme/SubscriptionBundle/Entity/Transaction.php
namespace Acme\SubscriptionBundle\Entity\Transaction;
// src/AppBundle/Entity/Transaction.php
namespace AppBundle\Entity\Transaction;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;
Expand Down
Loading

0 comments on commit fe7aa8b

Please sign in to comment.