1 | <?php |
||
26 | class Renderer extends AbstractValidateRenderer |
||
27 | { |
||
28 | /** |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $skipValidators = [ |
||
32 | 'Explode', |
||
33 | 'Upload' |
||
34 | ]; |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $rules = []; |
||
40 | |||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $messages = []; |
||
45 | |||
46 | /** |
||
47 | * @var RulePluginManager |
||
48 | */ |
||
49 | protected $rulePluginManager; |
||
50 | |||
51 | /** |
||
52 | * @param RulePluginManager $rulePluginManager |
||
53 | */ |
||
54 | public function setRulePluginManager(RulePluginManager $rulePluginManager) |
||
58 | |||
59 | /** |
||
60 | * @return RulePluginManager |
||
61 | */ |
||
62 | public function getRulePluginManager() |
||
66 | |||
67 | /** |
||
68 | * Executed before the ZF2 view helper renders the element |
||
69 | * |
||
70 | * @param string $formAlias |
||
71 | * @param \Zend\View\Renderer\PhpRenderer $view |
||
72 | * @param \Zend\Form\FormInterface $form |
||
73 | * @param array $options |
||
74 | * |
||
75 | * @return FormInterface |
||
76 | */ |
||
77 | public function preRenderForm($formAlias, View $view, FormInterface $form = null, array $options = []) |
||
99 | |||
100 | /** |
||
101 | * @param \Zend\Form\FormInterface $form |
||
102 | * @param Options $options |
||
103 | * |
||
104 | * @return string |
||
105 | */ |
||
106 | protected function buildInlineJavascript(FormInterface $form, Options $options) |
||
125 | |||
126 | /** |
||
127 | * @param string $formAlias |
||
128 | * @param \Zend\Form\ElementInterface $element |
||
129 | * @param \Zend\Validator\ValidatorInterface $validator |
||
130 | * |
||
131 | * @return mixed|void |
||
132 | */ |
||
133 | protected function addValidationAttributesForElement($formAlias, ElementInterface $element, ValidatorInterface $validator = null) |
||
165 | |||
166 | /** |
||
167 | * @param \Zend\Validator\ValidatorInterface $validator |
||
168 | * |
||
169 | * @return null|RuleInterface |
||
170 | */ |
||
171 | public function getRule(ValidatorInterface $validator = null) |
||
184 | |||
185 | /** |
||
186 | * @param string $elementName |
||
187 | * @param array $rules |
||
188 | */ |
||
189 | protected function addRules($elementName, array $rules = []) |
||
196 | |||
197 | /** |
||
198 | * @param string $elementName |
||
199 | * @param array $messages |
||
200 | */ |
||
201 | protected function addMessages($elementName, array $messages = []) |
||
208 | |||
209 | /** |
||
210 | * Resets previously set rules and messages, if you have multiple forms on one request |
||
211 | */ |
||
212 | protected function reset() |
||
217 | } |
||
218 |
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 sub-classes 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 parent class: