1 | <?php |
||
24 | class Application |
||
25 | { |
||
26 | |||
27 | /** |
||
28 | * @var ContainerInterface |
||
29 | */ |
||
30 | private static $container; |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | private $configPath; |
||
36 | |||
37 | /** |
||
38 | * @var Request |
||
39 | */ |
||
40 | private $request; |
||
41 | |||
42 | /** |
||
43 | * @var MiddlewareRunnerInterface |
||
44 | */ |
||
45 | private $runner; |
||
46 | |||
47 | /** |
||
48 | * @var Response |
||
49 | */ |
||
50 | private $response; |
||
51 | |||
52 | /** |
||
53 | * @var ContainerInterface |
||
54 | */ |
||
55 | private static $defaultContainer; |
||
56 | |||
57 | /** |
||
58 | * Creates an application with an HTTP request |
||
59 | * |
||
60 | * If no request is provided then a Slick\Http\PhpEnvironment\Request is |
||
61 | * created with values form current php environment settings. |
||
62 | * |
||
63 | * @param Request $request |
||
64 | */ |
||
65 | 8 | public function __construct(Request $request = null) |
|
75 | |||
76 | /** |
||
77 | * Sets a new request |
||
78 | * |
||
79 | * @param Request $request |
||
80 | * |
||
81 | * @return Application |
||
82 | */ |
||
83 | 2 | public function setRequest(Request $request) |
|
89 | |||
90 | /** |
||
91 | * Gets the application dependency injection container |
||
92 | * |
||
93 | * @return ContainerInterface|Container |
||
94 | */ |
||
95 | 6 | public function getContainer() |
|
102 | |||
103 | /** |
||
104 | * Sets the dependency injection container |
||
105 | * |
||
106 | * @param ContainerInterface $container |
||
107 | */ |
||
108 | 22 | public static function setContainer(ContainerInterface $container) |
|
112 | |||
113 | /** |
||
114 | * Returns the application dependency container |
||
115 | * |
||
116 | * @return ContainerInterface|Container |
||
117 | */ |
||
118 | 20 | public static function container() |
|
126 | |||
127 | /** |
||
128 | * Set middleware runner |
||
129 | * |
||
130 | * @param MiddlewareRunnerInterface $runner |
||
131 | * |
||
132 | * @return $this|self|Application |
||
133 | */ |
||
134 | 2 | public function setRunner(MiddlewareRunnerInterface $runner) |
|
139 | |||
140 | /** |
||
141 | * Returns the processed response |
||
142 | * |
||
143 | * @return Response |
||
144 | */ |
||
145 | 2 | public function getResponse() |
|
152 | |||
153 | /** |
||
154 | * Gets the HTTP middleware runner for this application |
||
155 | * |
||
156 | * @return MiddlewareRunnerInterface |
||
157 | */ |
||
158 | 2 | public function getRunner() |
|
169 | |||
170 | /** |
||
171 | * Set configuration path |
||
172 | * |
||
173 | * @param string $configPath |
||
174 | * |
||
175 | * @return Application|self |
||
176 | */ |
||
177 | public function setConfigPath($configPath) |
||
183 | |||
184 | /** |
||
185 | * Gets configuration path |
||
186 | * |
||
187 | * @return string |
||
188 | */ |
||
189 | public function getConfigPath() |
||
197 | |||
198 | /** |
||
199 | * Gets HTTP request object |
||
200 | * |
||
201 | * @return Request |
||
202 | */ |
||
203 | 4 | public function getRequest() |
|
211 | |||
212 | /** |
||
213 | * Gets container with user overridden settings |
||
214 | * |
||
215 | * @return ContainerInterface|\Slick\Di\Container |
||
216 | */ |
||
217 | 2 | protected function checkContainer() |
|
234 | |||
235 | } |
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 implementation 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 interface: