-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
replacing deprecated usage of True, False, Null validators in docs #5677
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0d5f098
Renaming constraint rst files to Is* to preserve edit history
11db556
Creating placeholder constraint rst docs for deprecated usage
f60c19a
Updated constraint reference docs for Null->IsNull, False->IsFalse, T…
68dde3a
Updating book examples to not use deprecated validation methods
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,9 @@ | ||
False | ||
===== | ||
|
||
Validates that a value is ``false``. Specifically, this checks to see if | ||
the value is exactly ``false``, exactly the integer ``0``, or exactly the | ||
string "``0``". | ||
|
||
Also see :doc:`True <True>`. | ||
|
||
+----------------+---------------------------------------------------------------------+ | ||
| Applies to | :ref:`property or method <validation-property-target>` | | ||
+----------------+---------------------------------------------------------------------+ | ||
| Options | - `message`_ | | ||
| | - `payload`_ | | ||
+----------------+---------------------------------------------------------------------+ | ||
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\False` | | ||
+----------------+---------------------------------------------------------------------+ | ||
| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\FalseValidator` | | ||
+----------------+---------------------------------------------------------------------+ | ||
|
||
Basic Usage | ||
----------- | ||
|
||
The ``False`` constraint can be applied to a property or a "getter" method, | ||
but is most commonly useful in the latter case. For example, suppose that | ||
you want to guarantee that some ``state`` property is *not* in a dynamic | ||
``invalidStates`` array. First, you'd create a "getter" method:: | ||
|
||
protected $state; | ||
|
||
protected $invalidStates = array(); | ||
|
||
public function isStateInvalid() | ||
{ | ||
return in_array($this->state, $this->invalidStates); | ||
} | ||
|
||
In this case, the underlying object is only valid if the ``isStateInvalid`` | ||
method returns **false**: | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: php-annotations | ||
|
||
// src/AppBundle/Entity/Author.php | ||
namespace AppBundle\Entity; | ||
|
||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
class Author | ||
{ | ||
/** | ||
* @Assert\False( | ||
* message = "You've entered an invalid state." | ||
* ) | ||
*/ | ||
public function isStateInvalid() | ||
{ | ||
// ... | ||
} | ||
} | ||
|
||
.. code-block:: yaml | ||
|
||
# src/AppBundle/Resources/config/validation.yml | ||
AppBundle\Entity\Author | ||
getters: | ||
stateInvalid: | ||
- 'False': | ||
message: You've entered an invalid state. | ||
|
||
.. code-block:: 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="AppBundle\Entity\Author"> | ||
<getter property="stateInvalid"> | ||
<constraint name="False"> | ||
<option name="message">You've entered an invalid state.</option> | ||
</constraint> | ||
</getter> | ||
</class> | ||
</constraint-mapping> | ||
|
||
.. code-block:: php | ||
|
||
// src/AppBundle/Entity/Author.php | ||
namespace AppBundle\Entity; | ||
|
||
use Symfony\Component\Validator\Mapping\ClassMetadata; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
class Author | ||
{ | ||
public static function loadValidatorMetadata(ClassMetadata $metadata) | ||
{ | ||
$metadata->addGetterConstraint('stateInvalid', new Assert\False()); | ||
} | ||
} | ||
|
||
.. caution:: | ||
|
||
When using YAML, be sure to surround ``False`` with quotes (``'False'``) | ||
or else YAML will convert this into a ``false`` boolean value. | ||
|
||
Options | ||
------- | ||
|
||
message | ||
~~~~~~~ | ||
|
||
**type**: ``string`` **default**: ``This value should be false.`` | ||
|
||
This message is shown if the underlying data is not false. | ||
The ``False`` constraint is deprecated since Symfony 2.7 | ||
and will be removed in Symfony 3.0. Use the ``IsFalse`` constraint instead. | ||
|
||
.. include:: /reference/constraints/_payload-option.rst.inc | ||
.. include:: /reference/constraints/IsFalse.rst | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
IsFalse | ||
======= | ||
|
||
Validates that a value is ``false``. Specifically, this checks to see if | ||
the value is exactly ``false``, exactly the integer ``0``, or exactly the | ||
string "``0``". | ||
|
||
Also see :doc:`IsTrue <IsTrue>`. | ||
|
||
+----------------+-----------------------------------------------------------------------+ | ||
| Applies to | :ref:`property or method <validation-property-target>` | | ||
+----------------+-----------------------------------------------------------------------+ | ||
| Options | - `message`_ | | ||
| | - `payload`_ | | ||
+----------------+-----------------------------------------------------------------------+ | ||
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\IsFalse` | | ||
+----------------+-----------------------------------------------------------------------+ | ||
| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\IsFalseValidator` | | ||
+----------------+-----------------------------------------------------------------------+ | ||
|
||
Basic Usage | ||
----------- | ||
|
||
The ``IsFalse`` constraint can be applied to a property or a "getter" method, | ||
but is most commonly useful in the latter case. For example, suppose that | ||
you want to guarantee that some ``state`` property is *not* in a dynamic | ||
``invalidStates`` array. First, you'd create a "getter" method:: | ||
|
||
protected $state; | ||
|
||
protected $invalidStates = array(); | ||
|
||
public function isStateInvalid() | ||
{ | ||
return in_array($this->state, $this->invalidStates); | ||
} | ||
|
||
In this case, the underlying object is only valid if the ``isStateInvalid`` | ||
method returns **false**: | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: php-annotations | ||
|
||
// src/AppBundle/Entity/Author.php | ||
namespace AppBundle\Entity; | ||
|
||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
class Author | ||
{ | ||
/** | ||
* @Assert\IsFalse( | ||
* message = "You've entered an invalid state." | ||
* ) | ||
*/ | ||
public function isStateInvalid() | ||
{ | ||
// ... | ||
} | ||
} | ||
|
||
.. code-block:: yaml | ||
|
||
# src/AppBundle/Resources/config/validation.yml | ||
AppBundle\Entity\Author | ||
getters: | ||
stateInvalid: | ||
- 'IsFalse': | ||
message: You've entered an invalid state. | ||
|
||
.. code-block:: 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="AppBundle\Entity\Author"> | ||
<getter property="stateInvalid"> | ||
<constraint name="IsFalse"> | ||
<option name="message">You've entered an invalid state.</option> | ||
</constraint> | ||
</getter> | ||
</class> | ||
</constraint-mapping> | ||
|
||
.. code-block:: php | ||
|
||
// src/AppBundle/Entity/Author.php | ||
namespace AppBundle\Entity; | ||
|
||
use Symfony\Component\Validator\Mapping\ClassMetadata; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
class Author | ||
{ | ||
public static function loadValidatorMetadata(ClassMetadata $metadata) | ||
{ | ||
$metadata->addGetterConstraint('stateInvalid', new Assert\IsFalse()); | ||
} | ||
} | ||
|
||
Options | ||
------- | ||
|
||
message | ||
~~~~~~~ | ||
|
||
**type**: ``string`` **default**: ``This value should be false.`` | ||
|
||
This message is shown if the underlying data is not false. | ||
|
||
.. include:: /reference/constraints/_payload-option.rst.inc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
IsNull | ||
====== | ||
|
||
Validates that a value is exactly equal to ``null``. To force that a property | ||
is simply blank (blank string or ``null``), see the :doc:`/reference/constraints/Blank` | ||
constraint. To ensure that a property is not null, see :doc:`/reference/constraints/NotNull`. | ||
|
||
Also see :doc:`NotNull <NotNull>`. | ||
|
||
+----------------+-----------------------------------------------------------------------+ | ||
| Applies to | :ref:`property or method <validation-property-target>` | | ||
+----------------+-----------------------------------------------------------------------+ | ||
| Options | - `message`_ | | ||
| | - `payload`_ | | ||
+----------------+-----------------------------------------------------------------------+ | ||
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\IsNull` | | ||
+----------------+-----------------------------------------------------------------------+ | ||
| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\IsNullValidator` | | ||
+----------------+-----------------------------------------------------------------------+ | ||
|
||
Basic Usage | ||
----------- | ||
|
||
If, for some reason, you wanted to ensure that the ``firstName`` property | ||
of an ``Author`` class exactly equal to ``null``, you could do the following: | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: php-annotations | ||
|
||
// src/AppBundle/Entity/Author.php | ||
namespace AppBundle\Entity; | ||
|
||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
class Author | ||
{ | ||
/** | ||
* @Assert\IsNull() | ||
*/ | ||
protected $firstName; | ||
} | ||
|
||
.. code-block:: yaml | ||
|
||
# src/AppBundle/Resources/config/validation.yml | ||
AppBundle\Entity\Author: | ||
properties: | ||
firstName: | ||
- 'IsNull': ~ | ||
|
||
.. code-block:: 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="AppBundle\Entity\Author"> | ||
<property name="firstName"> | ||
<constraint name="IsNull" /> | ||
</property> | ||
</class> | ||
</constraint-mapping> | ||
|
||
.. code-block:: php | ||
|
||
// src/AppBundle/Entity/Author.php | ||
namespace AppBundle\Entity; | ||
|
||
use Symfony\Component\Validator\Mapping\ClassMetadata; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
class Author | ||
{ | ||
public static function loadValidatorMetadata(ClassMetadata $metadata) | ||
{ | ||
$metadata->addPropertyConstraint('firstName', Assert\IsNull()); | ||
} | ||
} | ||
|
||
Options | ||
------- | ||
|
||
message | ||
~~~~~~~ | ||
|
||
**type**: ``string`` **default**: ``This value should be null.`` | ||
|
||
This is the message that will be shown if the value is not ``null``. | ||
|
||
.. include:: /reference/constraints/_payload-option.rst.inc |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of including the IsFalse documentation, I prefer to add a link to this docs in the caution above. So we end up with:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, including it does weird things, as it also includes the title