Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OptionsResolver] Support union of types #20537

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