Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[OptionsResolver] ContextErrorException on array option with callback allowed type #10202

Copy link
Copy link
Closed
@codekestrel

Description

@codekestrel
Issue body actions

In relation to #8375

I would get the following error when passing an array as an option with a callback allowed type:

ContextErrorException: Notice: Array to string conversion in /vendor/symfony/symfony/src/Symfony/Component/OptionsResolver/OptionsResolver.php line 303

The following alternation resolves the problem:

private function validateOptionValues(array $options)
{
    foreach ($this->allowedValues as $option => $allowedValues) {
        if (isset($options[$option])) {
            if (is_array($allowedValues) && !in_array($options[$option], $allowedValues, true)) {
                throw new InvalidOptionsException(sprintf('The option "%s" has the value "%s", but is expected to be one of "%s"', $option, $options[$option], implode('", "', $allowedValues)));
            }

            if (is_callable($allowedValues) && !call_user_func($allowedValues, $options[$option])) {
                if(! is_scalar($options[$option])) {
                    throw new InvalidOptionsException(sprintf(
                        'The option "%s" of value type "%s" does not have valid content', $option, gettype($options[$option])));
                } else {
                    throw new InvalidOptionsException(sprintf('The option "%s" has the value "%s", which it is not valid', $option, $options[$option]));
                }
            }
        }
    }
}

Is this recognized as a real problem?

This may also solve: #4833

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.