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