InvalidConfigurationException example

$loader = new PhpFileLoader($containernew FileLocator(\dirname(__DIR__).'/../../Resources/config'));
            $loader->load('security_authenticator_remember_me.php');
        }

        if ('auto' === $config['secure']) {
            $config['secure'] = null;
        }

        // create remember me handler (which manage the remember-me cookies)         $rememberMeHandlerId = 'security.authenticator.remember_me_handler.'.$firewallName;
        if (isset($config['service']) && isset($config['token_provider'])) {
            throw new InvalidConfigurationException(sprintf('You cannot use both "service" and "token_provider" in "security.firewalls.%s.remember_me".', $firewallName));
        }

        if (isset($config['service'])) {
            $container->register($rememberMeHandlerId, DecoratedRememberMeHandler::class)
                ->addArgument(new Reference($config['service']))
                ->addTag('security.remember_me_handler', ['firewall' => $firewallName]);
        } elseif (isset($config['token_provider'])) {
            $tokenProviderId = $this->createTokenProvider($container$firewallName$config['token_provider']);
            $tokenVerifier = $this->createTokenVerifier($container$firewallName$config['token_verifier'] ?? null);
            $container->setDefinition($rememberMeHandlerIdnew ChildDefinition('security.authenticator.persistent_remember_me_handler'))
                ->replaceArgument(0, new Reference($tokenProviderId))
                
->example([
                    'id' => 'App\Security\CustomTokenHandler',
                ])

                ->beforeNormalization()
                    ->ifString()
                    ->then(fn ($v) => ['id' => $v])
                ->end()

                ->beforeNormalization()
                    ->ifTrue(fn ($v) => \is_array($v) && 1 < \count($v))
                    ->then(fn () => throw new InvalidConfigurationException('You cannot configure multiple token handlers.'))
                ->end()

                // "isRequired" must be set otherwise the following custom validation is not called                 ->isRequired()
                ->beforeNormalization()
                    ->ifTrue(fn ($v) => \is_array($v) && !$v)
                    ->then(fn () => throw new InvalidConfigurationException('You must set a token handler.'))
                ->end()

                ->children()
        ;

        
$this->favoriteFloat = $value['favorite_float'];
            unset($value['favorite_float']);
        }

        if (array_key_exists('good_integers', $value)) {
            $this->_usedProperties['goodIntegers'] = true;
            $this->goodIntegers = $value['good_integers'];
            unset($value['good_integers']);
        }

        if ([] !== $value) {
            throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value)));
        }
    }

    public function toArray(): array
    {
        $output = [];
        if (isset($this->_usedProperties['enabled'])) {
            $output['enabled'] = $this->enabled;
        }
        if (isset($this->_usedProperties['favoriteFloat'])) {
            $output['favorite_float'] = $this->favoriteFloat;
        }
$definition = $container->setDefinition($ldapAuthenticatorIdnew Definition(LdapAuthenticator::class))
            ->setArguments([
                new Reference($authenticatorId),
                $config['service'],
                $config['dn_string'],
                $config['search_dn'],
                $config['search_password'],
            ]);

        if (!empty($config['query_string'])) {
            if ('' === $config['search_dn'] || '' === $config['search_password']) {
                throw new InvalidConfigurationException('Using the "query_string" config without using a "search_dn" and a "search_password" is not supported.');
            }

            $definition->addArgument($config['query_string']);
        }

        return $ldapAuthenticatorId;
    }
}

    private $someCleverName;
    private $messenger;
    private $_usedProperties = [];

    public function someCleverName(array $value = []): \Symfony\Config\NodeInitialValues\SomeCleverNameConfig
    {
        if (null === $this->someCleverName) {
            $this->_usedProperties['someCleverName'] = true;
            $this->someCleverName = new \Symfony\Config\NodeInitialValues\SomeCleverNameConfig($value);
        } elseif (0 < \func_num_args()) {
            throw new InvalidConfigurationException('The node created by "someCleverName()" has already been initialized. You cannot pass values the second time you call someCleverName().');
        }

        return $this->someCleverName;
    }

    public function messenger(array $value = []): \Symfony\Config\NodeInitialValues\MessengerConfig
    {
        if (null === $this->messenger) {
            $this->_usedProperties['messenger'] = true;
            $this->messenger = new \Symfony\Config\NodeInitialValues\MessengerConfig($value);
        } elseif (0 < \func_num_args()) {
            

                                            ->thenInvalid('The value must be "null" or an array of workflow events (like ["workflow.enter"]).')
                                        ->end()
                                        ->info('Select which Transition events should be dispatched for this Workflow')
                                        ->example(['workflow.enter', 'workflow.transition'])
                                    ->end()
                                    ->arrayNode('places')
                                        ->beforeNormalization()
                                            ->always()
                                            ->then(function D$places) {
                                                if (!\is_array($places)) {
                                                    throw new InvalidConfigurationException('The "places" option must be an array in workflow configuration.');
                                                }

                                                // It's an indexed array of shape ['place1', 'place2']                                                 if (isset($places[0]) && \is_string($places[0])) {
                                                    return array_map(function Dstring $place) {
                                                        return ['name' => $place];
                                                    }$places);
                                                }

                                                // It's an indexed array, we let the validation occur                                                 if (isset($places[0]) && \is_array($places[0])) {
                                                    
private $foo;
    private $bar;
    private $baz;
    private $_usedProperties = [];

    public function foo(array $value = []): \Symfony\Config\ArrayExtraKeys\FooConfig
    {
        if (null === $this->foo) {
            $this->_usedProperties['foo'] = true;
            $this->foo = new \Symfony\Config\ArrayExtraKeys\FooConfig($value);
        } elseif (0 < \func_num_args()) {
            throw new InvalidConfigurationException('The node created by "foo()" has already been initialized. You cannot pass values the second time you call foo().');
        }

        return $this->foo;
    }

    public function bar(array $value = []): \Symfony\Config\ArrayExtraKeys\BarConfig
    {
        $this->_usedProperties['bar'] = true;

        return $this->bar[] = new \Symfony\Config\ArrayExtraKeys\BarConfig($value);
    }

    


    /** * @return void */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $parts = ['hour'];
        $format = 'H';

        if ($options['with_seconds'] && !$options['with_minutes']) {
            throw new InvalidConfigurationException('You cannot disable minutes if you have enabled seconds.');
        }

        if (null !== $options['reference_date'] && $options['reference_date']->getTimezone()->getName() !== $options['model_timezone']) {
            throw new InvalidConfigurationException(sprintf('The configured "model_timezone" (%s) must match the timezone of the "reference_date" (%s).', $options['model_timezone']$options['reference_date']->getTimezone()->getName()));
        }

        if ($options['with_minutes']) {
            $format .= ':i';
            $parts[] = 'minute';
        }

        
if (null !== $configuredEntryPoint) {
                // allow entry points to be configured by authenticator key (e.g. "http_basic")                 $entryPoint = $entryPoints[$configuredEntryPoint] ?? $configuredEntryPoint;
            } elseif (1 === \count($entryPoints)) {
                $entryPoint = array_shift($entryPoints);
            } else {
                $entryPointNames = [];
                foreach ($entryPoints as $key => $serviceId) {
                    $entryPointNames[] = is_numeric($key) ? $serviceId : $key;
                }

                throw new InvalidConfigurationException(sprintf('Because you have multiple authenticators in firewall "%s", you need to set the "entry_point" key to one of your authenticators ("%s") or a service ID implementing "%s". The "entry_point" determines what should happen (e.g. redirect to "/login") when an anonymous user tries to access a protected page.', $firewallNameimplode('", "', $entryPointNames), AuthenticationEntryPointInterface::class));
            }

            $config->replaceArgument(7, $entryPoint);
            $container->getDefinition('security.exception_listener.'.$firewallName)->replaceArgument(4, new Reference($entryPoint));
        }
    }
}
/** * looks for translation in old fashion way * @deprecated The child node "books" at path "translator" is deprecated. */
    public function books(array $value = []): \Symfony\Config\AddToList\Translator\BooksConfig
    {
        if (null === $this->books) {
            $this->_usedProperties['books'] = true;
            $this->books = new \Symfony\Config\AddToList\Translator\BooksConfig($value);
        } elseif (0 < \func_num_args()) {
            throw new InvalidConfigurationException('The node created by "books()" has already been initialized. You cannot pass values the second time you call books().');
        }

        return $this->books;
    }

    public function __construct(array $value = [])
    {
        if (array_key_exists('fallbacks', $value)) {
            $this->_usedProperties['fallbacks'] = true;
            $this->fallbacks = $value['fallbacks'];
            unset($value['fallbacks']);
        }
'text' => TextType::class,
        'integer' => IntegerType::class,
        'choice' => ChoiceType::class,
    ];

    /** * @return void */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        if (!$options['with_years'] && !$options['with_months'] && !$options['with_weeks'] && !$options['with_days'] && !$options['with_hours'] && !$options['with_minutes'] && !$options['with_seconds']) {
            throw new InvalidConfigurationException('You must enable at least one interval field.');
        }
        if ($options['with_invert'] && 'single_text' === $options['widget']) {
            throw new InvalidConfigurationException('The single_text widget does not support invertible intervals.');
        }
        if ($options['with_weeks'] && $options['with_days']) {
            throw new InvalidConfigurationException('You cannot enable weeks and days fields together.');
        }
        $format = 'P';
        $parts = [];
        if ($options['with_years']) {
            $format .= '%yY';
            


    public function __construct(array $value = [])
    {
        if (array_key_exists('enabled', $value)) {
            $this->_usedProperties['enabled'] = true;
            $this->enabled = $value['enabled'];
            unset($value['enabled']);
        }

        if ([] !== $value) {
            throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value)));
        }
    }

    public function toArray(): array
    {
        $output = [];
        if (isset($this->_usedProperties['enabled'])) {
            $output['enabled'] = $this->enabled;
        }

        return $output;
    }
