Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions components/options_resolver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,13 @@ correctly. To validate the types of the options, call
$resolver->setAllowedTypes('host', 'string');

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

// check all items in an array recursively for a type
$resolver->setAllowedTypes('dates', 'DateTime[]');
$resolver->setAllowedTypes('ports', 'int[]');
$resolver->setAllowedTypes('dates', 'DateTime[]');
$resolver->setAllowedTypes('dates', '(DateTime|DateTimeImmutable)[]');
}
}

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

.. versionadded:: 7.3

The support of union types was introduced in Symfony 7.3.

.. _optionsresolver-validate-value:

Value Validation
Expand Down
Loading