-
Notifications
You must be signed in to change notification settings - Fork 0
/
Multiprocessor.php
49 lines (42 loc) · 1.12 KB
/
Multiprocessor.php
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
43
44
45
46
47
48
49
<?php
namespace Kolyunya\StringProcessor;
use Kolyunya\StringProcessor\BaseProcessor;
use Kolyunya\StringProcessor\ProcessorInterface;
/**
* Processor which combines multiple processors.
* @author Kolyunya
*/
class Multiprocessor extends BaseProcessor implements ProcessorInterface
{
/**
* An array of processors to use while procession.
* @var array
*/
private $processors;
/**
* Initializes the multiprocessor.
* @param array $processors Processors to use while procession.
*/
public function __construct($processors = array())
{
$this->processors = $processors;
}
/**
* Adds a processor to an array of processors used while procession.
* @param ProcessorInterface $processor Processor to add.
*/
public function addProcessor(ProcessorInterface $processor)
{
$this->processors[] = $processor;
}
/**
* @inheritdoc
*/
protected function selfProcession($string)
{
foreach ($this->processors as $processor) {
$string = $processor->process($string);
}
return $string;
}
}