/
PushOutput.php
51 lines (41 loc) · 1.49 KB
/
PushOutput.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
<?php
namespace Concrete\Core\Command\Task\Output;
use Concrete\Core\Entity\Command\Process;
use Concrete\Core\Notification\Events\MercureService;
use Concrete\Core\Notification\Events\ServerEvent\ProcessOutputEvent;
use Symfony\Component\Serializer\Normalizer\DenormalizableInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizableInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
defined('C5_EXECUTE') or die("Access Denied.");
class PushOutput implements OutputInterface, NormalizableInterface, DenormalizableInterface
{
/**
* @var MercureService
*/
protected $service;
/**
* @var string
*/
protected $processId;
public function __construct(MercureService $service = null, string $processId = null)
{
$this->service = $service;
$this->processId = $processId;
}
public function write($message)
{
$this->service->getHub()->publish((new ProcessOutputEvent($this->processId, $message))->getUpdate());
}
public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = [])
{
return [
'processId' => $this->processId,
];
}
public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = [])
{
$this->service = app(MercureService::class);
$this->processId = $data['processId'];
}
}