|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright © Thomas Klein, All rights reserved. |
|
4
|
|
|
* See LICENSE bundled with this library for license details. |
|
5
|
|
|
*/ |
|
6
|
|
|
declare(strict_types=1); |
|
7
|
|
|
|
|
8
|
|
|
namespace Zoho\Desk\Model; |
|
9
|
|
|
|
|
10
|
|
|
use Zoho\Desk\Client\RequestBuilder; |
|
11
|
|
|
use Zoho\Desk\Model\Operation\CreateOperation; |
|
12
|
|
|
use Zoho\Desk\Model\Operation\CreateOperationInterface; |
|
13
|
|
|
use Zoho\Desk\Model\Operation\DeleteOperation; |
|
14
|
|
|
use Zoho\Desk\Model\Operation\DeleteOperationInterface; |
|
15
|
|
|
use Zoho\Desk\Model\Operation\ListOperation; |
|
16
|
|
|
use Zoho\Desk\Model\Operation\ListOperationInterface; |
|
17
|
|
|
use Zoho\Desk\Model\Operation\ReadOperation; |
|
18
|
|
|
use Zoho\Desk\Model\Operation\ReadOperationInterface; |
|
19
|
|
|
use Zoho\Desk\Model\Operation\UpdateOperation; |
|
20
|
|
|
use Zoho\Desk\Model\Operation\UpdateOperationInterface; |
|
21
|
|
|
use function implode; |
|
22
|
|
|
use function md5; |
|
23
|
|
|
|
|
24
|
|
|
final class OperationPool |
|
25
|
|
|
{ |
|
26
|
|
|
private RequestBuilder $requestBuilder; |
|
27
|
|
|
|
|
28
|
|
|
private DataObjectFactory $dataObjectFactory; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var CreateOperationInterface[] |
|
32
|
|
|
*/ |
|
33
|
|
|
private array $createOperationPool; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var ReadOperationInterface[] |
|
37
|
|
|
*/ |
|
38
|
|
|
private array $readOperationPool; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var ListOperationInterface[] |
|
42
|
|
|
*/ |
|
43
|
|
|
private array $listOperationPool; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var UpdateOperationInterface[] |
|
47
|
|
|
*/ |
|
48
|
|
|
private array $updateOperationPool; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var DeleteOperationInterface[] |
|
52
|
|
|
*/ |
|
53
|
|
|
private array $deleteOperationPool; |
|
54
|
|
|
|
|
55
|
|
|
public function __construct( |
|
56
|
|
|
RequestBuilder $requestBuilder, |
|
57
|
|
|
DataObjectFactory $dataObjectFactory |
|
58
|
|
|
) { |
|
59
|
|
|
$this->requestBuilder = $requestBuilder; |
|
60
|
|
|
$this->dataObjectFactory = $dataObjectFactory; |
|
61
|
|
|
$this->createOperationPool = []; |
|
62
|
|
|
$this->readOperationPool = []; |
|
63
|
|
|
$this->listOperationPool = []; |
|
64
|
|
|
$this->updateOperationPool = []; |
|
65
|
|
|
$this->deleteOperationPool = []; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function getCreateOperation(string $entityType, array $arguments = []): CreateOperationInterface |
|
69
|
|
|
{ |
|
70
|
|
|
$hash = md5($entityType . implode('', $arguments)); |
|
71
|
|
|
|
|
72
|
|
|
return $this->createOperationPool[$hash] |
|
73
|
|
|
?? $this->createOperationPool[$hash] = new CreateOperation( |
|
74
|
|
|
$this->requestBuilder, |
|
75
|
|
|
$this->dataObjectFactory, |
|
76
|
|
|
$entityType, |
|
77
|
|
|
$arguments |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function getReadOperation(string $entityType, array $arguments = []): ReadOperationInterface |
|
82
|
|
|
{ |
|
83
|
|
|
$hash = md5($entityType . implode('', $arguments)); |
|
84
|
|
|
|
|
85
|
|
|
return $this->readOperationPool[$hash] |
|
86
|
|
|
?? $this->readOperationPool[$hash] = new ReadOperation( |
|
87
|
|
|
$this->requestBuilder, |
|
88
|
|
|
$this->dataObjectFactory, |
|
89
|
|
|
$entityType, |
|
90
|
|
|
$arguments |
|
91
|
|
|
); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getListOperation(string $entityType, array $arguments = []): ListOperationInterface |
|
95
|
|
|
{ |
|
96
|
|
|
$hash = md5($entityType . implode('', $arguments)); |
|
97
|
|
|
|
|
98
|
|
|
return $this->listOperationPool[$hash] |
|
99
|
|
|
?? $this->listOperationPool[$hash] = new ListOperation( |
|
100
|
|
|
$this->requestBuilder, |
|
101
|
|
|
$this->dataObjectFactory, |
|
102
|
|
|
$entityType, |
|
103
|
|
|
$arguments |
|
104
|
|
|
); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function getUpdateOperation(string $entityType, array $arguments = []): UpdateOperationInterface |
|
108
|
|
|
{ |
|
109
|
|
|
$hash = md5($entityType . implode('', $arguments)); |
|
110
|
|
|
|
|
111
|
|
|
return $this->updateOperationPool[$hash] |
|
112
|
|
|
?? $this->updateOperationPool[$hash] = new UpdateOperation( |
|
113
|
|
|
$this->requestBuilder, |
|
114
|
|
|
$this->dataObjectFactory, |
|
115
|
|
|
$entityType, |
|
116
|
|
|
$arguments |
|
117
|
|
|
); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function getDeleteOperation(string $entityType, array $arguments = []): DeleteOperationInterface |
|
121
|
|
|
{ |
|
122
|
|
|
$hash = md5($entityType . implode('', $arguments)); |
|
123
|
|
|
|
|
124
|
|
|
return $this->deleteOperationPool[$hash] |
|
125
|
|
|
?? $this->deleteOperationPool[$hash] = new DeleteOperation( |
|
126
|
|
|
$this->requestBuilder, |
|
127
|
|
|
$entityType, |
|
128
|
|
|
$arguments |
|
129
|
|
|
); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|