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\Column\ColumnExpression; |
11
|
|
|
use Brownie\BpmOnline\Exception\ValidateException; |
12
|
|
|
use Brownie\BpmOnline\DataService\Contract; |
13
|
|
|
use Brownie\BpmOnline\DataService\Response\InsertContract as ResponseInsertContract; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* InsertContract Data Contract. |
17
|
|
|
*/ |
18
|
|
|
class InsertContract extends Contract |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
private $dictionary = []; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Sets the input values. |
25
|
|
|
* |
26
|
|
|
* @param string $rootSchemaName The name of the root schema object. |
27
|
|
|
*/ |
28
|
7 |
|
public function __construct($rootSchemaName) |
29
|
|
|
{ |
30
|
7 |
|
parent::__construct([ |
31
|
7 |
|
'rootSchemaName' => $rootSchemaName, |
32
|
7 |
|
'operationType' => Contract::INSERT, |
33
|
7 |
|
'contractType' => Contract::INSERT_QUERY, |
34
|
|
|
]); |
35
|
7 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Adds a ColumnExpression object to the dictionary collection. |
39
|
|
|
* Returns the current object. |
40
|
|
|
* |
41
|
|
|
* @param string $name The name of the column. |
42
|
|
|
* @param ColumnExpression $columnExpression Query expression to the schema object. |
43
|
|
|
* |
44
|
|
|
* @return self |
45
|
|
|
*/ |
46
|
2 |
|
public function addColumn($name, ColumnExpression $columnExpression) |
47
|
|
|
{ |
48
|
2 |
|
$this->dictionary[$name] = $columnExpression; |
49
|
2 |
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Returns data as an associative array. |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
1 |
|
public function toArray() |
58
|
|
|
{ |
59
|
1 |
|
$dictionary = []; |
60
|
|
|
/** |
61
|
|
|
* @var ColumnExpression $columnExpression |
62
|
|
|
*/ |
63
|
1 |
|
foreach ($this->dictionary as $keyName => $columnExpression) { |
64
|
1 |
|
$dictionary[$keyName] = $columnExpression->toArray(); |
65
|
|
|
} |
66
|
|
|
return [ |
67
|
1 |
|
'RootSchemaName' => $this->getRootSchemaName(), |
68
|
1 |
|
'OperationType' => $this->getOperationType(), |
69
|
|
|
'ColumnValues' => [ |
70
|
1 |
|
'Items' => $dictionary |
71
|
|
|
] |
72
|
|
|
]; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Validates contract data, throws an exception in case of an error. |
77
|
|
|
* |
78
|
|
|
* @throws ValidateException |
79
|
|
|
*/ |
80
|
2 |
|
public function validate() |
81
|
|
|
{ |
82
|
2 |
|
if ((1 != $this->getOperationType()) || empty($this->dictionary)) { |
83
|
1 |
|
throw new ValidateException('Invalid contract arguments.'); |
84
|
|
|
} |
85
|
1 |
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Returns the response of the performance contract. |
89
|
|
|
* |
90
|
|
|
* @param string $rawResponse Raw response. |
91
|
|
|
* |
92
|
|
|
* @return ResponseInsertContract |
93
|
|
|
*/ |
94
|
1 |
|
public function getResponse($rawResponse) |
95
|
|
|
{ |
96
|
1 |
|
return new ResponseInsertContract($rawResponse); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|