| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the Ivory Google Map bundle package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) Eric GELOEN <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * For the full copyright and license information, please read the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace Ivory\GoogleMapBundle\DependencyInjection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @author GeLo <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | class Configuration implements ConfigurationInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     public function getConfigTreeBuilder() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $treeBuilder = $this->createTreeBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $children = $treeBuilder->root('ivory_google_map') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             ->children() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             ->append($this->createMapNode()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             ->append($this->createStaticMapNode()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $services = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             'direction'          => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             'distance_matrix'    => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             'elevation'          => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             'geocoder'           => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             'place_autocomplete' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             'place_detail'       => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             'place_photo'        => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             'place_search'       => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             'time_zone'          => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         foreach ($services as $service => $http) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             $children->append($this->createServiceNode($service, $http)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         return $treeBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @return ArrayNodeDefinition | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 56 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |     private function createMapNode() | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |         return $this->createNode('map') | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |             ->addDefaultsIfNotSet() | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |             ->children() | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |                 ->booleanNode('debug')->defaultValue('%kernel.debug%')->end() | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |                 ->scalarNode('language')->defaultValue('%locale%')->end() | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |                 ->scalarNode('api_key')->end() | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |             ->end(); | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * @return ArrayNodeDefinition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     private function createStaticMapNode() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         return $this->createNode('static_map') | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             ->addDefaultsIfNotSet() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             ->children() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |                 ->scalarNode('api_key')->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |                 ->append($this->createBusinessAccountNode(false)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             ->end(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * @param string $service | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * @param bool   $http | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * @return ArrayNodeDefinition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     private function createServiceNode($service, $http) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $node = $this->createNode($service); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $children = $node | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             ->children() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             ->scalarNode('api_key')->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             ->append($this->createBusinessAccountNode(true)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         if ($http) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             $children | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |                 ->scalarNode('client') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |                     ->isRequired() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |                     ->cannotBeEmpty() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |                 ->scalarNode('message_factory') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |                     ->isRequired() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |                     ->cannotBeEmpty() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |                 ->scalarNode('format')->end(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |             $node | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |                 ->beforeNormalization() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |                     ->ifNull() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |                     ->then(function () { return []; }) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |                 ->end(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         return $node; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |      * @param bool $service | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |      * @return ArrayNodeDefinition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     private function createBusinessAccountNode($service) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         $node = $this->createNode('business_account'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         $clientIdNode = $node->children() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |             ->scalarNode('secret') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |                 ->isRequired() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |                 ->cannotBeEmpty() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |             ->scalarNode('channel')->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |             ->scalarNode('client_id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         if ($service) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |             $clientIdNode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |                 ->isRequired() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |                 ->cannotBeEmpty(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         return $node; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |      * @param string $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |      * @param string $type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |      * @return ArrayNodeDefinition|NodeDefinition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     private function createNode($name, $type = 'array') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |         return $this->createTreeBuilder()->root($name, $type); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |      * @return TreeBuilder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     private function createTreeBuilder() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |         return new TreeBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 160 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 161 |  |  |  | 
            
                        
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: