Skip to content

Commit e72aca0

Browse files
committed
Add doc for Yaml's option configClass.
1 parent 04ccd92 commit e72aca0

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

reference/constraints/Yaml.rst

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,69 @@ Parameter Description
145145
``{{ line }}`` The line where the YAML syntax error happened
146146
=============== ==============================================================
147147

148+
``configClass``
149+
~~~~~~~~~~~
150+
151+
**type**: ``string`` **default**: ``null``
152+
153+
This option enable a validation check using a class that implement
154+
:class:`Symfony\Component\Config\Definition\ConfigurationInterface`. You need to give it the full classname of your
155+
configuration class.
156+
157+
.. configuration-block::
158+
159+
.. code-block:: php-attributes
160+
161+
// src/Entity/Report.php
162+
namespace App\Entity;
163+
164+
use App\Yaml\MyConfiguration;
165+
use Symfony\Component\Validator\Constraints as Assert;
166+
167+
class Report
168+
{
169+
#[Assert\Yaml(
170+
configClass: MyConfiguration::class,
171+
)]
172+
private string $customConfiguration;
173+
}
174+
175+
.. code-block:: php
176+
177+
// src/Entity/Report.php
178+
namespace App\Entity;
179+
180+
use App\Yaml\MyConfiguration;
181+
use Symfony\Component\Validator\Constraints as Assert;
182+
use Symfony\Component\Validator\Mapping\ClassMetadata;
183+
184+
class Report
185+
{
186+
public static function loadValidatorMetadata(ClassMetadata $metadata): void
187+
{
188+
$metadata->addPropertyConstraint('customConfiguration', new Assert\Yaml([
189+
'configClass' => MyConfiguration::class,
190+
]));
191+
}
192+
}
193+
194+
For more info about Configuration, see :doc:`Config component </components/config>`.
195+
196+
``configMessage``
197+
~~~~~~~~~~~
198+
199+
**type**: ``string`` **default**: ``This value do not match the required config.``
200+
201+
This message shown if the given YAML value is invalid regarding the Configuration class.
202+
203+
You can use the following parameters in this message:
204+
205+
=============== ==============================================================
206+
Parameter Description
207+
=============== ==============================================================
208+
``{{ error }}`` The full error message from the config Processor
209+
=============== ==============================================================
210+
148211
.. include:: /reference/constraints/_groups-option.rst.inc
149212

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

0 commit comments

Comments
 (0)