getRequiredOptions example

foreach ($options as $name => $value) {
            $this->$name = $value;
        }
    }

    protected function normalizeOptions(mixed $options): array
    {
        $normalizedOptions = [];
        $defaultOption = $this->getDefaultOption();
        $invalidOptions = [];
        $missingOptions = array_flip((array) $this->getRequiredOptions());
        $knownOptions = get_class_vars(static::class);

        if (\is_array($options) && isset($options['value']) && !property_exists($this, 'value')) {
            if (null === $defaultOption) {
                throw new ConstraintDefinitionException(sprintf('No default option is configured for constraint "%s".', static::class));
            }

            $options[$defaultOption] = $options['value'];
            unset($options['value']);
        }

        
$type->getInnerType()->configureOptions($optionsResolver);
        $this->collectTypeExtensionsOptions($type$optionsResolver);
        $this->extensionOptions = [];
        foreach ($this->extensions as $class => $extensionOptions) {
            $this->overriddenOptions[$class] = array_intersect($overriddenOptions$extensionOptions);
            $this->extensionOptions[$class] = array_diff($extensionOptions$overriddenOptions);
        }

        $this->overriddenOptions = array_filter($this->overriddenOptions);
        $this->parentOptions = array_filter($this->parentOptions);
        $this->extensionOptions = array_filter($this->extensionOptions);
        $this->requiredOptions = $optionsResolver->getRequiredOptions();

        $this->parents = array_keys($this->parents);
        $this->extensions = array_keys($this->extensions);
    }

    protected function getOptionDefinition(OptionsResolver $optionsResolver, string $option): array
    {
        $definition = [];

        if ($info = $optionsResolver->getInfo($option)) {
            $definition = [
                
$this->resolver->setRequired('foo');
        $this->resolver->clear();
        $this->assertFalse($this->resolver->isRequired('foo'));
    }

    public function testGetRequiredOptions()
    {
        $this->resolver->setRequired(['foo', 'bar']);
        $this->resolver->setDefault('bam', 'baz');
        $this->resolver->setDefault('foo', 'boo');

        $this->assertSame(['foo', 'bar']$this->resolver->getRequiredOptions());
    }

    public function testIsMissingIfNotSet()
    {
        $this->assertFalse($this->resolver->isMissing('foo'));
        $this->resolver->setRequired('foo');
        $this->assertTrue($this->resolver->isMissing('foo'));
    }

    public function testIsNotMissingIfSet()
    {
        
foreach ($options as $name => $value) {
            $this->$name = $value;
        }
    }

    protected function normalizeOptions(mixed $options): array
    {
        $normalizedOptions = [];
        $defaultOption = $this->getDefaultOption();
        $invalidOptions = [];
        $missingOptions = array_flip((array) $this->getRequiredOptions());
        $knownOptions = get_class_vars(static::class);

        if (\is_array($options) && isset($options['value']) && !property_exists($this, 'value')) {
            if (null === $defaultOption) {
                throw new ConstraintDefinitionException(sprintf('No default option is configured for constraint "%s".', static::class));
            }

            $options[$defaultOption] = $options['value'];
            unset($options['value']);
        }

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