|
1 | 1 | False |
2 | 2 | ===== |
3 | 3 |
|
4 | | -Validates that a value is ``false``. Specifically, this checks to see if |
5 | | -the value is exactly ``false``, exactly the integer ``0``, or exactly the |
6 | | -string "``0``". |
7 | | - |
8 | | -Also see :doc:`True <True>`. |
9 | | - |
10 | | -+----------------+---------------------------------------------------------------------+ |
11 | | -| Applies to | :ref:`property or method <validation-property-target>` | |
12 | | -+----------------+---------------------------------------------------------------------+ |
13 | | -| Options | - `message`_ | |
14 | | -+----------------+---------------------------------------------------------------------+ |
15 | | -| Class | :class:`Symfony\\Component\\Validator\\Constraints\\False` | |
16 | | -+----------------+---------------------------------------------------------------------+ |
17 | | -| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\FalseValidator` | |
18 | | -+----------------+---------------------------------------------------------------------+ |
19 | | - |
20 | | -Basic Usage |
21 | | ------------ |
22 | | - |
23 | | -The ``False`` constraint can be applied to a property or a "getter" method, |
24 | | -but is most commonly useful in the latter case. For example, suppose that |
25 | | -you want to guarantee that some ``state`` property is *not* in a dynamic |
26 | | -``invalidStates`` array. First, you'd create a "getter" method:: |
27 | | - |
28 | | - protected $state; |
29 | | - |
30 | | - protected $invalidStates = array(); |
31 | | - |
32 | | - public function isStateInvalid() |
33 | | - { |
34 | | - return in_array($this->state, $this->invalidStates); |
35 | | - } |
36 | | - |
37 | | -In this case, the underlying object is only valid if the ``isStateInvalid`` |
38 | | -method returns **false**: |
39 | | - |
40 | | -.. configuration-block:: |
41 | | - |
42 | | - .. code-block:: php-annotations |
43 | | -
|
44 | | - // src/AppBundle/Entity/Author.php |
45 | | - namespace AppBundle\Entity; |
46 | | -
|
47 | | - use Symfony\Component\Validator\Constraints as Assert; |
48 | | -
|
49 | | - class Author |
50 | | - { |
51 | | - /** |
52 | | - * @Assert\False( |
53 | | - * message = "You've entered an invalid state." |
54 | | - * ) |
55 | | - */ |
56 | | - public function isStateInvalid() |
57 | | - { |
58 | | - // ... |
59 | | - } |
60 | | - } |
61 | | -
|
62 | | - .. code-block:: yaml |
63 | | -
|
64 | | - # src/AppBundle/Resources/config/validation.yml |
65 | | - AppBundle\Entity\Author |
66 | | - getters: |
67 | | - stateInvalid: |
68 | | - - 'False': |
69 | | - message: You've entered an invalid state. |
70 | | -
|
71 | | - .. code-block:: xml |
72 | | -
|
73 | | - <!-- src/AppBundle/Resources/config/validation.xml --> |
74 | | - <?xml version="1.0" encoding="UTF-8" ?> |
75 | | - <constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping" |
76 | | - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
77 | | - xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"> |
78 | | -
|
79 | | - <class name="AppBundle\Entity\Author"> |
80 | | - <getter property="stateInvalid"> |
81 | | - <constraint name="False"> |
82 | | - <option name="message">You've entered an invalid state.</option> |
83 | | - </constraint> |
84 | | - </getter> |
85 | | - </class> |
86 | | - </constraint-mapping> |
87 | | -
|
88 | | - .. code-block:: php |
89 | | -
|
90 | | - // src/AppBundle/Entity/Author.php |
91 | | - namespace AppBundle\Entity; |
92 | | -
|
93 | | - use Symfony\Component\Validator\Mapping\ClassMetadata; |
94 | | - use Symfony\Component\Validator\Constraints as Assert; |
95 | | -
|
96 | | - class Author |
97 | | - { |
98 | | - public static function loadValidatorMetadata(ClassMetadata $metadata) |
99 | | - { |
100 | | - $metadata->addGetterConstraint('stateInvalid', new Assert\False()); |
101 | | - } |
102 | | - } |
103 | | -
|
104 | 4 | .. caution:: |
105 | 5 |
|
106 | | - When using YAML, be sure to surround ``False`` with quotes (``'False'``) |
107 | | - or else YAML will convert this into a ``false`` boolean value. |
108 | | - |
109 | | -Options |
110 | | -------- |
111 | | - |
112 | | -message |
113 | | -~~~~~~~ |
114 | | - |
115 | | -**type**: ``string`` **default**: ``This value should be false.`` |
| 6 | + The ``False`` constraint is deprecated since Symfony 2.7 |
| 7 | + and will be removed in Symfony 3.0. Use the ``IsFalse`` constraint instead. |
116 | 8 |
|
117 | | -This message is shown if the underlying data is not false. |
| 9 | +.. include:: /reference/constraints/IsFalse.rst |
0 commit comments