Skip to content
Open
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
51 changes: 51 additions & 0 deletions reference/constraints/Yaml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,57 @@
``{{ line }}`` The line where the YAML syntax error happened
=============== ==============================================================

``collection``

Check failure on line 148 in reference/constraints/Yaml.rst

View workflow job for this annotation

GitHub Actions / Lint (DOCtor-RST)

Please ensure title "collection" and underline length are matching
~~~~~~~~~~~~~~~

**type**: :class:``Symfony\Component\Validator\Constraints`` **default**: ``null``

This option apply a :class:``Symfony\Component\Validator\Constraints\Collection`` constraint to Yaml parsed data.
You can apply validation on the content of your Yaml.

.. configuration-block::

.. code-block:: php-attributes

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

use App\Yaml\MyConfiguration;
use Symfony\Component\Validator\Constraints as Assert;

class Report
{
#[Assert\Yaml(
collection: new Assert\Collection([
'foo' => new Assert\NotNull(),
]),
)]
private string $customConfiguration;
}

.. code-block:: php

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

use App\Yaml\MyConfiguration;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Mapping\ClassMetadata;

class Report
{
public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('customConfiguration', new Assert\Yaml([
collection: new Assert\Collection([

Check failure on line 190 in reference/constraints/Yaml.rst

View workflow job for this annotation

GitHub Actions / Code Blocks

[PHP syntax] Syntax error, unexpected ':', expecting ',' or ']' or ')'
'foo' => new Assert\NotNull(),
]),
]));

Check failure on line 193 in reference/constraints/Yaml.rst

View workflow job for this annotation

GitHub Actions / Code Blocks

[PHP syntax] Syntax error, unexpected ']', expecting ')'
}
}

See :doc:`Collection constraint </reference/constraints/Collection>` for more info.

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

.. include:: /reference/constraints/_payload-option.rst.inc
Expand Down
Loading