File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ .. index ::
2
+ single: Validation; Callables
3
+
4
+ How to Use Validation Constraints in Callable Validation (Validation Callables)
5
+ ===============================================================================
6
+
7
+ Sometimes you need to reuse Symfony's constraints in places like the Symfony Console,
8
+ to validate the answer to a console question. ``Validation::createCallable() ``
9
+ can be used to create a callable based on the given constraints::
10
+
11
+ use Symfony\Component\Console\Style\SymfonyStyle;
12
+ use Symfony\Component\Validator\Constraints\NotNull;
13
+ use Symfony\Component\Validator\Validation;
14
+
15
+ $io = new SymfonyStyle($input, $output);
16
+ $validation = Validation::createCallable(new NotBlank());
17
+
18
+ $wsdl = $io->ask('Wsdl location URL', null, $validation);
19
+
20
+ The argument of ``createCallable() `` is variadic, so you can pass any number of constraints::
21
+
22
+ // ...
23
+ use Symfony\Component\Validator\Constraints\Length;
24
+ use Symfony\Component\Validator\Constraints\Url;
25
+
26
+ $validation = Validation::createCallable(new Length(['max' => 255]), new Url());
27
+
28
+ .. versionadded :: 5.1
29
+
30
+ ``Validation::createCallable() `` was introduced in Symfony 5.1.
You can’t perform that action at this time.
0 commit comments