-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathGroupComposite.php
More file actions
41 lines (33 loc) · 942 Bytes
/
GroupComposite.php
File metadata and controls
41 lines (33 loc) · 942 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
<?php
namespace App\Composite;
class GroupComposite extends MessengerComponent
{
protected \SplObjectStorage $children;
public function __construct(string $name)
{
parent::__construct($name);
$this->children = new \SplObjectStorage();
}
public function add(MessengerComponent $component): void
{
$this->children->attach($component);
$component->setParent($this);
}
public function remove(MessengerComponent $component): void
{
$this->children->detach($component);
$component->setParent(null);
}
public function isComposite(): bool
{
return true;
}
public function operation(): string
{
$results = [];
foreach ($this->children as $child) {
$results[] = "\n\t" . $child->operation();
}
return "MessageGroup:{$this->name}(" . "\t" . implode("+", $results) . "\n" . ")";
}
}