1 | <?php |
||
21 | class EventPipe extends \PEIP\ABS\Pipe\EventPipe implements \PEIP\INF\Event\Listener |
||
22 | { |
||
23 | protected $eventName; |
||
24 | |||
25 | public function connectChannel(\PEIP\INF\Channel\Channel $inputChannel) |
||
29 | |||
30 | /** |
||
31 | * Sets the input channel for this event-pipe. Contrary to Pipe event-pipes |
||
32 | * listen to a given event on the input-channel and hanle resulting event-objects. |
||
33 | * |
||
34 | * @param \PEIP\INF\Channel\Channel $inputChannel the input-channel to listen for events. |
||
35 | * |
||
36 | * @return |
||
37 | */ |
||
38 | public function setInputChannel(\PEIP\INF\Channel\Channel $inputChannel) |
||
42 | |||
43 | /** |
||
44 | * Does the message replying logic for the event-pipe. |
||
45 | * In context of an event-pipe the message is normally a instance of |
||
46 | * \PEIP\INF\Event\Event representing an event on a channel/pipe. This method |
||
47 | * looks for a header 'MESSAGE' on the event object. If the header is a |
||
48 | * message (instance of \PEIP\INF\Message\Message) replies with the message. |
||
49 | * Implements PEIP\ABS\Handler\ReplyProducingMessageHandler::doReply. |
||
50 | * |
||
51 | * @abstract |
||
52 | * |
||
53 | * @param \PEIP\INF\Message\Message $message the message to reply with |
||
54 | */ |
||
55 | protected function doReply(\PEIP\INF\Message\Message $message) |
||
62 | |||
63 | /** |
||
64 | * Connects the event-pipe to a \PEIP\INF\Event\Connectable instance by |
||
65 | * listening to the event-type registered with this event-pipe. |
||
66 | * |
||
67 | * @param \PEIP\INF\Event\Connectable $connectable the connectable to listen to |
||
68 | * |
||
69 | * @return |
||
70 | */ |
||
71 | public function listen(\PEIP\INF\Event\Connectable $connectable) |
||
75 | |||
76 | /** |
||
77 | * Disconnects the event-pipe from a \PEIP\INF\Event\Connectable instance by |
||
78 | * listening to the event-type registered with this event-pipe. |
||
79 | * |
||
80 | * @param \PEIP\INF\Event\Connectable $connectable the connectable to unlisten |
||
81 | * |
||
82 | * @return |
||
83 | */ |
||
84 | public function unlisten(\PEIP\INF\Event\Connectable $connectable) |
||
88 | |||
89 | /** |
||
90 | * Returns the instances of \PEIP\INF\Event\Connectable the event-pipe is litening to. |
||
91 | * |
||
92 | * @return array array of \PEIP\INF\Event\Connectable instances |
||
93 | */ |
||
94 | public function getConnected() |
||
98 | |||
99 | /** |
||
100 | * Disconnects a \PEIP\INF\Channel\Channel instance from the event-pipe. |
||
101 | * |
||
102 | * @param \PEIP\INF\Channel\Channel $channel \PEIP\INF\Channel\Channel instance to disconnect from |
||
103 | * |
||
104 | * @return |
||
105 | */ |
||
106 | public function disconnectChannel(\PEIP\INF\Channel\Channel $channel) |
||
112 | |||
113 | /** |
||
114 | * Connects the registered input-channel to this event-pipe by |
||
115 | * listening to the event-type registered with this event-pipe. |
||
116 | * |
||
117 | * @return |
||
118 | */ |
||
119 | protected function connectInputChannel() |
||
125 | |||
126 | /** |
||
127 | * Disconnects the registered input-channel from this event-pipe by |
||
128 | * unlistening to the event-type registered with this event-pipe. |
||
129 | * |
||
130 | * @return |
||
131 | */ |
||
132 | protected function disconnectInputChannel() |
||
138 | |||
139 | /** |
||
140 | * Registers the event-name this event-pipe should listen to. |
||
141 | * |
||
142 | * @param $eventName |
||
143 | * |
||
144 | * @return |
||
145 | */ |
||
146 | public function setEventName($eventName) |
||
152 | } |
||
153 |
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: