-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessingManager.php
More file actions
40 lines (29 loc) · 891 Bytes
/
ProcessingManager.php
File metadata and controls
40 lines (29 loc) · 891 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
<?php
declare(strict_types = 1);
namespace app;
use app\decorators\BaseProcessing;
use app\interfaces\WordProcessing;
class ProcessingManager
{
protected $methods = [];
public function __construct(array $methods)
{
$this->methods = $methods;
}
public function manage(): WordProcessing
{
$processingChain = new PlainProcessing();
foreach ($this->methods as $method) {
$processingChain = $this->createDecorator($method, $processingChain);
}
return $processingChain;
}
protected function createDecorator(string $name, WordProcessing $wordProcessing): WordProcessing
{
$name = ucfirst($name) . 'Processing';
if (class_exists($name) && is_subclass_of($name, BaseProcessing::class)) {
return new $name($wordProcessing);
}
return $wordProcessing;
}
}