forked from jkapuscik2/design-patterns-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommunicator.php
More file actions
34 lines (25 loc) · 758 Bytes
/
Copy pathCommunicator.php
File metadata and controls
34 lines (25 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
namespace Behavioral\Observer;
use SplObjectStorage, SplObserver, SplSubject;
class Communicator implements SplSubject {
private $employees;
public $message;
public function __construct () {
$this->employees = new SplObjectStorage();
}
public function attach (SplObserver $employee): void {
$this->employees->attach($employee);
}
public function detach (SplObserver $employee): void {
$this->employees->detach($employee);
}
public function inform (string $message): void {
$this->message = $message;
$this->notify();
}
public function notify (): void {
foreach ($this->employees as $employee) {
$employee->update($this);
}
}
}