|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Swaggest\JsonSchema\Structure; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use Swaggest\JsonSchema\MagicMap; |
|
7
|
|
|
use Swaggest\JsonSchema\Schema; |
|
8
|
|
|
|
|
9
|
|
|
class ObjectItem extends MagicMap |
|
10
|
|
|
{ |
|
11
|
|
|
/** @var ObjectItem[] */ |
|
12
|
|
|
protected $__nestedObjects; |
|
13
|
|
|
|
|
14
|
|
|
public function setNestedProperty($propertyName, $value, Egg $nestedEgg) |
|
15
|
|
|
{ |
|
16
|
|
|
$nestedName = $nestedEgg->name; |
|
17
|
|
|
$nested = &$this->__nestedObjects[$nestedName]; |
|
18
|
|
|
if (null === $nested) { |
|
19
|
|
|
$nested = $nestedEgg->classSchema->makeObjectItem(); |
|
20
|
|
|
$this->__nestedObjects[$nestedName] = $nested; |
|
21
|
|
|
if ($nestedName !== $nestedEgg->classSchema->objectItemClass) { |
|
22
|
|
|
$this->$nestedName = $nested; |
|
23
|
|
|
} |
|
24
|
|
|
} |
|
25
|
|
|
$nested->$propertyName = $value; |
|
26
|
|
|
$this->__arrayOfData[$propertyName] = &$nested->$propertyName; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
protected $__additionalPropertyNames; |
|
30
|
|
|
public function addAdditionalPropertyName($name) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->__additionalPropertyNames[] = $name; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @return null|string[] |
|
37
|
|
|
*/ |
|
38
|
|
|
public function getAdditionalPropertyNames() |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->__additionalPropertyNames; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
protected $__patternPropertyNames; |
|
44
|
|
|
|
|
45
|
|
|
public function addPatternPropertyName($pattern, $name) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->__additionalPropertyNames[$pattern][] = $name; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param $pattern |
|
52
|
|
|
* @return null|string[] |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getPatternPropertyNames($pattern) |
|
55
|
|
|
{ |
|
56
|
|
|
if (isset($this->__patternPropertyNames[$pattern])) { |
|
57
|
|
|
return $this->__patternPropertyNames[$pattern]; |
|
58
|
|
|
} else { |
|
59
|
|
|
return null; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function jsonSerialize() |
|
64
|
|
|
{ |
|
65
|
|
|
if ($this->__nestedObjects) { |
|
|
|
|
|
|
66
|
|
|
$result = $this->__arrayOfData; |
|
67
|
|
|
foreach ($this->__nestedObjects as $object) { |
|
68
|
|
|
foreach ($object->__arrayOfData as $key => $value) { |
|
69
|
|
|
$result[$key] = $value; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
return (object)$result; |
|
73
|
|
|
} else { |
|
74
|
|
|
return (object)$this->__arrayOfData; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
} |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.