| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of ocubom/html-bundle | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * © Oscar Cubo Medina <https://ocubom.github.io> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace Ocubom\HtmlBundle\DependencyInjection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Symfony\Component\Config\Definition\Builder\TreeBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Symfony\Component\Config\Definition\ConfigurationInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | class Configuration implements ConfigurationInterface | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 19 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 20 | 2 |  |     public function getConfigTreeBuilder(): TreeBuilder | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 22 | 2 |  |         $builder = new TreeBuilder('ocubom_html'); | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 24 | 2 |  |         $root = $builder->getRootNode(); | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 26 | 2 |  |         $this->addHeadersSection($root); | 
            
                                                                        
                            
            
                                    
            
            
                | 27 | 2 |  |         $this->addHtmlCompressSection($root); | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 29 | 2 |  |         return $builder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 | 2 |  |     private function addHeadersSection(ArrayNodeDefinition $root): self | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 | 2 |  |         $root | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 2 |  |             ->fixXmlConfig('header') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 2 |  |             ->children() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 2 |  |                 ->arrayNode('headers') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 2 |  |                     ->info(implode("\n", [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 2 |  |                         'HTTP headers that must be set.', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 2 |  |                         'The listener will only be registered if at least one rule is enabled.', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 2 |  |                     ])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 2 |  |                     ->prototype('array') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 2 |  |                         ->fixXmlConfig('header') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 2 |  |                         ->treatFalseLike(['enabled' => false]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 2 |  |                         ->treatTrueLike(['enabled' => true]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 2 |  |                         ->treatNullLike(['enabled' => true]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 2 |  |                         ->children() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 2 |  |                             ->booleanNode('enabled') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 2 |  |                                 ->info('Apply this rule?') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 2 |  |                                 ->defaultTrue() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 2 |  |                             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 2 |  |                             ->scalarNode('name') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 2 |  |                                 ->info('The header name to be added.') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 2 |  |                                 ->example('X-UA-Compatible') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 2 |  |                                 ->isRequired() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 2 |  |                                 ->cannotBeEmpty() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 2 |  |                             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 2 |  |                             ->scalarNode('pattern') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 2 |  |                                 ->info('A regular expression to extract the header value.') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 2 |  |                                 ->example('@@[\p{Zs}]*<meta\s+(?:http-equiv="X-UA-Compatible"\s+content="([^"]+)"|content="([^"]+)"\s+http-equiv="X-UA-Compatible")\s*>\p{Zs}*\n?@i') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 2 |  |                                 ->isRequired() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 2 |  |                                 ->cannotBeEmpty() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 2 |  |                             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 2 |  |                             ->scalarNode('value') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 2 |  |                                 ->info('The format of the value (printf processed using the matched value).') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 2 |  |                                 ->example('%2$s') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 2 |  |                                 ->isRequired() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 2 |  |                                 ->cannotBeEmpty() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 2 |  |                             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 2 |  |                             ->scalarNode('replace') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 2 |  |                                 ->info('The text that replaces the match in the original (printf processed using the matched value).') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 2 |  |                                 // ->example('') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 2 |  |                                 ->defaultValue('%s') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 2 |  |                             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 2 |  |                             ->arrayNode('formats') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 2 |  |                                 ->info('The response formats when this replacement must be done.') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 2 |  |                                 ->example('["text/html"]') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 2 |  |                                 // ->addDefaultChildrenIfNoneSet() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 2 |  |                                 ->prototype('scalar') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 2 |  |                                     // ->defaultValue('text/html') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 2 |  |                                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 2 |  |                             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 2 |  |                         ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 | 2 |  |                     ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 2 |  |                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 | 2 |  |             ->end(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 | 2 |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 2 |  |     private function addHtmlCompressSection(ArrayNodeDefinition $root): self | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 | 2 |  |         $root | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 2 |  |             ->children() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 | 2 |  |                 ->arrayNode('compress') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 2 |  |                     ->addDefaultsIfNotSet() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 2 |  |                     ->children() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 | 2 |  |                         ->booleanNode('force') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 2 |  |                             ->info('Force compression?') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 | 2 |  |                             ->defaultFalse() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 2 |  |                         ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 | 2 |  |                         ->enumNode('level') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 2 |  |                             ->info('The level of compression to use') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 | 2 |  |                             ->defaultValue('smallest') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 | 2 |  |                             ->values(['none', 'fastest', 'normal', 'smallest']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 | 2 |  |                         ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 2 |  |                     ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 | 2 |  |                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 2 |  |             ->end(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 | 2 |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 113 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 114 |  |  |  |