|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
namespace AlgoWeb\ODataMetadata\MetadataV3\Edmx; |
|
7
|
|
|
|
|
8
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\DomBase; |
|
9
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\Edm\EdmBase; |
|
10
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\Edm\Schema; |
|
11
|
|
|
use AlgoWeb\ODataMetadata\OdataVersions; |
|
12
|
|
|
use AlgoWeb\ODataMetadata\Writer\AttributeContainer; |
|
13
|
|
|
use AlgoWeb\ODataMetadata\Writer\WriterContext; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class TEdmxType. |
|
17
|
|
|
* |
|
18
|
|
|
* 3.1 The edmx:Edmx Element |
|
19
|
|
|
* |
|
20
|
|
|
* An OData service exposes a single entity model. A CSDL description of the entity model can be requested from |
|
21
|
|
|
* $metadata. |
|
22
|
|
|
* |
|
23
|
|
|
* The document returned by $metadata MUST contain a single root edmx:Edmx element. This element MUST contain a single |
|
24
|
|
|
* direct child edmx:DataServices element. The data services element contains a description of the entity model(s) |
|
25
|
|
|
* exposed by the OData service. |
|
26
|
|
|
* |
|
27
|
|
|
* In addition to the data services element, Edmx may have zero or more edmx:Reference elements and zero or more |
|
28
|
|
|
* edmx:AnnotationsReference elements. Reference elements specify the location of schemas referenced by the OData |
|
29
|
|
|
* service. Annotations reference elements specify the location of annotations to be applied to the OData service. |
|
30
|
|
|
* |
|
31
|
|
|
* The following example demonstrates the basic structure of the Edmx element and the edmx:DataServices element: |
|
32
|
|
|
* |
|
33
|
|
|
* <edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" Version="1.0"> |
|
34
|
|
|
* <edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="2.0"> |
|
35
|
|
|
* <Schema ... /> |
|
36
|
|
|
* </edmx:DataServices> |
|
37
|
|
|
* </edmx:Edmx> |
|
38
|
|
|
* |
|
39
|
|
|
* The edmx:Edmx element defines the XML namespace for the EDMX document and contains the edmx:DataServices sub-element. |
|
40
|
|
|
* The following rules apply to the edmx:Edmx element: |
|
41
|
|
|
* An EDMX document MUST have exactly one edmx:Edmx element as its root element. |
|
42
|
|
|
* The Version attribute MUST be defined on the edmx:Edmx element. Version is of type xs:string, as specified in the |
|
43
|
|
|
* XML schema [XMLSCHEMA1]. |
|
44
|
|
|
* The edmx:Edmx element can contain a choice of zero or more of each of the following sub-elements: |
|
45
|
|
|
* edmx:Reference |
|
46
|
|
|
* edmx:AnnotationsReference |
|
47
|
|
|
* |
|
48
|
|
|
* Sub-elements in a given choice set can appear in any given order. |
|
49
|
|
|
* The edmx:Edmx element specifies exactly one edmx:DataServices sub-element. This sub-element MUST appear after the |
|
50
|
|
|
* edmx:Reference and edmx:AnnotationReference sub-elements, if present. |
|
51
|
|
|
* |
|
52
|
|
|
* @package AlgoWeb\ODataMetadata\MetadataV3 |
|
53
|
|
|
*/ |
|
54
|
|
|
class Edmx extends DomBase |
|
55
|
|
|
{ |
|
56
|
|
|
/** |
|
57
|
|
|
* @var string $version 3.1.1 The Version Attribute |
|
58
|
|
|
* The Version attribute MUST be present on the edmx:Edmx element. |
|
59
|
|
|
* |
|
60
|
|
|
* The Version attribute is a string value that specifies the version of the EDMX wrapper, and must be of the |
|
61
|
|
|
* form .. This version of the specification defines version 1.0 of the EDMX Wrapper. |
|
62
|
|
|
*/ |
|
63
|
|
|
private $version = '1.0'; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @var DataServices|Schema[] $dataServices 3.2 The edmx:DataServices Element |
|
67
|
|
|
* The edmx:DataServices element contains zero or more Edm:Schema elements which define the schema(s) exposed by |
|
68
|
|
|
* the OData service. |
|
69
|
|
|
*/ |
|
70
|
|
|
private $dataServices; |
|
71
|
|
|
|
|
72
|
|
|
public function __construct() |
|
73
|
|
|
{ |
|
74
|
|
|
$this->dataServices = new DataServices(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Adds as schema. |
|
79
|
|
|
* |
|
80
|
|
|
* @param Schema $schema |
|
81
|
|
|
* @return self |
|
82
|
|
|
*/ |
|
83
|
|
|
public function addToDataServices(Schema $schema) |
|
84
|
|
|
{ |
|
85
|
|
|
$this->dataServices[] = $schema; |
|
86
|
|
|
return $this; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* isset dataServices. |
|
91
|
|
|
* |
|
92
|
|
|
* @param int|string $index |
|
93
|
|
|
* @return bool |
|
94
|
|
|
*/ |
|
95
|
|
|
public function issetDataServices($index) |
|
96
|
|
|
{ |
|
97
|
|
|
return isset($this->dataServices[$index]); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* unset dataServices. |
|
102
|
|
|
* |
|
103
|
|
|
* @param int|string $index |
|
104
|
|
|
* @return void |
|
105
|
|
|
*/ |
|
106
|
|
|
public function unsetDataServices($index) |
|
107
|
|
|
{ |
|
108
|
|
|
unset($this->dataServices[$index]); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Gets as dataServices. |
|
113
|
|
|
* |
|
114
|
|
|
* @return Schema[] |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getDataServices() |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->dataServices; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Sets a new dataServices. |
|
123
|
|
|
* |
|
124
|
|
|
* @param Schema[] $dataServices |
|
125
|
|
|
* @return self |
|
126
|
|
|
*/ |
|
127
|
|
|
public function setDataServices(array $dataServices) |
|
128
|
|
|
{ |
|
129
|
|
|
$this->dataServices = $dataServices; |
|
130
|
|
|
return $this; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @return array|AttributeContainer[] |
|
135
|
|
|
*/ |
|
136
|
|
|
public function getAttributes(): array |
|
137
|
|
|
{ |
|
138
|
|
|
return [ |
|
139
|
|
|
new AttributeContainer('Version', $this->version) |
|
140
|
|
|
]; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* @return array|DomBase[] |
|
145
|
|
|
*/ |
|
146
|
|
|
public function getChildElements(): array |
|
147
|
|
|
{ |
|
148
|
|
|
return [$this->getDataServices()]; |
|
|
|
|
|
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @return string |
|
153
|
|
|
*/ |
|
154
|
|
|
public function getDomName(): string |
|
155
|
|
|
{ |
|
156
|
|
|
return 'edmx:Edmx'; |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: