-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRabbitMqProducer.php
77 lines (67 loc) · 2.23 KB
/
RabbitMqProducer.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace LaSalle\Rendimiento\JudithVilela\Shared\Infrastructure\RabbitMq;
use LaSalle\Rendimiento\JudithVilela\ImageRegister\Domain\Service\ImageProcess;
use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface;
final class RabbitMqProducer implements ImageProcess
{
/** @var ProducerInterface */
private $producerInterface;
public function __construct(ProducerInterface $producerInterface)
{
$this->producerInterface = $producerInterface;
}
/**
* @inheritDoc
*/
public function send(string $message)
{
$filters = ['prd', 'bw', 'ctr', 'frm','flp'];
foreach ($filters as $filter) {
$newMessage = $this->setFormat($message, $filter);
$this->producerInterface->publish($newMessage);
}
}
/**
* @param string $parameters
* @param string $filter
*
* @return array
*/
private function setFormat(string $parameters, string $filter) :string
{
$messageFilter = json_decode($parameters);
$messageFilter->filter = $filter;
$messageFilter->textFilter = $this->getFilter($filter);
$messageFilter->tag = $messageFilter->tag.' '.$this->getFilter($filter);
$messageFilter->processedImage = $messageFilter->imageName.'_'.$filter;
$messageFilter->processedImagePath = $messageFilter->processedImagePath.$messageFilter->processedImage.'.'.$messageFilter->imageExt;
return json_encode($messageFilter, JSON_UNESCAPED_SLASHES);
}
/**
* @param string $filter
* @return string
*/
private function getFilter(string $filter): string
{
$textFilter = null;
switch ($filter)
{
case 'prd':
$textFilter = 'sepia';
break;
case 'bw':
$textFilter = 'blanco y negro';
break;
case 'ctr':
$textFilter = 'citrico';
break;
case 'frm':
$textFilter = 'con bordes';
break;
case 'flp':
$textFilter = 'invertida';
break;
}
return $textFilter;
}
}