1
|
|
|
<?php |
2
|
|
|
namespace AlgoWeb\ODataMetadata\MetadataV3\edmx; |
3
|
|
|
|
4
|
|
|
use AlgoWeb\ODataMetadata\IsOK; |
5
|
|
|
use AlgoWeb\ODataMetadata\IsOKTraits\IsOKToolboxTrait; |
6
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\Schema; |
7
|
|
|
|
8
|
|
|
class TDataServicesType extends IsOK |
9
|
|
|
{ |
10
|
|
|
use IsOKToolboxTrait; |
11
|
|
|
/** |
12
|
|
|
* @property \AlgoWeb\ODataMetadata\MetadataV3\edm\Schema[] $schema |
13
|
|
|
*/ |
14
|
|
|
private $schema = []; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @property string $maxDataServiceVersion |
18
|
|
|
*/ |
19
|
|
|
private $maxDataServiceVersion; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @property string $dataServiceVersion |
23
|
|
|
*/ |
24
|
|
|
private $dataServiceVersion; |
25
|
|
|
|
26
|
|
|
public function __construct($maxDataServiceVersion = '3.0', $dataServiceVersion = '3.0') |
27
|
|
|
{ |
28
|
|
View Code Duplication |
if ('3.0' == $this->maxDataServiceVersion && '4.0' == $this->dataServiceVersion) { |
29
|
|
|
$msg = "Data service version cannot be greater than maximum service version"; |
30
|
|
|
throw new \InvalidArgumentException($msg); |
31
|
|
|
} |
32
|
|
|
$this->setDataServiceVersion($dataServiceVersion); |
33
|
|
|
$this->setMaxDataServiceVersion($maxDataServiceVersion); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Gets as MaxDataServiceVersion |
38
|
|
|
* |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
|
|
public function getMaxDataServiceVersion() |
42
|
|
|
{ |
43
|
|
|
return $this->maxDataServiceVersion; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Sets a new DataServiceVersion |
48
|
|
|
* |
49
|
|
|
* @param string $maxDataServiceVersion |
50
|
|
|
* @return self |
51
|
|
|
*/ |
52
|
|
|
public function setMaxDataServiceVersion($maxDataServiceVersion) |
53
|
|
|
{ |
54
|
|
|
$maxDataValid = ['3.0', '4.0']; |
55
|
|
|
if (!in_array($maxDataServiceVersion, $maxDataValid)) { |
56
|
|
|
$msg = "Maximum data service version must be 3.0 or 4.0"; |
57
|
|
|
throw new \InvalidArgumentException($msg); |
58
|
|
|
} |
59
|
|
|
$this->maxDataServiceVersion = $maxDataServiceVersion; |
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Gets as DataServiceVersion |
65
|
|
|
* |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
public function getDataServiceVersion() |
69
|
|
|
{ |
70
|
|
|
return $this->dataServiceVersion; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Sets a new DataServiceVersion |
75
|
|
|
* |
76
|
|
|
* @param string $dataServiceVersion |
77
|
|
|
* @return self |
78
|
|
|
*/ |
79
|
|
|
public function setDataServiceVersion($dataServiceVersion) |
80
|
|
|
{ |
81
|
|
|
$dataValid = ['1.0', '2.0', '3.0', '4.0']; |
82
|
|
|
if (!in_array($dataServiceVersion, $dataValid)) { |
83
|
|
|
$msg = "Data service version must be 1.0, 2.0, 3.0 or 4.0"; |
84
|
|
|
throw new \InvalidArgumentException($msg); |
85
|
|
|
} |
86
|
|
|
$this->dataServiceVersion = $dataServiceVersion; |
87
|
|
|
return $this; |
88
|
|
|
} |
89
|
|
|
/** |
90
|
|
|
* Adds as schema |
91
|
|
|
* |
92
|
|
|
* @return self |
93
|
|
|
* @param \AlgoWeb\ODataMetadata\MetadataV3\edm\Schema $schema |
94
|
|
|
*/ |
95
|
|
|
public function addToSchema(Schema $schema) |
96
|
|
|
{ |
97
|
|
|
$msg = null; |
98
|
|
|
if (!$schema->isOK($msg)) { |
99
|
|
|
throw new \InvalidArgumentException($msg); |
100
|
|
|
} |
101
|
|
|
$this->schema[] = $schema; |
102
|
|
|
return $this; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* isset schema |
107
|
|
|
* |
108
|
|
|
* @param scalar $index |
109
|
|
|
* @return boolean |
110
|
|
|
*/ |
111
|
|
|
public function issetSchema($index) |
112
|
|
|
{ |
113
|
|
|
return isset($this->schema[$index]); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* unset schema |
118
|
|
|
* |
119
|
|
|
* @param scalar $index |
120
|
|
|
* @return void |
121
|
|
|
*/ |
122
|
|
|
public function unsetSchema($index) |
123
|
|
|
{ |
124
|
|
|
unset($this->schema[$index]); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Gets as schema |
129
|
|
|
* |
130
|
|
|
* @return \AlgoWeb\ODataMetadata\MetadataV3\edm\Schema[] |
131
|
|
|
*/ |
132
|
|
|
public function getSchema() |
133
|
|
|
{ |
134
|
|
|
return $this->schema; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Sets a new schema |
139
|
|
|
* |
140
|
|
|
* @param \AlgoWeb\ODataMetadata\MetadataV3\edm\Schema[] $dataServices |
141
|
|
|
* @return self |
142
|
|
|
*/ |
143
|
|
|
public function setSchema(array $dataServices) |
144
|
|
|
{ |
145
|
|
|
if (!$this->isValidArrayOK( |
146
|
|
|
$dataServices, |
147
|
|
|
'\AlgoWeb\ODataMetadata\MetadataV3\edm\Schema' |
148
|
|
|
)) { |
149
|
|
|
$msg = "Data services array not a valid array"; |
150
|
|
|
throw new \InvalidArgumentException($msg); |
151
|
|
|
} |
152
|
|
|
$this->schema = $dataServices; |
153
|
|
|
return $this; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function isOK(&$msg = null) |
157
|
|
|
{ |
158
|
|
|
$dataValid = ['1.0', '2.0', '3.0', '4.0']; |
159
|
|
|
$maxDataValid = ['3.0', '4.0']; |
160
|
|
|
if (!in_array($this->maxDataServiceVersion, $maxDataValid)) { |
161
|
|
|
$msg = "Maximum data service version must be 3.0 or 4.0"; |
162
|
|
|
return false; |
163
|
|
|
} |
164
|
|
|
if (!in_array($this->dataServiceVersion, $dataValid)) { |
165
|
|
|
$msg = "Data service version must be 1.0, 2.0, 3.0 or 4.0"; |
166
|
|
|
return false; |
167
|
|
|
} |
168
|
|
View Code Duplication |
if ('3.0' == $this->maxDataServiceVersion && '4.0' == $this->dataServiceVersion) { |
169
|
|
|
$msg = "Data service version cannot be greater than maximum service version"; |
170
|
|
|
return false; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
if (!$this->isValidArrayOK($this->schema, '\AlgoWeb\ODataMetadata\MetadataV3\edm\Schema', $msg, 1)) { |
174
|
|
|
return false; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
return true; |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|