1 | <?php |
||
40 | class Resolver extends ConfigDelegator implements ResolverInterface, AutoWiringInterface, ReferenceResolveInterface |
||
41 | { |
||
42 | /** |
||
43 | * The config for object resolving |
||
44 | * |
||
45 | * @var ObjectResolver |
||
46 | * @access protected |
||
47 | */ |
||
48 | protected $object_resolver; |
||
49 | |||
50 | /** |
||
51 | * The config for parameter resolver |
||
52 | * |
||
53 | * @var ConfigInterface |
||
54 | * @access protected |
||
55 | */ |
||
56 | protected $config_resolver; |
||
57 | |||
58 | /** |
||
59 | * Container related definition starting node at $config |
||
60 | * |
||
61 | * @var string |
||
62 | * @access protected |
||
63 | */ |
||
64 | protected $base_node; |
||
65 | |||
66 | /** |
||
67 | * For autowiring |
||
68 | * |
||
69 | * @var bool |
||
70 | * @access protected |
||
71 | */ |
||
72 | protected $auto = true; |
||
73 | |||
74 | /** |
||
75 | * @param Container $container |
||
76 | * @param ConfigInterface $config inject config for parameter resolving |
||
77 | * @param string $nodeName |
||
78 | * @access public |
||
79 | */ |
||
80 | public function __construct( |
||
96 | |||
97 | /** |
||
98 | * Resolving use the parameter resolver |
||
99 | * |
||
100 | * {@inheritDoc} |
||
101 | */ |
||
102 | public function resolve(&$toResolve) |
||
109 | |||
110 | /** |
||
111 | * {@inheritDoc} |
||
112 | */ |
||
113 | public function getService(/*# string */ $id = '') |
||
121 | |||
122 | /** |
||
123 | * Autowiring support added |
||
124 | * |
||
125 | * {@inheritDoc} |
||
126 | */ |
||
127 | public function hasService(/*# string */ $id = '')/*# : bool */ |
||
135 | |||
136 | /** |
||
137 | * {@inheritDoc} |
||
138 | */ |
||
139 | public function setService( |
||
152 | |||
153 | /** |
||
154 | * {@inheritDoc} |
||
155 | */ |
||
156 | public function getSectionId( |
||
163 | |||
164 | /** |
||
165 | * {@inheritDoc} |
||
166 | */ |
||
167 | public function auto(/*# bool */ $flag = true) |
||
172 | |||
173 | /** |
||
174 | * {@inheritDoc} |
||
175 | */ |
||
176 | public function isAuto()/*# : bool */ |
||
180 | |||
181 | /** |
||
182 | * Returns true if |
||
183 | * |
||
184 | * 1) autowiring is true |
||
185 | * 2) $id is a existing classname |
||
186 | * 3) resolver $this is writable |
||
187 | * |
||
188 | * @param string $id |
||
189 | * @return bool |
||
190 | * @access protected |
||
191 | */ |
||
192 | protected function autoClassName(/*# string */ $id)/*# : bool */ |
||
200 | } |
||
201 |
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.