Skip to content

Commit

Permalink
[OptionsResolver] Support union of types
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored and javiereguiluz committed Jan 9, 2025
1 parent 2ccc964 commit f8667f5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions components/options_resolver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,20 @@ correctly. To validate the types of the options, call

// specify multiple allowed types
$resolver->setAllowedTypes('port', ['null', 'int']);
// which is similar to
$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('endpoints', '(int|string)[]');
}
}

.. versionadded:: 7.3

Union of type, using the ``|`` syntax, was introduced in Symfony 7.3.

You can pass any type for which an ``is_<type>()`` function is defined in PHP.
You may also pass fully qualified class or interface names (which is checked
using ``instanceof``). Additionally, you can validate all items in an array
Expand Down

0 comments on commit f8667f5

Please sign in to comment.