| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace App\Common\Config\Definition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Symfony\Component\Config\Definition\ConfigurationInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Symfony\Component\Config\Definition\Builder\TreeBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use App\Common\Acl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @inheritdoc | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | class AclConfigDefinition implements ConfigurationInterface | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |      * @inheritdoc | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     public function getConfigTreeBuilder() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         $treeBuilder = new TreeBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         $rootNode = $treeBuilder->root(null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         /* | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |          * verify the following structure | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |          *   return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |          *       'definition' => ACLConfigDefinition::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |          * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |          *       'acl' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |          *           'default_role' => 'guest', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |          * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |          *           'roles' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |          *               // role => [multiple parents specification as array] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |          *               'admin' => ['user'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |          *           ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |          * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |          *           'resources' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |          *              // resource => parent | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |          *           ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |          * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |          *           // where we specify the guarding! | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |          *           'guards' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |          * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |          *              Acl::GUARD_TYPE_RESOURCE => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |          * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |          *              ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |          * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |          *              Acl::GUARD_TYPE_ROUTE => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |          *                   // resource, [roles as array], [privileges as array] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |          *                   ['/api/token', ['guest'], [Acl::PRIVILEGE_POST]], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |          *              ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |          * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |          *              Acl::GUARD_TYPE_CALLABLE => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |          *                   // resource, [roles as array], [privileges as array] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |          *                   ['App\Controller\CrudController',              ['user']], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |          *              ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |          *           ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |          *       ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |          *   ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |          */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $rootNode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             ->children() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                 // 'definition' => ACLConfigDefinition::class, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |                 ->scalarNode('definition') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                     ->isRequired() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |                     ->cannotBeEmpty() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                 // 'acl' => [] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                 ->arrayNode('acl') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                     ->children() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |                         // 'default_role' => 'guest', | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                         ->scalarNode('default_role') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                             ->isRequired() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                             ->cannotBeEmpty() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |                         ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                         // 'roles' => [ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |                         //      'user'  => ['guest'], | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |                         //  ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |                         ->arrayNode('roles') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |                             ->useAttributeAsKey('name') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |                             ->prototype('array') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |                                 ->prototype('scalar') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |                             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                         ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |                         // 'resources' => [] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |                         ->arrayNode('resources') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |                             ->useAttributeAsKey('name') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |                             ->prototype('scalar') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |                             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |                         ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |                         // 'guards' => [] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |                         ->arrayNode('guards') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |                             ->children() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |                                 ->arrayNode(Acl::GUARD_TYPE_RESOURCE) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |                                     // ['user', ['admin']] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |                                     ->prototype('array') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |                                         ->children() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |                                             // 'user' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |                                             ->scalarNode(0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |                                             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |                                             // ['admin'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |                                             ->arrayNode(1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |                                                 ->prototype('scalar') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |                                                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |                                             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |                                         ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |                                     ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |                                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |                                 ->arrayNode(Acl::GUARD_TYPE_ROUTE) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |                                     // ['route', ['roles'], ['privilege1', 'privilege2']] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |                                     ->prototype('array') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |                                         ->children() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |                                             // 'route' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |                                             ->scalarNode(0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |                                             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |                                             // ['roles'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |                                             ->arrayNode(1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |                                                 ->prototype('scalar') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |                                                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |                                             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |                                             // ['privilege1', 'privilege2'] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |                                             ->arrayNode(2) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |                                                 ->prototype('scalar') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |                                                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |                                             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |                                         ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |                                     ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |                                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |                                 ->arrayNode(Acl::GUARD_TYPE_CALLABLE) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |                                     // ['callable', ['roles']] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |                                     ->prototype('array') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |                                         ->children() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |                                             // 'callable' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |                                             ->scalarNode(0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |                                             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |                                             // ['roles'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |                                             ->arrayNode(1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |                                                 ->prototype('scalar') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |                                                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |                                             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |                                         ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |                                     ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |                                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |                             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |                         ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |                     ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |                 ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |             ->end() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |         return $treeBuilder; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 159 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 160 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 161 |  |  |  | 
            
                        
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.