-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathCommunicator.php
More file actions
42 lines (34 loc) · 860 Bytes
/
Copy pathCommunicator.php
File metadata and controls
42 lines (34 loc) · 860 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
35
36
37
38
39
40
41
42
<?php
namespace App\Behavioral\Observer;
use SplObjectStorage;
use SplObserver;
use SplSubject;
final class Communicator implements SplSubject
{
private SplObjectStorage $employees;
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->notify($message);
}
public function notify(string $message = ""): void
{
foreach ($this->employees as $employee) {
/**
* @var $employee Employee
*/
$employee->update($this, $message);
}
}
}