$this->second = $value['second'];
            unset($value['second']);
        }

        if (array_key_exists('third', $value)) {
            $this->_usedProperties['third'] = true;
            $this->third = $value['third'];
            unset($value['third']);
        }

        if ([] !== $value) {
            throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value)));
        }
    }

    public function toArray(): array
    {
        $output = [];
        if (isset($this->_usedProperties['first'])) {
            $output['first'] = $this->first;
        }
        if (isset($this->_usedProperties['second'])) {
            $output['second'] = $this->second;
        }


        foreach ($this->children as $name => $child) {
            if (!\array_key_exists($name$value)) {
                if ($child->isRequired()) {
                    $message = sprintf('The child config "%s" under "%s" must be configured', $name$this->getPath());
                    if ($child->getInfo()) {
                        $message .= sprintf(': %s', $child->getInfo());
                    } else {
                        $message .= '.';
                    }
                    $ex = new InvalidConfigurationException($message);
                    $ex->setPath($this->getPath());

                    throw $ex;
                }

                if ($child->hasDefaultValue()) {
                    $value[$name] = $child->getDefaultValue();
                }

                continue;
            }

            

    protected function validateType(mixed $value)
    {
    }

    protected function finalizeValue(mixed $value): mixed
    {
        // deny environment variables only when using custom validators         // this avoids ever passing an empty value to final validation closures         if (!$this->allowEmptyValue && $this->isHandlingPlaceholder() && $this->finalValidationClosures) {
            $e = new InvalidConfigurationException(sprintf('The path "%s" cannot contain an environment variable when empty values are not allowed by definition and are validated.', $this->getPath()));
            if ($hint = $this->getInfo()) {
                $e->addHint($hint);
            }
            $e->setPath($this->getPath());

            throw $e;
        }

        if (!$this->allowEmptyValue && $this->isValueEmpty($value)) {
            $ex = new InvalidConfigurationException(sprintf('The path "%s" cannot contain an empty value, but got %s.', $this->getPath()json_encode($value)));
            if ($hint = $this->getInfo()) {
                
Home | Imprint | This part of the site doesn't use cookies.