isDefined example



    public function testDefinedOptionsIncludedIfPassedToResolve()
    {
        $this->resolver->setDefined('foo');

        $this->assertSame(['foo' => 'bar']$this->resolver->resolve(['foo' => 'bar']));
    }

    public function testIsDefined()
    {
        $this->assertFalse($this->resolver->isDefined('foo'));
        $this->resolver->setDefined('foo');
        $this->assertTrue($this->resolver->isDefined('foo'));
    }

    public function testLazyOptionsAreDefined()
    {
        $this->assertFalse($this->resolver->isDefined('foo'));
        $this->resolver->setDefault('foo', function DOptions $options) {});
        $this->assertTrue($this->resolver->isDefined('foo'));
    }

    

class OptionsResolverIntrospector
{
    private \Closure $get;

    public function __construct(OptionsResolver $optionsResolver)
    {
        $this->get = \Closure::bind(function D$property$option$message) {
            /** @var OptionsResolver $this */
            if (!$this->isDefined($option)) {
                throw new UndefinedOptionsException(sprintf('The option "%s" does not exist.', $option));
            }

            if (!\array_key_exists($option$this->{$property})) {
                throw new NoConfigurationException($message);
            }

            return $this->{$property}[$option];
        }$optionsResolver$optionsResolver);
    }

    
sort($options[$k]);
            }
        } else {
            if (!class_exists($class) || !is_subclass_of($class, FormTypeInterface::class)) {
                $class = $this->getFqcnTypeClass($input$io$class);
            }
            $resolvedType = $this->formRegistry->getType($class);

            if ($option = $input->getArgument('option')) {
                $object = $resolvedType->getOptionsResolver();

                if (!$object->isDefined($option)) {
                    $message = sprintf('Option "%s" is not defined in "%s".', $option$resolvedType->getInnerType()::class);

                    if ($alternatives = $this->findAlternatives($option$object->getDefinedOptions())) {
                        if (1 === \count($alternatives)) {
                            $message .= "\n\nDid you mean this?\n ";
                        } else {
                            $message .= "\n\nDid you mean one of these?\n ";
                        }
                        $message .= implode("\n ", $alternatives);
                    }

                    
Home | Imprint | This part of the site doesn't use cookies.