| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * This file is part of the ekino Drupal Debug project. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * (c) ekino | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | namespace Ekino\Drupal\Debug\Configuration; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Ekino\Drupal\Debug\ActionMetadata\Model\ActionMetadata; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Ekino\Drupal\Debug\ActionMetadata\Model\ActionWithOptionsMetadata; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Ekino\Drupal\Debug\Configuration\Model\DefaultsConfiguration as DefaultsConfigurationModel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Symfony\Component\Config\Definition\Builder\TreeBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | class ActionsConfiguration extends AbstractConfiguration | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     public const ROOT_KEY = 'actions'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @var ActionMetadata[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     private $actionsMetadata; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     private $defaultsConfiguration; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @param ActionMetadata[]           $actionsMetadata | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @param DefaultsConfigurationModel $defaultsConfiguration | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 37 | 19 |  |     public function __construct(array $actionsMetadata, DefaultsConfigurationModel $defaultsConfiguration) | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 39 | 19 |  |         $this->actionsMetadata = $actionsMetadata; | 
            
                                                                        
                            
            
                                    
            
            
                | 40 | 19 |  |         $this->defaultsConfiguration = $defaultsConfiguration; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 19 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 19 |  |     public function getArrayNodeDefinition(TreeBuilder $treeBuilder): ArrayNodeDefinition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         /** @var ArrayNodeDefinition $rootNode */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 19 |  |         $rootNode = $treeBuilder->root(self::ROOT_KEY); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $nodeBuilder = $rootNode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 19 |  |             ->addDefaultsIfNotSet() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 19 |  |             ->children(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 19 |  |         foreach ($this->actionsMetadata as $actionMetadata) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             $childrenNodeBuilder = $nodeBuilder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 19 |  |                 ->arrayNode($actionMetadata->getShortName()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 19 |  |                     ->canBeDisabled() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 19 |  |                     ->children(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 19 |  |             if ($actionMetadata instanceof ActionWithOptionsMetadata) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 19 |  |                 $actionMetadata->getOptionsClass()::addConfiguration($childrenNodeBuilder, $this->defaultsConfiguration); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             $childrenNodeBuilder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 19 |  |                 ->end(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $rootNode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 19 |  |             ->end(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 19 |  |         return $rootNode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 73 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |  |