| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the pixelart Swiftmailer manipulator bundle. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) pixelart GmbH | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 Pixelart\Bundle\SwiftmailerManipulatorBundle\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 | 100 |  |     public function getConfigTreeBuilder() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 | 100 |  |         $treeBuilder = new TreeBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 | 100 |  |         $rootNode = $treeBuilder->root('pixelart_swiftmailer_manipulator'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $rootNode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 | 100 |  |             ->beforeNormalization() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |                 ->ifTrue(function ($v) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 | 100 |  |                     return is_array($v) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 100 |  |                         && count($v) > 0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 100 |  |                         && !array_key_exists('mailers', $v) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 100 |  |                         && !array_key_exists('mailer', $v) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 | 60 |  |                     ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 100 |  |                 }) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 | 100 |  |                 ->then(function (array $v) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 45 |  |                     $mailer = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 45 |  |                     foreach ($v as $key => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 45 |  |                         $mailer[$key] = $v[$key]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 45 |  |                         unset($v[$key]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 27 |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 45 |  |                     $v['mailers'] = ['default' => $mailer]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 45 |  |                     return $v; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 100 |  |                 }) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 100 |  |             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 100 |  |             ->children() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 100 |  |                 ->append($this->getMailersNode()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 100 |  |             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 100 |  |             ->fixXmlConfig('mailer') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 100 |  |         return $treeBuilder; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 53 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |      * Return the mailers node. | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |      * @return ArrayNodeDefinition | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 100 |  |     private function getMailersNode() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 100 |  |         $treeBuilder = new TreeBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 100 |  |         $node = $treeBuilder->root('mailers'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $node | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 100 |  |             ->requiresAtLeastOneElement() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 100 |  |             ->useAttributeAsKey('name') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 100 |  |                 ->prototype('array') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 100 |  |             ->children() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 100 |  |                 ->scalarNode('prepend_subject') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 100 |  |                     ->info('String which is prepended onto the subject') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 100 |  |                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 100 |  |                 ->scalarNode('prepend_body') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 100 |  |                     ->info('Path to template which is prepended onto the mail body') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 100 |  |                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 100 |  |                 ->scalarNode('from_address') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 100 |  |                     ->info('The address message should be sent from') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 100 |  |                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 100 |  |             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 100 |  |         return $node; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 84 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 85 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 86 |  |  |  |