1 | <?php |
||
17 | abstract class AbstractLinkViewHelper extends AbstractTagBasedViewHelper |
||
18 | { |
||
19 | /** |
||
20 | * Tag type. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $tagName = 'a'; |
||
25 | |||
26 | /** |
||
27 | * Store the last href to avoid escaping for the URI view Helper. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $lastHref = ''; |
||
32 | |||
33 | /** |
||
34 | * Arguments initialization. |
||
35 | */ |
||
36 | public function initializeArguments() |
||
48 | |||
49 | /** |
||
50 | * render the link. |
||
51 | * |
||
52 | * @param int|null $pageUid target page. See TypoLink destination |
||
53 | * @param array $additionalParams query parameters to be attached to the resulting URI |
||
54 | * @param bool $absolute |
||
55 | * |
||
56 | * @return string Rendered page URI |
||
57 | */ |
||
58 | public function renderLink($pageUid = null, array $additionalParams = [], $absolute = false, $section = '') |
||
79 | |||
80 | /** |
||
81 | * Get the right page Uid. |
||
82 | * |
||
83 | * @param int $pageUid |
||
84 | * @param string|null $contextName |
||
85 | * |
||
86 | * @return int |
||
87 | */ |
||
88 | protected function getPageUid($pageUid, $contextName = null) |
||
107 | } |
||
108 |
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: