1 | <?php |
||
22 | class Configuration implements ConfigurationInterface |
||
23 | { |
||
24 | /** |
||
25 | * Whether to use the debug mode. |
||
26 | * |
||
27 | * @see https://github.com/doctrine/DoctrineBundle/blob/v1.5.2/DependencyInjection/Configuration.php#L31-L41 |
||
28 | * |
||
29 | * @var bool |
||
30 | */ |
||
31 | private $debug; |
||
32 | |||
33 | /** |
||
34 | * @param bool $debug |
||
35 | */ |
||
36 | 30 | public function __construct($debug) |
|
40 | |||
41 | /** |
||
42 | * Proxy to get root node for Symfony < 4.2. |
||
43 | * |
||
44 | * @param TreeBuilder $treeBuilder |
||
45 | * @param string $name |
||
46 | * |
||
47 | * @return NodeDefinition |
||
48 | */ |
||
49 | 30 | protected function getRootNode(TreeBuilder $treeBuilder, string $name) |
|
57 | |||
58 | /** |
||
59 | * Generates the configuration tree builder. |
||
60 | * |
||
61 | * @return TreeBuilder The tree builder |
||
62 | */ |
||
63 | 30 | public function getConfigTreeBuilder() |
|
64 | { |
||
65 | 30 | $treeBuilder = new TreeBuilder('bazinga_geocoder'); |
|
66 | |||
67 | 30 | $this->getRootNode($treeBuilder, 'bazinga_geocoder') |
|
68 | 30 | ->children() |
|
69 | 30 | ->append($this->getProvidersNode()) |
|
70 | 30 | ->arrayNode('profiling') |
|
71 | 30 | ->addDefaultsIfNotSet() |
|
72 | 30 | ->treatFalseLike(['enabled' => false]) |
|
73 | 30 | ->treatTrueLike(['enabled' => true]) |
|
74 | 30 | ->treatNullLike(['enabled' => $this->debug]) |
|
75 | 30 | ->info('Extend the debug profiler with information about requests.') |
|
76 | 30 | ->children() |
|
77 | 30 | ->booleanNode('enabled') |
|
78 | 30 | ->info('Turn the toolbar on or off. Defaults to kernel debug mode.') |
|
79 | 30 | ->defaultValue($this->debug) |
|
80 | 30 | ->end() |
|
81 | 30 | ->end() |
|
82 | 30 | ->end() |
|
83 | 30 | ->arrayNode('fake_ip') |
|
84 | 30 | ->beforeNormalization() |
|
85 | 30 | ->ifString() |
|
86 | ->then(function ($value) { |
||
87 | return ['ip' => $value]; |
||
88 | 30 | }) |
|
89 | 30 | ->end() |
|
90 | 30 | ->canBeEnabled() |
|
91 | 30 | ->children() |
|
92 | 30 | ->scalarNode('ip')->defaultNull()->end() |
|
93 | 30 | ->end() |
|
94 | 30 | ->end(); |
|
95 | |||
96 | 30 | return $treeBuilder; |
|
97 | } |
||
98 | |||
99 | /** |
||
100 | * @return ArrayNodeDefinition |
||
101 | */ |
||
102 | 30 | private function getProvidersNode() |
|
130 | |||
131 | /** |
||
132 | * Create plugin node of a client. |
||
133 | * |
||
134 | * @return ArrayNodeDefinition The plugin node |
||
135 | */ |
||
136 | 30 | private function createClientPluginNode() |
|
182 | } |
||
183 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.