Skip to content

Commit

Permalink
minor #5651 [Reference][Constraints] follow best practices in the con…
Browse files Browse the repository at this point in the history
…straints reference (xabbuh)

This PR was merged into the 2.7 branch.

Discussion
----------

[Reference][Constraints] follow best practices in the constraints reference

| Q             | A
| ------------- | ---
| Doc fix?      | yes
| New docs?     | no
| Applies to    | 2.7+
| Fixed tickets |

This completes the work done by @wouterj in #5645 by updating the docs that were added for Symfony 2.6/2.7.

Commits
-------

bfca2b7 follow best practices in the constraints reference
  • Loading branch information
wouterj committed Sep 5, 2015
2 parents c93a948 + bfca2b7 commit 206a98d
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 163 deletions.
2 changes: 1 addition & 1 deletion reference/constraints/Callback.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ You can then use the following configuration to invoke this validator:
.. code-block:: php-annotations
// src/AppBundle/Entity/Author.php
namespace Acme\BlogBundle\Entity;
namespace AppBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
Expand Down
35 changes: 18 additions & 17 deletions reference/constraints/Expression.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Basic Usage
Imagine you have a class ``BlogPost`` with ``category`` and ``isTechnicalPost``
properties::

namespace Acme\DemoBundle\Model;
// src/AppBundle/Model/BlogPost.php
namespace AppBundle\Model;

use Symfony\Component\Validator\Constraints as Assert;

Expand Down Expand Up @@ -61,17 +62,17 @@ One way to accomplish this is with the Expression constraint:

.. code-block:: yaml
# src/Acme/DemoBundle/Resources/config/validation.yml
Acme\DemoBundle\Model\BlogPost:
# src/AppBundle/Resources/config/validation.yml
AppBundle\Model\BlogPost:
constraints:
- Expression:
expression: "this.getCategory() in ['php', 'symfony'] or !this.isTechnicalPost()"
message: "If this is a tech post, the category should be either php or symfony!"
.. code-block:: php-annotations
// src/Acme/DemoBundle/Model/BlogPost.php
namespace Acme\DemoBundle\Model;
// src/AppBundle/Model/BlogPost.php
namespace AppBundle\Model;
use Symfony\Component\Validator\Constraints as Assert;
Expand All @@ -88,12 +89,12 @@ One way to accomplish this is with the Expression constraint:
.. code-block:: xml
<!-- src/Acme/DemoBundle/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\DemoBundle\Model\BlogPost">
<class name="AppBundle\Model\BlogPost">
<constraint name="Expression">
<option name="expression">
this.getCategory() in ['php', 'symfony'] or !this.isTechnicalPost()
Expand All @@ -107,8 +108,8 @@ One way to accomplish this is with the Expression constraint:
.. code-block:: php
// src/Acme/DemoBundle/Model/BlogPost.php
namespace Acme\DemoBundle\Model;
// src/AppBundle/Model/BlogPost.php
namespace AppBundle\Model;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;
Expand Down Expand Up @@ -142,8 +143,8 @@ more about the expression language syntax, see

.. code-block:: yaml
# src/Acme/DemoBundle/Resources/config/validation.yml
Acme\DemoBundle\Model\BlogPost:
# src/AppBundle/Resources/config/validation.yml
AppBundle\Model\BlogPost:
properties:
isTechnicalPost:
- Expression:
Expand All @@ -152,8 +153,8 @@ more about the expression language syntax, see
.. code-block:: php-annotations
// src/Acme/DemoBundle/Model/BlogPost.php
namespace Acme\DemoBundle\Model;
// src/AppBundle/Model/BlogPost.php
namespace AppBundle\Model;
use Symfony\Component\Validator\Constraints as Assert;
Expand All @@ -174,13 +175,13 @@ more about the expression language syntax, see
.. code-block:: xml
<!-- src/Acme/DemoBundle/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\DemoBundle\Model\BlogPost">
<class name="AppBundle\Model\BlogPost">
<property name="isTechnicalPost">
<constraint name="Expression">
<option name="expression">
Expand All @@ -196,8 +197,8 @@ more about the expression language syntax, see
.. code-block:: php
// src/Acme/DemoBundle/Model/BlogPost.php
namespace Acme\DemoBundle\Model;
// src/AppBundle/Model/BlogPost.php
namespace AppBundle\Model;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Mapping\ClassMetadata;
Expand Down
48 changes: 24 additions & 24 deletions reference/constraints/GreaterThan.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ that a date must at least be the next day:

.. code-block:: php-annotations
// src/Acme/OrderBundle/Entity/Order.php
namespace Acme\OrderBundle\Entity;
// src/AppBundle/Entity/Order.php
namespace AppBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
Expand All @@ -119,21 +119,21 @@ that a date must at least be the next day:
.. code-block:: yaml
# src/Acme/OrderBundle/Resources/config/validation.yml
Acme\OrderBundle\Entity\Order:
# src/AppBundle/Resources/config/validation.yml
AppBundle\Entity\Order:
properties:
deliveryDate:
- GreaterThan: today
.. code-block:: xml
<!-- src/Acme/OrderBundle/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\OrderBundle\Entity\Order">
<class name="AppBundle\Entity\Order">
<property name="deliveryDate">
<constraint name="GreaterThan">today</constraint>
</property>
Expand All @@ -142,8 +142,8 @@ that a date must at least be the next day:
.. code-block:: php
// src/Acme/OrderBundle/Entity/Order.php
namespace Acme\OrderBundle\Entity;
// src/AppBundle/Entity/Order.php
namespace AppBundle\Entity;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;
Expand All @@ -163,8 +163,8 @@ dates. If you want to fix the timezone, append it to the date string:

.. code-block:: php-annotations
// src/Acme/OrderBundle/Entity/Order.php
namespace Acme\OrderBundle\Entity;
// src/AppBundle/Entity/Order.php
namespace AppBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
Expand All @@ -178,21 +178,21 @@ dates. If you want to fix the timezone, append it to the date string:
.. code-block:: yaml
# src/Acme/OrderBundle/Resources/config/validation.yml
Acme\OrderBundle\Entity\Order:
# src/AppBundle/Resources/config/validation.yml
AppBundle\Entity\Order:
properties:
deliveryDate:
- GreaterThan: today UTC
.. code-block:: xml
<!-- src/Acme/OrderBundle/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\OrderBundle\Entity\Order">
<class name="AppBundle\Entity\Order">
<property name="deliveryDate">
<constraint name="GreaterThan">today UTC</constraint>
</property>
Expand All @@ -201,8 +201,8 @@ dates. If you want to fix the timezone, append it to the date string:
.. code-block:: php
// src/Acme/OrderBundle/Entity/Order.php
namespace Acme\OrderBundle\Entity;
// src/AppBundle/Entity/Order.php
namespace AppBundle\Entity;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;
Expand All @@ -223,8 +223,8 @@ current time:

.. code-block:: php-annotations
// src/Acme/OrderBundle/Entity/Order.php
namespace Acme\OrderBundle\Entity;
// src/AppBundle/Entity/Order.php
namespace AppBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
Expand All @@ -238,21 +238,21 @@ current time:
.. code-block:: yaml
# src/Acme/OrderBundle/Resources/config/validation.yml
Acme\OrderBundle\Entity\Order:
# src/AppBundle/Resources/config/validation.yml
AppBundle\Entity\Order:
properties:
deliveryDate:
- GreaterThan: +5 hours
.. code-block:: xml
<!-- src/Acme/OrderBundle/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\OrderBundle\Entity\Order">
<class name="AppBundle\Entity\Order">
<property name="deliveryDate">
<constraint name="GreaterThan">+5 hours</constraint>
</property>
Expand All @@ -261,8 +261,8 @@ current time:
.. code-block:: php
// src/Acme/OrderBundle/Entity/Order.php
namespace Acme\OrderBundle\Entity;
// src/AppBundle/Entity/Order.php
namespace AppBundle\Entity;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints as Assert;
Expand Down
Loading

0 comments on commit 206a98d

Please sign in to comment.