1 | <?php |
||
20 | class Escape implements InterceptorInterface |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * Is the interceptor enabled right now for child nodes? |
||
25 | * |
||
26 | * @var boolean |
||
27 | */ |
||
28 | protected $childrenEscapingEnabled = true; |
||
29 | |||
30 | /** |
||
31 | * A stack of ViewHelperNodes which currently disable the interceptor. |
||
32 | * Needed to enable the interceptor again. |
||
33 | * |
||
34 | * @var NodeInterface[] |
||
35 | */ |
||
36 | protected $viewHelperNodesWhichDisableTheInterceptor = []; |
||
37 | |||
38 | /** |
||
39 | * Adds a ViewHelper node using the Format\HtmlspecialcharsViewHelper to the given node. |
||
40 | * If "escapingInterceptorEnabled" in the ViewHelper is FALSE, will disable itself inside the ViewHelpers body. |
||
41 | * |
||
42 | * @param NodeInterface $node |
||
43 | * @param integer $interceptorPosition One of the INTERCEPT_* constants for the current interception point |
||
44 | * @param ParsingState $parsingState the current parsing state. Not needed in this interceptor. |
||
45 | * @return NodeInterface |
||
46 | */ |
||
47 | public function process(NodeInterface $node, $interceptorPosition, ParsingState $parsingState) |
||
72 | |||
73 | /** |
||
74 | * This interceptor wants to hook into object accessor creation, and opening / closing ViewHelpers. |
||
75 | * |
||
76 | * @return array Array of INTERCEPT_* constants |
||
77 | */ |
||
78 | public function getInterceptionPoints() |
||
87 | } |
||
88 |
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: