1 | <?php |
||
10 | abstract class Command implements \SplObserver |
||
11 | { |
||
12 | /** |
||
13 | * @param \SplSubject $subject |
||
14 | * |
||
15 | * @throws \InvalidArgumentException |
||
16 | */ |
||
17 | 6 | public function update(\SplSubject $subject) |
|
18 | { |
||
19 | 6 | if (!$subject instanceof EventInterface) { |
|
20 | 2 | throw new \InvalidArgumentException('Command can only be attached to an event!'); |
|
21 | } |
||
22 | 4 | if (method_exists($this, '__invoke')) { |
|
23 | 2 | call_user_func_array($this, $subject->getInvokeArgs()); |
|
24 | } else { |
||
25 | 2 | throw new \Exception('Command should have at least one __invoke method'); |
|
26 | } |
||
27 | 2 | } |
|
28 | |||
29 | /** |
||
30 | * Overwrite this to change the name for the Command that is displayed in the graph. |
||
31 | * |
||
32 | * @return string |
||
33 | */ |
||
34 | 1 | public function __toString() |
|
38 | } |
||
39 |