1 | <?php |
||
11 | class Subjects implements SplSubject |
||
12 | { |
||
13 | /** |
||
14 | * @var \SplObserver[] $observers List of all observers |
||
15 | */ |
||
16 | protected $observers = []; |
||
17 | |||
18 | /** |
||
19 | * @var \stdClass[] $notifyHeap List of notify to send |
||
20 | */ |
||
21 | protected $notifyHeap = []; |
||
22 | |||
23 | /** |
||
24 | * @var string $action The current action to send to observers |
||
25 | */ |
||
26 | protected $action = ''; |
||
27 | |||
28 | /** |
||
29 | * @var mixed $context The current context to send to observers |
||
30 | */ |
||
31 | protected $context = null; |
||
32 | |||
33 | /** |
||
34 | * Return list of all observers |
||
35 | * |
||
36 | * @return \SplObserver[] |
||
37 | */ |
||
38 | public function getObservers() |
||
42 | |||
43 | /** |
||
44 | * Return the action |
||
45 | * |
||
46 | * @return string |
||
47 | */ |
||
48 | public function getAction() |
||
52 | |||
53 | /** |
||
54 | * Return the context |
||
55 | * |
||
56 | * @return mixed |
||
57 | */ |
||
58 | public function getContext() |
||
62 | |||
63 | /** |
||
64 | * Attach a new observer to the list |
||
65 | * |
||
66 | * @param \SplObserver $observer The new observer |
||
67 | * |
||
68 | * @return \BFW\Subjects The current instance of this class |
||
69 | */ |
||
70 | public function attach(SplObserver $observer) |
||
76 | |||
77 | /** |
||
78 | * Detach a observer to the list |
||
79 | * |
||
80 | * @param \SplObserver $observer The observer instance to detach |
||
81 | * |
||
82 | * @return \BFW\Subjects The current instance of this class |
||
83 | */ |
||
84 | public function detach(SplObserver $observer) |
||
94 | |||
95 | /** |
||
96 | * Send a notification to all observers |
||
97 | * |
||
98 | * @return \BFW\Subjects The current instance of this class |
||
99 | */ |
||
100 | public function notify() |
||
108 | |||
109 | public function readNotifyHeap() |
||
128 | |||
129 | /** |
||
130 | * Add a new notification to the list of notification to send. |
||
131 | * If there is only one notification into the list, it will be send now. |
||
132 | * Else, a notification is currently sent, so we wait it finish and the |
||
133 | * current notification will be sent. |
||
134 | * |
||
135 | * @param string $action The action to send |
||
136 | * @param notification $context (default null) The context to send |
||
137 | * |
||
138 | * @return \BFW\Subjects The current instance of this class |
||
139 | */ |
||
140 | public function addNotification($action, $context = null) |
||
153 | } |
||
154 |