1 | <?php |
||
16 | class Controller |
||
17 | { |
||
18 | use DynamicGlobal; |
||
19 | |||
20 | /** @var string */ |
||
21 | public $layout = 'main'; |
||
22 | |||
23 | /** @var string */ |
||
24 | protected $output; |
||
25 | |||
26 | /** @var \Ffcms\Core\Network\Request */ |
||
27 | public $request; |
||
28 | /** @var \Ffcms\Core\Network\Response */ |
||
29 | public $response; |
||
30 | /** @var View */ |
||
31 | public $view; |
||
32 | |||
33 | /** |
||
34 | * Controller constructor. Set controller access data - request, response, view |
||
35 | */ |
||
36 | public function __construct() |
||
43 | |||
44 | /** Before action call method */ |
||
45 | public function before() {} |
||
46 | |||
47 | /** Global bootable method */ |
||
48 | public static function boot() {} |
||
49 | |||
50 | /** |
||
51 | * Build variables and display output html |
||
52 | */ |
||
53 | public function buildOutput() |
||
97 | |||
98 | /** After action called method */ |
||
99 | public function after() {} |
||
100 | |||
101 | /** |
||
102 | * Set single global variable |
||
103 | * @param string $var |
||
104 | * @param string $value |
||
105 | * @param bool $html |
||
106 | */ |
||
107 | public function setGlobalVar($var, $value, $html = false) |
||
111 | |||
112 | /** |
||
113 | * Set global variables as array key=>value |
||
114 | * @param $array |
||
115 | */ |
||
116 | public function setGlobalVarArray(array $array) |
||
120 | |||
121 | /** |
||
122 | * Special method to set response of action execution |
||
123 | * @param string $output |
||
124 | */ |
||
125 | public function setOutput($output) |
||
129 | |||
130 | /** |
||
131 | * Get response of action rendering |
||
132 | * @return string |
||
133 | */ |
||
134 | public function getOutput() |
||
138 | |||
139 | } |
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: