Skip to content

Commit

Permalink
Replace Assert annotations with attributes, remove Assert annotation …
Browse files Browse the repository at this point in the history
…configuration block
  • Loading branch information
ker0x authored and Romain Monteil committed Aug 22, 2022
1 parent 1c62383 commit eed27a0
Show file tree
Hide file tree
Showing 72 changed files with 21 additions and 1,967 deletions.
10 changes: 3 additions & 7 deletions form/embedded.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ creating the ``Category`` class::

class Category
{
/**
* @Assert\NotBlank
*/
#[Assert\NotBlank]
public $name;
}

Expand All @@ -38,10 +36,8 @@ Next, add a new ``category`` property to the ``Task`` class::
{
// ...

/**
* @Assert\Type(type="App\Entity\Category")
* @Assert\Valid
*/
#[Assert\Type(type: Category::class)]
#[Assert\Valid]
protected $category;

// ...
Expand Down
21 changes: 0 additions & 21 deletions forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -469,27 +469,6 @@ object.

.. configuration-block::

.. code-block:: php-annotations
// src/Entity/Task.php
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class Task
{
/**
* @Assert\NotBlank
*/
public $task;
/**
* @Assert\NotBlank
* @Assert\Type("\DateTime")
*/
protected $dueDate;
}
.. code-block:: php-attributes
// src/Entity/Task.php
Expand Down
18 changes: 0 additions & 18 deletions reference/constraints/All.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,6 @@ entry in that array:

.. configuration-block::

.. code-block:: php-annotations
// src/Entity/User.php
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class User
{
/**
* @Assert\All({
* @Assert\NotBlank,
* @Assert\Length(min=5)
* })
*/
protected $favoriteColors = [];
}
.. code-block:: php-attributes
// src/Entity/User.php
Expand Down
28 changes: 0 additions & 28 deletions reference/constraints/AtLeastOneOf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,6 @@ The following constraints ensure that:

.. configuration-block::

.. code-block:: php-annotations
// src/Entity/Student.php
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class Student
{
/**
* @Assert\AtLeastOneOf({
* @Assert\Regex("/#/"),
* @Assert\Length(min=10)
* })
*/
protected $password;
/**
* @Assert\AtLeastOneOf({
* @Assert\Count(min=3),
* @Assert\All(
* @Assert\GreaterThanOrEqual(5)
* )
* })
*/
protected $grades;
}
.. code-block:: php-attributes
// src/Entity/Student.php
Expand Down
15 changes: 0 additions & 15 deletions reference/constraints/Bic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,6 @@ will contain a Business Identifier Code (BIC).

.. configuration-block::

.. code-block:: php-annotations
// src/Entity/Transaction.php
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class Transaction
{
/**
* @Assert\Bic
*/
protected $businessIdentifierCode;
}
.. code-block:: php-attributes
// src/Entity/Transaction.php
Expand Down
15 changes: 0 additions & 15 deletions reference/constraints/Blank.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,6 @@ of an ``Author`` class were blank, you could do the following:

.. configuration-block::

.. code-block:: php-annotations
// src/Entity/Author.php
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class Author
{
/**
* @Assert\Blank
*/
protected $firstName;
}
.. code-block:: php-attributes
// src/Entity/Author.php
Expand Down
37 changes: 2 additions & 35 deletions reference/constraints/Callback.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,6 @@ Configuration

.. configuration-block::

.. code-block:: php-annotations
// src/Entity/Author.php
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
class Author
{
/**
* @Assert\Callback
*/
public function validate(ExecutionContextInterface $context, $payload)
{
// ...
}
}
.. code-block:: php-attributes
// src/Entity/Author.php
Expand Down Expand Up @@ -178,20 +159,6 @@ You can then use the following configuration to invoke this validator:

.. configuration-block::

.. code-block:: php-annotations
// src/Entity/Author.php
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @Assert\Callback({"Acme\Validator", "validate"})
*/
class Author
{
}
.. code-block:: php-attributes
// src/Entity/Author.php
Expand Down Expand Up @@ -280,8 +247,8 @@ constructor of the Callback constraint::

.. warning::

Using a ``Closure`` together with annotation configuration will disable the
annotation cache for that class/property/method because ``Closure`` cannot
Using a ``Closure`` together with attribute configuration will disable the
attribute cache for that class/property/method because ``Closure`` cannot
be cached. For best performance, it's recommended to use a static callback method.

Options
Expand Down
18 changes: 0 additions & 18 deletions reference/constraints/CardScheme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,6 @@ on an object that will contain a credit card number.

.. configuration-block::

.. code-block:: php-annotations
// src/Entity/Transaction.php
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class Transaction
{
/**
* @Assert\CardScheme(
* schemes={"VISA"},
* message="Your credit card number is invalid."
* )
*/
protected $cardNumber;
}
.. code-block:: php-attributes
// src/Entity/Transaction.php
Expand Down
54 changes: 0 additions & 54 deletions reference/constraints/Choice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,6 @@ If your valid choice list is simple, you can pass them in directly via the

.. configuration-block::

.. code-block:: php-annotations
// src/Entity/Author.php
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class Author
{
const GENRES = ['fiction', 'non-fiction'];
/**
* @Assert\Choice({"New York", "Berlin", "Tokyo"})
*/
protected $city;
/**
* You can also directly provide an array constant to the "choices" option in the annotation
*
* @Assert\Choice(choices=Author::GENRES, message="Choose a valid genre.")
*/
protected $genre;
}
.. code-block:: php-attributes
// src/Entity/Author.php
Expand Down Expand Up @@ -152,21 +128,6 @@ constraint.

.. configuration-block::

.. code-block:: php-annotations
// src/Entity/Author.php
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class Author
{
/**
* @Assert\Choice(callback="getGenres")
*/
protected $genre;
}
.. code-block:: php-attributes
// src/Entity/Author.php
Expand Down Expand Up @@ -230,21 +191,6 @@ you can pass the class name and the method as an array.

.. configuration-block::

.. code-block:: php-annotations
// src/Entity/Author.php
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class Author
{
/**
* @Assert\Choice(callback={"App\Entity\Genre", "getGenres"})
*/
protected $genre;
}
.. code-block:: php-attributes
// src/Entity/Author.php
Expand Down
15 changes: 0 additions & 15 deletions reference/constraints/Cidr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,6 @@ Basic Usage

.. configuration-block::

.. code-block:: php-annotations
// src/Entity/NetworkSettings.php
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class NetworkSettings
{
/**
* @Assert\Cidr
*/
protected $cidrNotation;
}
.. code-block:: php-attributes
// src/Entity/NetworkSettings.php
Expand Down
Loading

0 comments on commit eed27a0

Please sign in to comment.