1 | <?php |
||
17 | class ConsoleController extends AbstractActionController |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * @var \Zend\Console\Adapter\AdapterInterface console object |
||
22 | */ |
||
23 | protected $console; |
||
24 | |||
25 | /** |
||
26 | * @var AssetManager asset manager object |
||
27 | */ |
||
28 | protected $assetManager; |
||
29 | |||
30 | /** |
||
31 | * @var array associative array represents app config |
||
32 | */ |
||
33 | protected $appConfig; |
||
34 | |||
35 | /** |
||
36 | * @param Console $console |
||
37 | * @param AssetManager $assetManager |
||
38 | * @param array $appConfig |
||
39 | */ |
||
40 | 1 | public function __construct(Console $console, AssetManager $assetManager, array $appConfig) |
|
46 | |||
47 | /** |
||
48 | * {@inheritdoc} |
||
49 | * @param RequestInterface $request |
||
50 | * @param ResponseInterface $response |
||
51 | * @return mixed|ResponseInterface |
||
52 | * @throws \RuntimeException |
||
53 | */ |
||
54 | 1 | public function dispatch(RequestInterface $request, ResponseInterface $response = null) |
|
62 | |||
63 | /** |
||
64 | * Dumps all assets to cache directories. |
||
65 | */ |
||
66 | 1 | public function warmupAction() |
|
90 | |||
91 | /** |
||
92 | * Purges all directories defined as AssetManager cache dir. |
||
93 | * @param bool $verbose verbose flag, default false |
||
94 | * @return bool false if caching is not set, otherwise true |
||
95 | */ |
||
96 | protected function purgeCache($verbose = false) |
||
120 | |||
121 | /** |
||
122 | * Removes given node from filesystem (recursively). |
||
123 | * @param string $node - uri of node that should be removed from filesystem |
||
124 | * @param bool $verbose verbose flag, default false |
||
125 | */ |
||
126 | protected function recursiveRemove($node, $verbose = false) |
||
142 | |||
143 | /** |
||
144 | * Outputs given $line if $verbose i truthy value. |
||
145 | * @param $line |
||
146 | * @param bool $verbose verbose flag, default true |
||
147 | */ |
||
148 | 1 | protected function output($line, $verbose = true) |
|
154 | } |
||
155 |
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: