Skip to content

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

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
Sep 5, 2015
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
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