1 | <?php |
||
13 | class Reference implements \JsonSerializable, \IteratorAggregate |
||
14 | { |
||
15 | /** |
||
16 | * A JSON object resulting from a json_decode call or a Closure. |
||
17 | * If a closure is used it should resolve to a JSON object when called. |
||
18 | * |
||
19 | * @var object|Closure |
||
20 | */ |
||
21 | private $schema; |
||
22 | |||
23 | private $cached; |
||
24 | |||
25 | /** |
||
26 | * A valid JSON reference. The reference should point to a location in $schema. |
||
27 | * @see https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03 |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | private $ref; |
||
32 | |||
33 | /** |
||
34 | * @param object|Closure $schema |
||
35 | 62 | * @param string $ref |
|
36 | */ |
||
37 | 62 | public function __construct($schema, $ref) |
|
42 | |||
43 | /** |
||
44 | * Specify data which should be serialized to JSON. |
||
45 | * Because a reference can be circular, references are always |
||
46 | * re-serialized as the reference property instead of attempting |
||
47 | * to inline the data. |
||
48 | * |
||
49 | * @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
||
50 | * |
||
51 | * @return mixed data which can be serialized by <b>json_encode</b>, |
||
52 | 10 | * which is a value of any type other than a resource. |
|
53 | */ |
||
54 | 10 | public function jsonSerialize() |
|
58 | |||
59 | /** |
||
60 | * Resolve the reference and return the data. |
||
61 | * |
||
62 | 58 | * @return mixed |
|
63 | */ |
||
64 | 58 | public function resolve() |
|
76 | |||
77 | 26 | /** |
|
78 | * Resolve an external reference and return the resolved schema. |
||
79 | * |
||
80 | * @return mixed The resolved schema |
||
81 | */ |
||
82 | private function resolveExternalReference() |
||
86 | |||
87 | 44 | /** |
|
88 | 44 | * Resolve an internal reference and return the resolved schema. |
|
89 | 44 | * |
|
90 | * @return mixed The resolved schema |
||
91 | */ |
||
92 | private function resolveInternalReference() |
||
98 | |||
99 | /** |
||
100 | * Proxies property access to the underlying schema. |
||
101 | 16 | * |
|
102 | * @param string $property |
||
103 | 16 | * |
|
104 | 16 | * @return mixed |
|
105 | 14 | * |
|
106 | * @throws \InvalidArgumentException |
||
107 | */ |
||
108 | 2 | public function __get($property) |
|
117 | |||
118 | public function getIterator() |
||
122 | } |
||
123 |