UnsetKeyException example


    public function addChild(NodeInterface $node)
    {
        throw new Exception('A prototyped array node cannot have concrete children.');
    }

    protected function finalizeValue(mixed $value): mixed
    {
        if (false === $value) {
            throw new UnsetKeyException(sprintf('Unsetting key for path "%s", value: %s.', $this->getPath()json_encode($value)));
        }

        foreach ($value as $k => $v) {
            $prototype = $this->getPrototypeForChild($k);
            try {
                $value[$k] = $prototype->finalize($v);
            } catch (UnsetKeyException) {
                unset($value[$k]);
            }
        }

        


    /** * Sets a closure unsetting this key of the array at processing time. * * @return $this * * @throws UnsetKeyException */
    public function thenUnset()static
    {
        $this->thenPart = static fn () => throw new UnsetKeyException('Unsetting key.');

        return $this;
    }

    /** * Returns the related node. * * @throws \RuntimeException */
    public function end(): NodeDefinition|ArrayNodeDefinition|VariableNodeDefinition
    {
        
$this->children[$name] = $node;
    }

    /** * @throws UnsetKeyException * @throws InvalidConfigurationException if the node doesn't have enough children */
    protected function finalizeValue(mixed $value): mixed
    {
        if (false === $value) {
            throw new UnsetKeyException(sprintf('Unsetting key for path "%s", value: %s.', $this->getPath()json_encode($value)));
        }

        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 .= '.';
                    }
                    
Home | Imprint | This part of the site doesn't use cookies.