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

Commit42c3a6d

Browse files
committed
[Validator] Add documention for ULID validator
1 parent707580e commit42c3a6d

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

‎reference/constraints/Ulid.rst‎

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
ULID
2+
====
3+
4+
..versionadded::5.2
5+
6+
The ULID validator was introduced in Symfony 5.2.
7+
8+
Validates that a value is a valid `Universally Unique Lexicographically Sortable Identifier (ULID)`_.
9+
10+
========== ===================================================================
11+
Applies to:ref:`property or method<validation-property-target>`
12+
Options - `groups`_
13+
- `message`_
14+
- `normalizer`_
15+
- `payload`_
16+
Class:class:`Symfony\\Component\\Validator\\Constraints\\Ulid`
17+
Validator:class:`Symfony\\Component\\Validator\\Constraints\\UlidValidator`
18+
========== ===================================================================
19+
20+
Basic Usage
21+
-----------
22+
23+
..configuration-block::
24+
25+
..code-block::php-annotations
26+
27+
// src/Entity/File.php
28+
namespace App\Entity;
29+
30+
use Symfony\Component\Validator\Constraints as Assert;
31+
32+
class File
33+
{
34+
/**
35+
* @Assert\Ulid
36+
*/
37+
protected $identifier;
38+
}
39+
40+
..code-block::yaml
41+
42+
# config/validator/validation.yaml
43+
App\Entity\File:
44+
properties:
45+
identifier:
46+
-Ulid:~
47+
48+
..code-block::xml
49+
50+
<!-- config/validator/validation.xml-->
51+
<?xml version="1.0" encoding="UTF-8" ?>
52+
<constraint-mappingxmlns="http://symfony.com/schema/dic/constraint-mapping"
53+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
54+
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping https://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
55+
56+
<classname="App\Entity\File">
57+
<propertyname="identifier">
58+
<constraintname="Ulid"/>
59+
</property>
60+
</class>
61+
</constraint-mapping>
62+
63+
..code-block::php
64+
65+
// src/Entity/File.php
66+
namespace App\Entity;
67+
68+
use Symfony\Component\Validator\Constraints as Assert;
69+
use Symfony\Component\Validator\Mapping\ClassMetadata;
70+
71+
class File
72+
{
73+
public static function loadValidatorMetadata(ClassMetadata $metadata)
74+
{
75+
$metadata->addPropertyConstraint('identifier', new Assert\Ulid());
76+
}
77+
}
78+
79+
..include::/reference/constraints/_empty-values-are-valid.rst.inc
80+
81+
Options
82+
-------
83+
84+
..include::/reference/constraints/_groups-option.rst.inc
85+
86+
``message``
87+
~~~~~~~~~~~
88+
89+
**type**: ``string`` **default**: ``This is not a valid ULID.``
90+
91+
This message is shown if the string is not a valid ULID.
92+
93+
You can use the following parameters in this message:
94+
95+
=============== ==============================================================
96+
Parameter Description
97+
=============== ==============================================================
98+
``{{ value }}`` The current (invalid) value
99+
``{{ label }}`` Corresponding form field label
100+
=============== ==============================================================
101+
102+
..include::/reference/constraints/_normalizer-option.rst.inc
103+
104+
..include::/reference/constraints/_payload-option.rst.inc
105+
106+
107+
.. _`Universally Unique Lexicographically Sortable Identifier (ULID)`:https://github.com/ulid/spec

‎reference/constraints/map.rst.inc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ String Constraints
2424
* :doc:`Ip</reference/constraints/Ip>`
2525
* :doc:`Json</reference/constraints/Json>`
2626
* :doc:`Uuid</reference/constraints/Uuid>`
27+
* :doc:`Ulid</reference/constraints/Ulid>`
2728
* :doc:`UserPassword</reference/constraints/UserPassword>`
2829
* :doc:`NotCompromisedPassword</reference/constraints/NotCompromisedPassword>`
2930

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp