From 2d05c9e2eb28747e7d18588fdf5bbe35169f848c Mon Sep 17 00:00:00 2001 From: Benjamin Georgeault Date: Tue, 15 Oct 2024 14:30:05 +0200 Subject: [PATCH] Add doc for Yaml's option `collection`. --- reference/constraints/Yaml.rst | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/reference/constraints/Yaml.rst b/reference/constraints/Yaml.rst index 49b65f251e8..834e6cbe5e7 100644 --- a/reference/constraints/Yaml.rst +++ b/reference/constraints/Yaml.rst @@ -145,6 +145,57 @@ Parameter Description ``{{ line }}`` The line where the YAML syntax error happened =============== ============================================================== +``collection`` +~~~~~~~~~~~~~~~ + +**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([ + 'foo' => new Assert\NotNull(), + ]), + ])); + } + } + +See :doc:`Collection constraint ` for more info. + .. include:: /reference/constraints/_groups-option.rst.inc .. include:: /reference/constraints/_payload-option.rst.inc pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy