8000 Reword · symfony/symfony-docs@a992448 · GitHub
[go: up one dir, main page]

Skip to content

Commit a992448

Browse files
committed
Reword
1 parent d97e75d commit a992448

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

reference/constraints/Type.rst

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ option to validate this.
2121
Basic Usage
2222
-----------
2323

24-
This will check if ``firstName`` is of type ``string`` and that ``age`` is an
25-
``integer``.
24+
This will check that ``id`` is an instance of ``Ramsey\Uuid\UuidInterface``,
25+
``firstName`` is of type ``string`` and ``age`` is an ``integer``.
2626

2727
.. configuration-block::
2828

@@ -35,6 +35,11 @@ This will check if ``firstName`` is of type ``string`` and that ``age`` is an
3535
3636
class Author
3737
{
38+
/**
39+
* @Assert\Type("Ramsey\Uuid\UuidInterface")
40+
*/
41+
protected $id;
42+
3843
/**
3944
* @Assert\Type("string")
4045
*/
@@ -54,6 +59,9 @@ This will check if ``firstName`` is of type ``string`` and that ``age`` is an
5459
# src/AppBundle/Resources/config/validation.yml
5560
AppBundle\Entity\Author:
5661
properties:
62+
id:
63+
- Type: Ramsey\Uuid\UuidInterface
64+
5765
firstName:
5866
- Type: string
5967
@@ -71,6 +79,11 @@ This will check if ``firstName`` is of type ``string`` and that ``age`` is an
7179
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping https://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
7280
7381
<class name="AppBundle\Entity\Author">
82+
<property name="id">
83+
<constraint name="Type">
84+
<option name="type">Ramsey\Uuid\UuidInterface</option>
85+
</constraint>
86+
</property>
7487
<property name="firstName">
7588
<constraint name="Type">
7689
<option name="type">string</option>
@@ -90,13 +103,16 @@ This will check if ``firstName`` is of type ``string`` and that ``age`` is an
90103
// src/AppBundle/Entity/Author.php
91104
namespace AppBundle\Entity;
92105
106+
use Ramsey\Uuid\UuidInterface;
93107
use Symfony\Component\Validator\Constraints as Assert;
94108
use Symfony\Component\Validator\Mapping\ClassMetadata;
95109
96110
class Author
97111
{
98112
public static function loadValidatorMetadata(ClassMetadata $metadata)
99113
{
114+
$metadata->addPropertyConstraint('id', new Assert\Type(UuidInterface::class));
115+
100116
$metadata->addPropertyConstraint('firstName', new Assert\Type('string'));
101117
102118
$metadata->addPropertyConstraint('age', new Assert\Type([
@@ -106,10 +122,6 @@ This will check if ``firstName`` is of type ``string`` and that ``age`` is an
106122
}
107123
}
108124
109-
.. tip::
110-
111-
Type value can be class's or interface's fully qualified class name
112-
113125
Options
114126
-------
115127

@@ -120,8 +132,8 @@ type
120132

121133
**type**: ``string`` [:ref:`default option <validation-default-option>`]
122134

123-
This required option is the fully qualified class name or one of the PHP
124-
datatypes as determined by PHP's ``is_()`` functions.
135+
This required option is either the FQCN (fully qualified class name) of some PHP
136+
class/interface or a valid PHP datatype (checked by PHP's ``is_()`` functions):
125137

126138
* :phpfunction:`array <is_array>`
127139
* :phpfunction:`bool <is_bool>`

0 commit comments

Comments
 (0)
0