1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @category Brownie/BpmOnline |
4
|
|
|
* @author Brownie <[email protected]> |
5
|
|
|
* @license https://opensource.org/licenses/MIT |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Brownie\BpmOnline\DataService\Contract; |
9
|
|
|
|
10
|
|
|
use Brownie\BpmOnline\DataService\Contract; |
11
|
|
|
use Brownie\BpmOnline\Exception\ValidateException; |
12
|
|
|
use Brownie\BpmOnline\DataService\Response\BatchContract as ResponseBranchContract; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* BatchContract Data Contract. |
16
|
|
|
*/ |
17
|
|
|
class BatchContract extends Contract |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Contracts. |
22
|
|
|
* |
23
|
|
|
* @var Contract[] |
24
|
|
|
*/ |
25
|
|
|
private $contracts = []; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Sets the input values. |
29
|
|
|
* |
30
|
|
|
* BatchContract constructor. |
31
|
|
|
*/ |
32
|
5 |
|
public function __construct() |
33
|
|
|
{ |
34
|
5 |
|
parent::__construct([ |
35
|
5 |
|
'operationType' => Contract::BATCH, |
36
|
5 |
|
'contractType' => Contract::BATCH_QUERY, |
37
|
|
|
]); |
38
|
5 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Adding contract. |
42
|
|
|
* |
43
|
|
|
* @param Contract $contract Contract. |
44
|
|
|
* |
45
|
|
|
* @return self |
46
|
|
|
*/ |
47
|
3 |
|
public function addContract(Contract $contract) |
48
|
|
|
{ |
49
|
3 |
|
$this->contracts[] = $contract; |
50
|
3 |
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Returns contracts. |
55
|
|
|
* |
56
|
|
|
* @return Contract[] |
57
|
|
|
*/ |
58
|
4 |
|
private function getContracts() |
59
|
|
|
{ |
60
|
4 |
|
return $this->contracts; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Returns data as an associative array. |
65
|
|
|
* |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
1 |
|
public function toArray() |
69
|
|
|
{ |
70
|
1 |
|
$items = []; |
71
|
1 |
|
foreach ($this->getContracts() as $index => $contract) { |
72
|
1 |
|
$items[] = array_merge( |
73
|
1 |
|
['__type' => 'Terrasoft.Nui.ServiceModel.DataContract.' . $contract->getContractType()], |
74
|
1 |
|
$contract->toArray() |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
return [ |
78
|
1 |
|
'items' => $items |
79
|
|
|
]; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Validates contract data, throws an exception in case of an error. |
84
|
|
|
* |
85
|
|
|
* @throws ValidateException |
86
|
|
|
*/ |
87
|
2 |
|
public function validate() |
88
|
|
|
{ |
89
|
2 |
|
if (empty($this->getContracts())) { |
90
|
1 |
|
throw new ValidateException('Invalid contract arguments.'); |
91
|
|
|
} |
92
|
1 |
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Returns the response of the performance contract. |
96
|
|
|
* |
97
|
|
|
* @param string $rawResponse Raw response. |
98
|
|
|
* |
99
|
|
|
* @return ResponseBranchContract |
100
|
|
|
*/ |
101
|
1 |
|
public function getResponse($rawResponse) |
102
|
|
|
{ |
103
|
1 |
|
return new ResponseBranchContract($rawResponse, $this->getContracts()); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|