Skip to content

Commit 8d9cc65

Browse files
committed
[OptionsResolver] Support union of types
1 parent 2ccc964 commit 8d9cc65

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

components/options_resolver.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,13 @@ correctly. To validate the types of the options, call
304304
$resolver->setAllowedTypes('host', 'string');
305305

306306
// specify multiple allowed types
307-
$resolver->setAllowedTypes('port', ['null', 'int']);
307+
$resolver->setAllowedTypes('port', ['int', 'null']);
308+
$resolver->setAllowedTypes('port', 'int|null');
308309

309310
// check all items in an array recursively for a type
310-
$resolver->setAllowedTypes('dates', 'DateTime[]');
311311
$resolver->setAllowedTypes('ports', 'int[]');
312+
$resolver->setAllowedTypes('dates', 'DateTime[]');
313+
$resolver->setAllowedTypes('dates', '(DateTime|DateTimeImmutable)[]');
312314
}
313315
}
314316

@@ -331,6 +333,10 @@ is thrown::
331333
In sub-classes, you can use :method:`Symfony\\Component\\OptionsResolver\\OptionsResolver::addAllowedTypes`
332334
to add additional allowed types without erasing the ones already set.
333335

336+
.. versionadded:: 7.3
337+
338+
The support of union types was introduced in Symfony 7.3.
339+
334340
.. _optionsresolver-validate-value:
335341

336342
Value Validation

0 commit comments

Comments
 (0)