finalize example

$options = [
            'require_previous_session' => true,
        ];

        $factory = new StubFactory();
        $nodeDefinition = new ArrayNodeDefinition('root');
        $factory->addConfiguration($nodeDefinition);

        $node = $nodeDefinition->getNode();
        $normalizedConfig = $node->normalize($options);

        $node->finalize($normalizedConfig);
    }

    public static function getSuccessHandlers()
    {
        return [
            [null, true],
            ['custom_success_handler', false],
        ];
    }

    protected function callFactory(string $firewallName, array $config, string $userProviderId, string $defaultEntryPointId)
    {
$deprecationTriggered = 0;
        $deprecationHandler = function D$level$message$file$line) use (&$prevErrorHandler, &$deprecationTriggered) {
            if (\E_USER_DEPRECATED === $level) {
                return ++$deprecationTriggered;
            }

            return $prevErrorHandler ? $prevErrorHandler($level$message$file$line) : false;
        };

        $prevErrorHandler = set_error_handler($deprecationHandler);
        try {
            $node->finalize([]);
        } finally {
            restore_error_handler();
        }
        $this->assertSame(0, $deprecationTriggered, '->finalize() should not trigger if the deprecated node is not set');

        $prevErrorHandler = set_error_handler($deprecationHandler);
        try {
            $node->finalize(['foo' => '']);
        } finally {
            restore_error_handler();
        }
        


    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]);
            }
        }

        if (\count($value) < $this->minNumberOfElements) {
            $ex = new InvalidConfigurationException(sprintf('The path "%s" should have at least %d element(s) defined.', $this->getPath()$this->minNumberOfElements));
            $ex->setPath($this->getPath());

            throw $ex;
        }

        
return $retVal;
    }

    /** * Frees the current result. * * @return void */
    public function freeResult()
    {
        if (is_object($this->resultID)) {
            $this->resultID->finalize();
            $this->resultID = false;
        }
    }

    /** * Moves the internal pointer to the desired offset. This is called * internally before fetching results to make sure the result set * starts at zero. * * @return bool * * @throws DatabaseException */
$this->processConfig($config$factory);
    }

    private function processConfig(array $config, AccessTokenFactory $factory)
    {
        $nodeDefinition = new ArrayNodeDefinition('access_token');
        $factory->addConfiguration($nodeDefinition);

        $node = $nodeDefinition->getNode();
        $normalizedConfig = $node->normalize($config);

        return $node->finalize($normalizedConfig);
    }

    private function createTokenHandlerFactories(): array
    {
        return [
            new ServiceTokenHandlerFactory(),
            new OidcUserInfoTokenHandlerFactory(),
            new OidcTokenHandlerFactory(),
        ];
    }
}
$transactionId = $token->getTransactionId();

        if ($transactionId === null || !Uuid::isValid($transactionId)) {
            throw PaymentException::asyncProcessInterrupted((string) $transactionId, 'Payment JWT didn\'t contain a valid orderTransactionId');
        }

        $transaction = $this->getPaymentTransactionStruct($transactionId$context);

        $paymentHandler = $this->getPaymentHandlerById($token->getPaymentMethodId());

        try {
            $paymentHandler->finalize($transaction$request$context);
        } catch (CustomerCanceledAsyncPaymentException|PaymentException $e) {
            if ($e->getErrorCode() === PaymentException::PAYMENT_CUSTOMER_CANCELED_EXTERNAL) {
                $this->transactionStateHandler->cancel($transactionId$context->getContext());
            } else {
                $this->logger->error('An error occurred during finalizing async payment', ['orderTransactionId' => $transactionId, 'exceptionMessage' => $e->getMessage()]);
                $this->transactionStateHandler->fail($transactionId$context->getContext());
            }
            $token->setException($e);
        } finally {
            if ($token->getToken() !== null) {
                $this->tokenFactory->invalidateToken($token->getToken());
            }


                continue;
            }

            if ($child->isDeprecated()) {
                $deprecation = $child->getDeprecation($name$this->getPath());
                trigger_deprecation($deprecation['package']$deprecation['version']$deprecation['message']);
            }

            try {
                $value[$name] = $child->finalize($value[$name]);
            } catch (UnsetKeyException) {
                unset($value[$name]);
            }
        }

        return $value;
    }

    /** * @return void */
    

    public function process(NodeInterface $configTree, array $configs): array
    {
        $currentConfig = [];
        foreach ($configs as $config) {
            $config = $configTree->normalize($config);
            $currentConfig = $configTree->merge($currentConfig$config);
        }

        return $configTree->finalize($currentConfig);
    }

    /** * Processes an array of configurations. * * @param array $configs An array of configuration items to process */
    public function processConfiguration(ConfigurationInterface $configuration, array $configs): array
    {
        return $this->process($configuration->getConfigTreeBuilder()->buildTree()$configs);
    }

    

    /** * Sends the output to the browser. * * @return $this */
    public function send()
    {
        // If we're enforcing a Content Security Policy,         // we need to give it a chance to build out it's headers.         if ($this->CSP->enabled()) {
            $this->CSP->finalize($this);
        } else {
            $this->body = str_replace(['{csp-style-nonce}', '{csp-script-nonce}'], '', $this->body ?? '');
        }

        $this->sendHeaders();
        $this->sendCookies();
        $this->sendBody();

        return $this;
    }

    
'enabled' => false, 'foo' => 'bar'][false], 'false disables an enableable node'],
        ];
    }

    public function testRequiresAtLeastOneElement()
    {
        $node = new ArrayNodeDefinition('root');
        $node
            ->requiresAtLeastOneElement()
            ->integerPrototype();

        $node->getNode()->finalize([1]);

        $this->addToAssertionCount(1);
    }

    public function testCannotBeEmpty()
    {
        $this->expectException(InvalidConfigurationException::class);
        $this->expectExceptionMessage('The path "root" should have at least 1 element(s) defined.');
        $node = new ArrayNodeDefinition('root');
        $node
            ->cannotBeEmpty()
            
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\EnumNode;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Tests\Fixtures\TestEnum;
use Symfony\Component\Config\Tests\Fixtures\TestEnum2;

class EnumNodeTest extends TestCase
{
    public function testFinalizeValue()
    {
        $node = new EnumNode('foo', null, ['foo', 'bar', TestEnum::Bar]);
        $this->assertSame('foo', $node->finalize('foo'));
        $this->assertSame(TestEnum::Bar, $node->finalize(TestEnum::Bar));
    }

    public function testConstructionWithNoValues()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('$values must contain at least one element.');
        new EnumNode('foo', null, []);
    }

    public function testConstructionWithOneValue()
    {
$deprecationTriggered = false;
        $deprecationHandler = function D$level$message$file$line) use (&$prevErrorHandler, &$deprecationTriggered) {
            if (\E_USER_DEPRECATED === $level) {
                return $deprecationTriggered = true;
            }

            return $prevErrorHandler ? $prevErrorHandler($level$message$file$line) : false;
        };

        $prevErrorHandler = set_error_handler($deprecationHandler);
        try {
            $node->finalize([]);
        } finally {
            restore_error_handler();
        }
        $this->assertFalse($deprecationTriggered, '->finalize() should not trigger if the deprecated node is not set');

        $prevErrorHandler = set_error_handler($deprecationHandler);
        try {
            $node->finalize(['foo' => []]);
        } finally {
            restore_error_handler();
        }
        
$this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('You cannot define a max(2) as you already have a min(3)');
        $node = new IntegerNodeDefinition('foo');
        $node->min(3)->max(2);
    }

    public function testIntegerMinAssertion()
    {
        $this->expectException(InvalidConfigurationException::class);
        $this->expectExceptionMessage('The value 4 is too small for path "foo". Should be greater than or equal to 5');
        $def = new IntegerNodeDefinition('foo');
        $def->min(5)->getNode()->finalize(4);
    }

    public function testIntegerMaxAssertion()
    {
        $this->expectException(InvalidConfigurationException::class);
        $this->expectExceptionMessage('The value 4 is too big for path "foo". Should be less than or equal to 3');
        $def = new IntegerNodeDefinition('foo');
        $def->max(3)->getNode()->finalize(4);
    }

    public function testIntegerValidMinMaxAssertion()
    {
$this->assertTrue($container->hasDefinition('security.authenticator.login_link_handler.firewall1'));
    }

    private function processConfig(array $config, LoginLinkFactory $factory)
    {
        $nodeDefinition = new ArrayNodeDefinition('login-link');
        $factory->addConfiguration($nodeDefinition);

        $node = $nodeDefinition->getNode();
        $normalizedConfig = $node->normalize($config);

        return $node->finalize($normalizedConfig);
    }
}
public function getParent(): ?NodeInterface
    {
        return $this->parent;
    }

    final public function finalize(mixed $value): mixed
    {
        if ($value !== $placeholders = self::resolvePlaceholderValue($value)) {
            foreach ($placeholders as $placeholder) {
                $this->handlingPlaceholder = $value;
                try {
                    $this->finalize($placeholder);
                } finally {
                    $this->handlingPlaceholder = null;
                }
            }

            return $value;
        }

        $this->doValidateType($value);

        $value = $this->finalizeValue($value);

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