vendor/paymentsuite/paymentsuite/src/PaymentSuite/PaymentCoreBundle/DependencyInjection/Abstracts/AbstractPaymentSuiteConfiguration.php line 37

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the PaymentSuite package.
  4.  *
  5.  * Copyright (c) 2013-2016 Marc Morera
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  *
  10.  * Feel free to edit as you please, and have fun.
  11.  *
  12.  * @author Marc Morera <yuhu@mmoreram.com>
  13.  */
  14. namespace PaymentSuite\PaymentCoreBundle\DependencyInjection\Abstracts;
  15. use Symfony\Component\Config\Definition\Builder\NodeDefinition;
  16. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  17. use Symfony\Component\Config\Definition\ConfigurationInterface;
  18. /**
  19.  * Class AbstractPaymentSuiteConfiguration.
  20.  */
  21. abstract class AbstractPaymentSuiteConfiguration implements ConfigurationInterface
  22. {
  23.     /**
  24.      * Add a new success route in configuration.
  25.      *
  26.      * @param string $routeName Route name
  27.      *
  28.      * @return NodeDefinition Node
  29.      */
  30.     protected function addRouteConfiguration($routeName)
  31.     {
  32.         $builder = new TreeBuilder();
  33.         $node $builder->root($routeName);
  34.         $node
  35.             ->isRequired()
  36.             ->children()
  37.                 ->scalarNode('route')
  38.                     ->isRequired()
  39.                     ->cannotBeEmpty()
  40.                 ->end()
  41.                 ->booleanNode('order_append')
  42.                     ->defaultTrue()
  43.                 ->end()
  44.                 ->scalarNode('order_append_field')
  45.                     ->defaultValue('order_id')
  46.                 ->end()
  47.             ->end();
  48.         return $node;
  49.     }
  50.     /**
  51.      * Adds common configuration for every payment method given a root node.
  52.      *
  53.      * @param NodeDefinition $rootNode
  54.      */
  55.     final protected function addSettingsProviderConfiguration(NodeDefinition $rootNode): void
  56.     {
  57.         $rootNode
  58.             ->beforeNormalization()
  59.                 ->ifTrue(function ($v) {
  60.                     return isset($v['settings_provider']) && 'default' != $v['settings_provider'];
  61.                 })
  62.                 ->then(function ($v) {
  63.                     return static::setDefaultSettings($v);
  64.                 })
  65.             ->end()
  66.             ->children()
  67.                 ->scalarNode('settings_provider')
  68.                     ->defaultValue('default')
  69.                 ->end()
  70.             ->end();
  71.     }
  72.     /**
  73.      * Sets default values for required custom settings.
  74.      *
  75.      * @param array $config
  76.      *
  77.      * @return array
  78.      */
  79.     protected function setDefaultSettings(array $config): array
  80.     {
  81.         return $config;
  82.     }
  83. }