-
Notifications
You must be signed in to change notification settings - Fork 454
/
AggregateOutput.php
57 lines (47 loc) · 1.59 KB
/
AggregateOutput.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
50
51
52
53
54
55
56
57
<?php
namespace Concrete\Core\Command\Task\Output;
use Symfony\Component\Serializer\Normalizer\DenormalizableInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizableInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class AggregateOutput implements OutputInterface, NormalizableInterface, DenormalizableInterface
{
/**
* @var OutputInterface[]
*/
protected $outputs = [];
/**
* AggregateOutput constructor.
* @param OutputInterface[] $outputs
*/
public function __construct(array $outputs = [])
{
$this->outputs = $outputs;
}
public function addOutput(OutputInterface $output)
{
$this->outputs[] = $output;
}
public function write($message)
{
foreach($this->outputs as $output) {
$output->write($message);
}
}
public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = [])
{
$outputs = [];
foreach($this->outputs as $output) {
$outputs[] = ['type' => get_class($output), 'output' => $normalizer->normalize($output)];
}
return ['outputs' => $outputs];
}
public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = [])
{
$outputs = [];
foreach($data['outputs'] as $dataOutput) {
$output = $denormalizer->denormalize($dataOutput['output'], $dataOutput['type']);
$this->outputs[] = $output;
}
}
}