Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb34fb64

Browse files
committed
feature#3619 [Validator] Uuid constraint reference (colinodell)
This PR was merged into the master branch.Discussion----------[Validator] Uuid constraint referenceThis adds documentation for the proposed Uuid validation constraint.| Q | A| ------------- | ---| Doc fix? | no| New docs? | yes (symfony/symfony#10291)| Applies to | 2.5+| Fixed tickets | N/ACommits-------6f6c03f Fix formatting issues3ea9137 List the UUID constraint in the reference sectionf4afaab Documentation for the new Uuid constraint
2 parentsd7027c0 +6f6c03f commitb34fb64

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed

‎reference/constraints.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Validation Constraints Reference
1818
constraints/Url
1919
constraints/Regex
2020
constraints/Ip
21+
constraints/Uuid
2122

2223
constraints/Range
2324

‎reference/constraints/Uuid.rst

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
Uuid
2+
====
3+
4+
..versionadded::2.5
5+
The Uuid constraint was introduced in Symfony 2.5.
6+
7+
Validates that a value is a valid `Universally unique identifier (UUID)`_ per `RFC 4122`_.
8+
By default, this will validate the format according to the RFC's guidelines, but this can
9+
be relaxed to accept non-standard UUIDs that other systems (like PostgreSQL) accept.
10+
UUID versions can also be restricted using a whitelist.
11+
12+
+----------------+---------------------------------------------------------------------+
13+
| Applies to|:ref:`property or method<validation-property-target>`|
14+
+----------------+---------------------------------------------------------------------+
15+
| Options| - `message`_|
16+
|| - `strict`_|
17+
|| - `versions`_|
18+
+----------------+---------------------------------------------------------------------+
19+
| Class|:class:`Symfony\\Component\\Validator\\Constraints\\Uuid`|
20+
+----------------+---------------------------------------------------------------------+
21+
| Validator|:class:`Symfony\\Component\\Validator\\Constraints\\UuidValidator`|
22+
+----------------+---------------------------------------------------------------------+
23+
24+
Basic Usage
25+
-----------
26+
27+
..configuration-block::
28+
29+
..code-block::yaml
30+
31+
# src/UploadsBundle/Resources/config/validation.yml
32+
Acme\UploadsBundle\Entity\File:
33+
properties:
34+
identifier:
35+
-Uuid:~
36+
37+
..code-block::php-annotations
38+
39+
// src/Acme/UploadsBundle/Entity/File.php
40+
namespace Acme\UploadsBundle\Entity;
41+
42+
use Symfony\Component\Validator\Constraints as Assert;
43+
44+
class File
45+
{
46+
/**
47+
* @Assert\Uuid
48+
*/
49+
protected $identifier;
50+
}
51+
52+
..code-block::xml
53+
54+
<!-- src/Acme/UploadsBundle/Resources/config/validation.xml-->
55+
<?xml version="1.0" encoding="UTF-8" ?>
56+
<constraint-mappingxmlns="http://symfony.com/schema/dic/constraint-mapping"
57+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
58+
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
59+
60+
<classname="Acme\UploadsBundle\Entity\File">
61+
<propertyname="identifier">
62+
<constraintname="Uuid" />
63+
</property>
64+
</class>
65+
</constraint-mapping>
66+
67+
..code-block::php
68+
69+
// src/Acme/UploadsBundle/Entity/File.php
70+
namespace Acme\UploadsBundle\Entity;
71+
72+
use Symfony\Component\Validator\Mapping\ClassMetadata;
73+
use Symfony\Component\Validator\Constraints as Assert;
74+
75+
class File
76+
{
77+
public static function loadValidatorMetadata(ClassMetadata $metadata)
78+
{
79+
$metadata->addPropertyConstraint('identifier', new Assert\Uuid());
80+
}
81+
}
82+
83+
84+
Options
85+
-------
86+
87+
message
88+
~~~~~~~
89+
90+
**type**: ``string`` **default**: ``This is not a valid UUID.``
91+
92+
This message is shown if the string is not a valid UUID.
93+
94+
strict
95+
~~~~~~
96+
97+
**type**: ``boolean`` **default**: ``true``
98+
99+
If this option is set to ``true`` the constraint will check if the UUID is formatted per the
100+
RFC's input format rules: ``216fff40-98d9-11e3-a5e2-0800200c9a66``. Setting this to ``false``
101+
will allow alternate input formats like:
102+
103+
* ``216f-ff40-98d9-11e3-a5e2-0800-200c-9a66``
104+
* ``{216fff40-98d9-11e3-a5e2-0800200c9a66}``
105+
* ``216fff4098d911e3a5e20800200c9a66``
106+
107+
versions
108+
~~~~~~~~
109+
110+
**type**: ``int[]`` **default**: ``[1,2,3,4,5]``
111+
112+
This option can be used to only allow specific `UUID versions`_. Valid versions are 1 - 5.
113+
The following PHP constants can also be used:
114+
115+
* ``Uuid::V1_MAC``
116+
* ``Uuid::V2_DCE``
117+
* ``Uuid::V3_MD5``
118+
* ``Uuid::V4_RANDOM``
119+
* ``Uuid::V5_SHA1``
120+
121+
All five versions are allowed by default.
122+
123+
.. _`Universally unique identifier (UUID)`:http://en.wikipedia.org/wiki/Universally_unique_identifier
124+
.. _`RFC 4122`:http://tools.ietf.org/html/rfc4122
125+
.. _`UUID versions`:http://en.wikipedia.org/wiki/Universally_unique_identifier#Variants_and_versions

‎reference/constraints/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ String Constraints
2020
* :doc:`Url</reference/constraints/Url>`
2121
* :doc:`Regex</reference/constraints/Regex>`
2222
* :doc:`Ip</reference/constraints/Ip>`
23+
* :doc:`Uuid</reference/constraints/Uuid>`
2324

2425
Number Constraints
2526
~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp