Skip to content

Commit f8667f5

Browse files
VincentLangletjaviereguiluz
authored andcommitted
[OptionsResolver] Support union of types
1 parent 2ccc964 commit f8667f5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

components/options_resolver.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,20 @@ correctly. To validate the types of the options, call
305305

306306
// specify multiple allowed types
307307
$resolver->setAllowedTypes('port', ['null', 'int']);
308+
// which is similar to
309+
$resolver->setAllowedTypes('port', 'int|null');
308310

309311
// check all items in an array recursively for a type
310312
$resolver->setAllowedTypes('dates', 'DateTime[]');
311313
$resolver->setAllowedTypes('ports', 'int[]');
314+
$resolver->setAllowedTypes('endpoints', '(int|string)[]');
312315
}
313316
}
314317

318+
.. versionadded:: 7.3
319+
320+
Union of type, using the ``|`` syntax, was introduced in Symfony 7.3.
321+
315322
You can pass any type for which an ``is_<type>()`` function is defined in PHP.
316323
You may also pass fully qualified class or interface names (which is checked
317324
using ``instanceof``). Additionally, you can validate all items in an array

0 commit comments

Comments
 (0)