|
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\Writer\AttributeContainer; |
|
12
|
|
|
use AlgoWeb\ODataMetadata\Writer\WriterContext; |
|
13
|
|
|
use ArrayAccess; |
|
14
|
|
|
use DOMElement; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class DataServices. |
|
18
|
|
|
* |
|
19
|
|
|
* 3.2 The edmx:DataServices Element |
|
20
|
|
|
* The edmx:DataServices element contains zero or more Edm:Schema elements which define the schema(s) exposed by the |
|
21
|
|
|
* OData service. |
|
22
|
|
|
* |
|
23
|
|
|
* The edmx:DataServices element contains the service metadata of a data service. This service metadata contains zero |
|
24
|
|
|
* or more Entity Data Model (EDM) conceptual schemas (as specified in [MC-CSDL]), which are annotated as specified in |
|
25
|
|
|
* [MS-ODATA]. |
|
26
|
|
|
* |
|
27
|
|
|
* The following represents the edmx:DataServices element. |
|
28
|
|
|
* |
|
29
|
|
|
* <edmx:DataServices> |
|
30
|
|
|
* |
|
31
|
|
|
* The following rule applies to the edmx:DataServices element: |
|
32
|
|
|
* The edmx:DataServices element can contain any number of Schema sub-elements.<1> |
|
33
|
|
|
* @package AlgoWeb\ODataMetadata\MetadataV3 |
|
34
|
|
|
*/ |
|
35
|
|
|
class DataServices extends DomBase implements ArrayAccess |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* @return string |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getDomName(): string |
|
41
|
|
|
{ |
|
42
|
|
|
return 'edmx:DataServices'; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param WriterContext|null $wc |
|
47
|
|
|
* @return array|AttributeContainer[] |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getAttributes(WriterContext $wc = null): array |
|
50
|
|
|
{ |
|
51
|
|
|
/** |
|
52
|
|
|
* @return string 3.2.1 The metadata:DataServiceVersion Attribute |
|
53
|
|
|
* The metadata:DataServiceVersion attribute describes the version of OData protocol required to consume the service. |
|
54
|
|
|
* This version of the specification defines the following valid data service version values: |
|
55
|
|
|
* "1.0", "2.0", and "3.0", corresponding to OData protocol versions 1.0, 2.0 and 3.0 respectively. |
|
56
|
|
|
*/ |
|
57
|
|
|
return [ |
|
58
|
|
|
new AttributeContainer('metadata:DataServiceVersion', $wc->/** @scrutinizer ignore-call */getOdataVersion()) |
|
59
|
|
|
]; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return array|DomBase[] |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getChildElements(): array |
|
66
|
|
|
{ |
|
67
|
|
|
return empty($this->schema) ? [new Schema()] : $this->schema; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @var Schema[] $dataServices 3.2 The edmx:DataServices Element |
|
72
|
|
|
* The edmx:DataServices element contains zero or more Edm:Schema elements which define the schema(s) exposed by |
|
73
|
|
|
* the OData service. |
|
74
|
|
|
*/ |
|
75
|
|
|
private $schema = []; |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
public function offsetExists($offset) |
|
80
|
|
|
{ |
|
81
|
|
|
return array_key_exists($offset, $this->schema); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function offsetGet($offset) |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->schema[$offset]; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function offsetSet($offset, $value) |
|
90
|
|
|
{ |
|
91
|
|
|
if (null === $offset) { |
|
92
|
|
|
$this->schema[] = $value; |
|
93
|
|
|
} else { |
|
94
|
|
|
$this->schema[$offset] = $value; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function offsetUnset($offset) |
|
99
|
|
|
{ |
|
100
|
|
|
unset($this->schema[$offset]); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|