|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AppBuilder\Application\Module\TicketAggregate; |
|
6
|
|
|
|
|
7
|
|
|
use AppBuilder\Application\Module\TicketAggregate\Factory\TicketServiceFactory; |
|
8
|
|
|
use AppBuilder\Event\Application\BitbucketTicketMappedEvent; |
|
9
|
|
|
use AppBuilder\Event\Application\BitbucketTicketMappedEventAware; |
|
10
|
|
|
use AppBuilder\Event\Application\JiraTicketMappedEvent; |
|
11
|
|
|
use AppBuilder\Event\Application\JiraTicketMappedEventAware; |
|
12
|
|
|
use AppBuilder\Event\Application\TicketDirIndexedEvent; |
|
13
|
|
|
use AppBuilder\Event\Application\TicketDirIndexedEventAware; |
|
14
|
|
|
use Psr\Log\LoggerInterface; |
|
15
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
16
|
|
|
|
|
17
|
|
|
class TicketServiceRepository implements |
|
18
|
|
|
JiraTicketMappedEventAware, |
|
19
|
|
|
BitbucketTicketMappedEventAware, |
|
20
|
|
|
TicketDirIndexedEventAware |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var array */ |
|
23
|
|
|
private $ticketServices = []; |
|
24
|
|
|
|
|
25
|
|
|
/** @var TicketServiceFactory */ |
|
26
|
|
|
private $factory; |
|
27
|
|
|
|
|
28
|
|
|
/** @var TicketBuilder */ |
|
29
|
|
|
private $builder; |
|
30
|
|
|
|
|
31
|
|
|
/** @var EventDispatcherInterface */ |
|
32
|
|
|
private $dispatcher; |
|
33
|
|
|
|
|
34
|
|
|
/** @var LoggerInterface */ |
|
35
|
|
|
private $logger; |
|
36
|
|
|
|
|
37
|
|
|
public function __construct( |
|
38
|
|
|
TicketServiceFactory $factory, |
|
39
|
|
|
TicketBuilder $builder, |
|
40
|
|
|
EventDispatcherInterface $dispatcher, |
|
41
|
|
|
LoggerInterface $logger |
|
42
|
|
|
) { |
|
43
|
|
|
$this->factory = $factory; |
|
44
|
|
|
$this->builder = $builder; |
|
45
|
|
|
$this->dispatcher = $dispatcher; |
|
46
|
|
|
$this->logger = $logger; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Returns ticket service, adequate to 'id' passed as parameter, from ticketService repository. |
|
51
|
|
|
* If passed 'id' is not in repository, creates new ticket service, adds to repository and returns it. |
|
52
|
|
|
*/ |
|
53
|
|
|
public function get(int $id) : TicketService |
|
54
|
|
|
{ |
|
55
|
|
|
if (array_key_exists($id, $this->ticketServices)) { |
|
56
|
|
|
return $this->ticketServices[$id]; |
|
57
|
|
|
} |
|
58
|
|
|
$ticketService = $this->factory->create( |
|
59
|
|
|
$this->builder, |
|
60
|
|
|
$this->dispatcher, |
|
61
|
|
|
$this->logger |
|
62
|
|
|
); |
|
63
|
|
|
$this->ticketServices[$id] = $ticketService; |
|
64
|
|
|
|
|
65
|
|
|
return $ticketService; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Gets adequate ticketService from repository and passes event to it. |
|
70
|
|
|
*/ |
|
71
|
|
|
public function onBitbucketTicketMapped(BitbucketTicketMappedEvent $event) : void |
|
72
|
|
|
{ |
|
73
|
|
|
$ticketService = $this->get(array_keys($event->bitbucketTicket())['0']); |
|
74
|
|
|
$ticketService->onBitbucketTicketMapped($event); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Gets adequate ticketService from repository and passes event to it. |
|
79
|
|
|
*/ |
|
80
|
|
|
public function onJiraTicketMapped(JiraTicketMappedEvent $event) : void |
|
81
|
|
|
{ |
|
82
|
|
|
$ticketService = $this->get($event->ticket()['id']); |
|
83
|
|
|
$ticketService->onJiraTicketMapped($event); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Gets adequate ticketService from repository and passes event to it. |
|
88
|
|
|
*/ |
|
89
|
|
|
public function onTicketDirIndexed(TicketDirIndexedEvent $event) : void |
|
90
|
|
|
{ |
|
91
|
|
|
$ticketService = $this->get($event->indexedDir()['ticketId']); |
|
92
|
|
|
$ticketService->onTicketDirIndexed($event); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|