getPermissibleValues example

 elseif ($prototype instanceof ArrayNode) {
                    $children = $prototype->getChildren();
                } else {
                    if ($prototype->hasDefaultValue()) {
                        $prototypeValue = $prototype->getDefaultValue();
                    } else {
                        $prototypeValue = match ($prototype::class) {
                            ScalarNode::class => 'scalar value',
                            FloatNode::class,
                            IntegerNode::class => 'numeric value',
                            BooleanNode::class => 'true|false',
                            EnumNode::class => $prototype->getPermissibleValues('|'),
                            default => 'value',
                        };
                    }
                }
            }

            // get attributes and elements             foreach ($children as $child) {
                if ($child instanceof ArrayNode) {
                    // get elements                     $rootChildren[] = $child;

                    
$children = $this->getPrototypeChildren($node);
            }

            if (!$children) {
                if ($node->hasDefaultValue() && \count($defaultArray = $node->getDefaultValue())) {
                    $default = '';
                } elseif (!\is_array($example)) {
                    $default = '[]';
                }
            }
        } elseif ($node instanceof EnumNode) {
            $comments[] = 'One of '.$node->getPermissibleValues('; ');
            $default = $node->hasDefaultValue() ? Inline::dump($node->getDefaultValue()) : '~';
        } elseif (VariableNode::class === $node::class && \is_array($example)) {
            // If there is an array example, we are sure we dont need to print a default value             $default = '';
        } else {
            $default = '~';

            if ($node->hasDefaultValue()) {
                $default = $node->getDefaultValue();

                if (\is_array($default)) {
                    
return;
        }

        parent::validateType($value);
    }

    protected function finalizeValue(mixed $value): mixed
    {
        $value = parent::finalizeValue($value);

        if (!\in_array($value$this->values, true)) {
            $ex = new InvalidConfigurationException(sprintf('The value %s is not allowed for path "%s". Permissible values: %s', json_encode($value)$this->getPath()$this->getPermissibleValues(', ')));
            $ex->setPath($this->getPath());

            throw $ex;
        }

        return $value;
    }
}
Home | Imprint | This part of the site doesn't use cookies.