Skip to content

[Validator] Add documentation for ULID validator #14350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions reference/constraints/Ulid.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
ULID
====

.. versionadded:: 5.2

The ULID validator was introduced in Symfony 5.2.

Validates that a value is a valid `Universally Unique Lexicographically Sortable Identifier (ULID)`_.

========== ===================================================================
Applies to :ref:`property or method <validation-property-target>`
Options - `groups`_
- `message`_
- `normalizer`_
- `payload`_
Class :class:`Symfony\\Component\\Validator\\Constraints\\Ulid`
Validator :class:`Symfony\\Component\\Validator\\Constraints\\UlidValidator`
========== ===================================================================

Basic Usage
-----------

.. configuration-block::

.. code-block:: php-annotations

// src/Entity/File.php
namespace App\Entity;

use Symfony\Component\Validator\Constraints as Assert;

class File
{
/**
* @Assert\Ulid
*/
protected $identifier;
}

.. code-block:: yaml

# config/validator/validation.yaml
App\Entity\File:
properties:
identifier:
- Ulid: ~

.. code-block:: xml

<!-- config/validator/validation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping https://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">

<class name="App\Entity\File">
<property name="identifier">
<constraint name="Ulid"/>
</property>
</class>
</constraint-mapping>

.. code-block:: php

// src/Entity/File.php
namespace App\Entity;

use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Mapping\ClassMetadata;

class File
{
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('identifier', new Assert\Ulid());
}
}

.. include:: /reference/constraints/_empty-values-are-valid.rst.inc

Options
-------

.. include:: /reference/constraints/_groups-option.rst.inc

``message``
~~~~~~~~~~~

**type**: ``string`` **default**: ``This is not a valid ULID.``

This message is shown if the string is not a valid ULID.

You can use the following parameters in this message:

=============== ==============================================================
Parameter Description
=============== ==============================================================
``{{ value }}`` The current (invalid) value
``{{ label }}`` Corresponding form field label
=============== ==============================================================

.. include:: /reference/constraints/_normalizer-option.rst.inc

.. include:: /reference/constraints/_payload-option.rst.inc


.. _`Universally Unique Lexicographically Sortable Identifier (ULID)`: https://github.com/ulid/spec
1 change: 1 addition & 0 deletions reference/constraints/map.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ String Constraints
* :doc:`Ip </reference/constraints/Ip>`
* :doc:`Json </reference/constraints/Json>`
* :doc:`Uuid </reference/constraints/Uuid>`
* :doc:`Ulid </reference/constraints/Ulid>`
* :doc:`UserPassword </reference/constraints/UserPassword>`
* :doc:`NotCompromisedPassword </reference/constraints/NotCompromisedPassword>`

Expand Down