1 | <?php |
||
13 | class Reference implements \JsonSerializable |
||
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 | /** |
||
24 | * A valid JSON reference. The reference should point to a location in $schema. |
||
25 | * @see https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03 |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | private $ref; |
||
30 | |||
31 | /** |
||
32 | 42 | * @param object|Closure $schema |
|
33 | * @param string $ref |
||
34 | 42 | */ |
|
35 | 42 | public function __construct($schema, $ref) |
|
40 | |||
41 | /** |
||
42 | * Specify data which should be serialized to JSON. |
||
43 | * Because a reference can be circular, references are always |
||
44 | * re-serialized as the reference property instead of attempting |
||
45 | * to inline the data. |
||
46 | * |
||
47 | * @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
||
48 | 4 | * |
|
49 | * @return mixed data which can be serialized by <b>json_encode</b>, |
||
50 | 4 | * which is a value of any type other than a resource. |
|
51 | */ |
||
52 | public function jsonSerialize() |
||
56 | |||
57 | /** |
||
58 | 38 | * Resolve the reference and return the data. |
|
59 | * |
||
60 | 38 | * @return mixed |
|
61 | 38 | */ |
|
62 | 38 | public function resolve() |
|
69 | |||
70 | /** |
||
71 | * Resolve an external reference and return the resolved schema. |
||
72 | 6 | * |
|
73 | * @return mixed The resolved schema |
||
74 | 6 | */ |
|
75 | 6 | private function resolveExternalReference() |
|
79 | |||
80 | /** |
||
81 | * Resolve an internal reference and return the resolved schema. |
||
82 | * |
||
83 | * @return mixed The resolved schema |
||
84 | */ |
||
85 | private function resolveInternalReference() |
||
91 | |||
92 | /** |
||
93 | * Proxies property access to the underlying schema. |
||
94 | * |
||
95 | * @param string $property |
||
96 | * |
||
97 | * @return mixed |
||
98 | * |
||
99 | * @throws \InvalidArgumentException |
||
100 | */ |
||
101 | public function __get($property) |
||
110 | } |
||
111 |