1 | <?php |
||
23 | class Form extends Nette\Forms\Form implements ISignalReceiver |
||
24 | { |
||
25 | /** |
||
26 | * Application form constructor. |
||
27 | */ |
||
28 | public function __construct(Nette\ComponentModel\IContainer $parent = null, $name = null) |
||
36 | |||
37 | /** |
||
38 | * Returns the presenter where this component belongs to. |
||
39 | * @param bool throw exception if presenter doesn't exist? |
||
40 | * @return Nette\ComponentModel\IComponent |
||
41 | */ |
||
42 | public function getPresenter($need = true) |
||
46 | |||
47 | /** |
||
48 | * This method will be called when the component (or component's parent) |
||
49 | * becomes attached to a monitored object. Do not call this method yourself. |
||
50 | * @param Nette\ComponentModel\IComponent |
||
51 | * @return void |
||
52 | */ |
||
53 | protected function attached($presenter) |
||
80 | |||
81 | /** |
||
82 | * Tells if the form is anchored. |
||
83 | * @return bool |
||
84 | */ |
||
85 | public function isAnchored() |
||
89 | |||
90 | /** |
||
91 | * Internal: returns submitted HTTP data or NULL when form was not submitted. |
||
92 | * @return array|NULL |
||
93 | */ |
||
94 | protected function receiveHttpData() |
||
113 | |||
114 | /********************* interface ISignalReceiver ****************d*g**/ |
||
115 | |||
116 | /** |
||
117 | * This method is called by presenter. |
||
118 | * @param string |
||
119 | * @return void |
||
120 | */ |
||
121 | public function signalReceived($signal) |
||
132 | } |
||
133 |
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: