File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,11 @@ Validator :class:`Symfony\\Component\\Validator\\Constraints\\TypeValidator`
14
14
Basic Usage
15
15
-----------
16
16
17
- This will check if ``emailAddress `` is an instance of ``Symfony\Component\Mime\Address ``,
17
+ This constraint should be applied to untyped variables/properties. If a property
18
+ or variable is typed and you pass a value of a different type, PHP will throw an
19
+ exception before this constraint is checked.
20
+
21
+ The following example checks if ``emailAddress `` is an instance of ``Symfony\Component\Mime\Address ``,
18
22
``firstName `` is of type ``string `` (using :phpfunction: `is_string ` PHP function),
19
23
``age `` is an ``integer `` (using :phpfunction: `is_int ` PHP function) and
20
24
``accessCode `` contains either only letters or only digits (using
@@ -33,19 +37,19 @@ This will check if ``emailAddress`` is an instance of ``Symfony\Component\Mime\A
33
37
class Author
34
38
{
35
39
#[Assert\Type(Address::class)]
36
- protected Address $emailAddress;
40
+ protected $emailAddress;
37
41
38
42
#[Assert\Type('string')]
39
- protected string $firstName;
43
+ protected $firstName;
40
44
41
45
#[Assert\Type(
42
46
type: 'integer',
43
47
message: 'The value {{ value }} is not a valid {{ type }}.',
44
48
)]
45
- protected int $age;
49
+ protected $age;
46
50
47
51
#[Assert\Type(type: ['alpha', 'digit'])]
48
- protected string $accessCode;
52
+ protected $accessCode;
49
53
}
50
54
51
55
.. code-block :: yaml
You can’t perform that action at this time.
0 commit comments