From 7dab8a03fe759c4e437fb11797e8330f015d816d Mon Sep 17 00:00:00 2001 From: Benjamin Georgeault Date: Mon, 14 Oct 2024 11:51:58 +0200 Subject: [PATCH] Add doc for Yaml's option `configClass`. --- reference/constraints/Yaml.rst | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/reference/constraints/Yaml.rst b/reference/constraints/Yaml.rst index 49b65f251e8..29849ec8617 100644 --- a/reference/constraints/Yaml.rst +++ b/reference/constraints/Yaml.rst @@ -145,6 +145,69 @@ Parameter Description ``{{ line }}`` The line where the YAML syntax error happened =============== ============================================================== +``configClass`` +~~~~~~~~~~~~~~~ + +**type**: ``string`` **default**: ``null`` + +This option enable a validation check using a class that implement +:class:``Symfony\Component\Config\Definition\ConfigurationInterface``. You need to give it the full classname of your +configuration class. + +.. 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( + configClass: MyConfiguration::class, + )] + 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([ + 'configClass' => MyConfiguration::class, + ])); + } + } + +For more info about Configuration, see :doc:`Config component `. + +``configMessage`` +~~~~~~~~~~~~~~~~~ + +**type**: ``string`` **default**: ``This value do not match the required config.`` + +This message shown if the given YAML value is invalid regarding the Configuration class. + +You can use the following parameters in this message: + +=============== ============================================================== +Parameter Description +=============== ============================================================== +``{{ error }}`` The full error message from the config Processor +=============== ============================================================== + .. include:: /reference/constraints/_groups-option.rst.inc .. include:: /reference/constraints/_payload-option.rst.inc