vendor/winzou/state-machine-bundle/DependencyInjection/Configuration.php line 28

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the StateMachine package.
  4.  *
  5.  * (c) Alexandre Bacco
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace winzou\Bundle\StateMachineBundle\DependencyInjection;
  11. use Symfony\Component\Config\Definition\Builder\NodeBuilder;
  12. use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  13. use Symfony\Component\Config\Definition\ConfigurationInterface;
  14. class Configuration implements ConfigurationInterface
  15. {
  16.     /**
  17.      * {@inheritDoc}
  18.      */
  19.     public function getConfigTreeBuilder()
  20.     {
  21.         $treeBuilder = new TreeBuilder();
  22.         $configNode $treeBuilder
  23.             ->root('winzou_state_machine')
  24.             ->useAttributeAsKey('name')
  25.             ->prototype('array')
  26.             ->children()
  27.         ;
  28.         $configNode
  29.             ->scalarNode('class')->isRequired()->end()
  30.             ->scalarNode('graph')->defaultValue('default')->end()
  31.             ->scalarNode('property_path')->defaultValue('state')->end()
  32.             ->scalarNode('state_machine_class')->defaultValue('SM\\StateMachine\\StateMachine')->end()
  33.         ;
  34.         $this->addStateSection($configNode);
  35.         $this->addTransitionSection($configNode);
  36.         $this->addCallbackSection($configNode);
  37.         $configNode->end()->end();
  38.         return $treeBuilder;
  39.     }
  40.     /**
  41.      * @param NodeBuilder $configNode
  42.      */
  43.     protected function addStateSection(NodeBuilder $configNode)
  44.     {
  45.         $configNode
  46.             ->arrayNode('states')
  47.                 ->useAttributeAsKey('name')
  48.                 ->prototype('scalar')
  49.             ->end()
  50.         ;
  51.     }
  52.     /**
  53.      * @param NodeBuilder $configNode
  54.      */
  55.     protected function addTransitionSection(NodeBuilder $configNode)
  56.     {
  57.         $configNode
  58.             ->arrayNode('transitions')
  59.                 ->useAttributeAsKey('name')
  60.                 ->prototype('array')
  61.                     ->children()
  62.                         ->arrayNode('from')
  63.                             ->prototype('scalar')->end()
  64.                         ->end()
  65.                         ->scalarNode('to')->end()
  66.                     ->end()
  67.                 ->end()
  68.             ->end()
  69.         ;
  70.     }
  71.     /**
  72.      * @param NodeBuilder $configNode
  73.      */
  74.     protected function addCallbackSection(NodeBuilder $configNode)
  75.     {
  76.         $callbacks $configNode->arrayNode('callbacks')->children();
  77.         $this->addSubCallbackSection($callbacks'guard');
  78.         $this->addSubCallbackSection($callbacks'before');
  79.         $this->addSubCallbackSection($callbacks'after');
  80.         $callbacks->end()->end();
  81.     }
  82.     /**
  83.      * @param NodeBuilder $callbacks
  84.      * @param string      $type
  85.      */
  86.     protected function addSubCallbackSection(NodeBuilder $callbacks$type)
  87.     {
  88.         $callbacks
  89.             ->arrayNode($type)
  90.                 ->useAttributeAsKey('name')
  91.                 ->prototype('array')
  92.                     ->children()
  93.                         ->variableNode('on')->end()
  94.                         ->variableNode('from')->end()
  95.                         ->variableNode('to')->end()
  96.                         ->variableNode('excluded_on')->end()
  97.                         ->variableNode('excluded_from')->end()
  98.                         ->variableNode('excluded_to')->end()
  99.                         ->variableNode('do')->end()
  100.                         ->scalarNode('disabled')->defaultValue(false)->end()
  101.                         ->scalarNode('priority')->defaultValue(0)->end()
  102.                         ->arrayNode('args')->performNoDeepMerging()->prototype('scalar')->end()
  103.                     ->end()
  104.                 ->end()
  105.             ->end()
  106.         ;
  107.     }
  108. }