diff --git a/components/options_resolver.rst b/components/options_resolver.rst index 1ed2347b4d8..54fa38829ba 100644 --- a/components/options_resolver.rst +++ b/components/options_resolver.rst @@ -317,14 +317,27 @@ correctly. To validate the types of the options, call public function configureOptions(OptionsResolver $resolver) { // ... + + // specify one allowed type $resolver->setAllowedTypes('host', 'string'); + + // specify multiple allowed types $resolver->setAllowedTypes('port', array('null', 'int')); + + // check all items in an array recursively for a type + $resolver->setAllowedTypes('dates', 'DateTime[]'); + $resolver->setAllowedtypes('ports', 'int[]'); } } -For each option, you can define either just one type or an array of acceptable -types. You can pass any type for which an ``is_()`` function is defined -in PHP. Additionally, you may pass fully qualified class or interface names. +You can pass any type for which an ``is_()`` 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 +recursively by suffixing the type with ``[]``. + +.. versionadded:: 3.4 + Validating types of array items recursively was introduced in Symfony 3.4. + Prior to Symfony 3.4, only scalar values could be validated. If you pass an invalid option now, an :class:`Symfony\\Component\\OptionsResolver\\Exception\\InvalidOptionsException` pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy