| 1 | <?php |
||
| 8 | use Symfony\Component\Config\Definition\ConfigurationInterface; |
||
| 9 | |||
| 10 | class Configuration implements ConfigurationInterface |
||
| 11 | { |
||
| 12 | public function getConfigTreeBuilder() |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @return ArrayNodeDefinition|NodeDefinition |
||
| 59 | */ |
||
| 60 | public function getAdminsConfigurationNode() |
||
| 61 | { |
||
| 62 | $builder = new TreeBuilder(); |
||
| 63 | $node = $builder->root('admins'); |
||
| 64 | |||
| 65 | $node |
||
|
1 ignored issue
–
show
|
|||
| 66 | ->prototype('array') |
||
| 67 | ->children() |
||
| 68 | ->scalarNode('entity')->end() |
||
| 69 | ->scalarNode('data_provider')->end() |
||
| 70 | ->scalarNode('form')->end() |
||
| 71 | ->scalarNode('max_per_page')->end() |
||
| 72 | ->scalarNode('controller')->defaultValue('LAGAdminBundle:CRUD')->end() |
||
| 73 | // actions configurations |
||
| 74 | ->arrayNode('actions') |
||
| 75 | ->useAttributeAsKey('name') |
||
| 76 | ->prototype('array') |
||
| 77 | ->children() |
||
| 78 | ->scalarNode('title')->end() |
||
| 79 | ->arrayNode('permissions') |
||
| 80 | ->defaultValue(['ROLE_USER']) |
||
| 81 | ->prototype('scalar')->end() |
||
| 82 | ->end() |
||
| 83 | ->arrayNode('export') |
||
| 84 | ->prototype('scalar')->end() |
||
| 85 | ->end() |
||
| 86 | ->arrayNode('order') |
||
| 87 | ->prototype('array') |
||
| 88 | ->children() |
||
| 89 | ->scalarNode('field')->end() |
||
| 90 | ->scalarNode('order')->end() |
||
| 91 | ->end() |
||
| 92 | ->end() |
||
| 93 | ->end() |
||
| 94 | ->arrayNode('fields') |
||
| 95 | ->prototype('array') |
||
| 96 | ->children() |
||
| 97 | ->scalarNode('type')->end() |
||
| 98 | ->arrayNode('options') |
||
| 99 | ->prototype('variable')->end() |
||
| 100 | ->end() |
||
| 101 | ->end() |
||
| 102 | ->end() |
||
| 103 | ->end() |
||
| 104 | ->arrayNode('filters') |
||
| 105 | ->prototype('scalar')->end() |
||
| 106 | ->end() |
||
| 107 | ->arrayNode('batch') |
||
| 108 | ->prototype('variable')->end() |
||
| 109 | ->end() |
||
| 110 | ->arrayNode('actions') |
||
| 111 | ->prototype('array') |
||
| 112 | ->children() |
||
| 113 | ->scalarNode('title')->end() |
||
| 114 | ->scalarNode('route')->end() |
||
| 179 |
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: