1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Swaggest\JsonSchema\Structure; |
4
|
|
|
|
5
|
|
|
use Swaggest\JsonSchema\MagicMapTrait; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Trait ObjectItemTrait |
9
|
|
|
* @package Swaggest\JsonSchema\Structure |
10
|
|
|
* @see ObjectItemContract |
11
|
|
|
*/ |
12
|
|
|
trait ObjectItemTrait |
13
|
|
|
{ |
14
|
|
|
use MagicMapTrait; |
15
|
|
|
|
16
|
|
|
/** @var ObjectItem[] */ |
17
|
|
|
protected $__nestedObjects; |
18
|
|
|
protected $__documentPath; |
19
|
|
|
protected $__fromRef; |
20
|
|
|
|
21
|
|
|
public function getNestedObject($className) { |
22
|
|
|
if (isset($this->__nestedObjects[$className])) { |
23
|
|
|
return $this->__nestedObjects[$className]; |
24
|
|
|
} |
25
|
|
|
return null; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function setNestedProperty($propertyName, $value, Egg $nestedEgg) |
29
|
|
|
{ |
30
|
|
|
$nestedName = $nestedEgg->name; |
31
|
|
|
$nested = &$this->__nestedObjects[$nestedName]; |
32
|
|
|
if (null === $nested) { |
33
|
|
|
$nested = $nestedEgg->classSchema->makeObjectItem(); |
34
|
|
|
$this->__nestedObjects[$nestedName] = $nested; |
35
|
|
|
if ($nestedName !== $nestedEgg->classSchema->objectItemClass) { |
36
|
|
|
$this->$nestedName = $nested; |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
$nested->$propertyName = $value; |
40
|
|
|
$this->__arrayOfData[$propertyName] = &$nested->$propertyName; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected $__additionalPropertyNames; |
44
|
|
|
public function addAdditionalPropertyName($name) |
45
|
|
|
{ |
46
|
|
|
$this->__additionalPropertyNames[] = $name; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return null|string[] |
51
|
|
|
*/ |
52
|
|
|
public function getAdditionalPropertyNames() |
53
|
|
|
{ |
54
|
|
|
return $this->__additionalPropertyNames; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected $__patternPropertyNames; |
58
|
|
|
|
59
|
|
|
public function addPatternPropertyName($pattern, $name) |
60
|
|
|
{ |
61
|
|
|
$this->__patternPropertyNames[$pattern][] = $name; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param $pattern |
66
|
|
|
* @return null|string[] |
67
|
|
|
*/ |
68
|
|
|
public function getPatternPropertyNames($pattern) |
69
|
|
|
{ |
70
|
|
|
if (isset($this->__patternPropertyNames[$pattern])) { |
71
|
|
|
return $this->__patternPropertyNames[$pattern]; |
72
|
|
|
} else { |
73
|
|
|
return null; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function jsonSerialize() |
78
|
|
|
{ |
79
|
|
|
if ($this->__nestedObjects) { |
80
|
|
|
$result = $this->__arrayOfData; |
81
|
|
|
foreach ($this->__nestedObjects as $object) { |
82
|
|
|
foreach ($object->toArray() as $key => $value) { |
83
|
|
|
$result[$key] = $value; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
return (object)$result; |
87
|
|
|
} else { |
88
|
|
|
return (object)$this->__arrayOfData; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public function getDocumentPath() |
96
|
|
|
{ |
97
|
|
|
return $this->__documentPath; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function setDocumentPath($path) |
101
|
|
|
{ |
102
|
|
|
$this->__documentPath = $path; |
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
|
|
public function getFromRef() |
110
|
|
|
{ |
111
|
|
|
return $this->__fromRef; |
112
|
|
|
} |
113
|
|
|
} |