1 | <?php |
||
9 | class JsonValidator |
||
10 | { |
||
11 | /** @var \stdClass */ |
||
12 | private $schema; |
||
13 | |||
14 | /** |
||
15 | * JsonSchema constructor. |
||
16 | * Consider using one of the following factories instead of invoking the controller directly: |
||
17 | * - JsonValidator::fromFile() |
||
18 | * - JsonValidator::fromEncodedString() |
||
19 | * - JsonValidator::fromDecodedObject() |
||
20 | * - JsonValidator::fromArray() |
||
21 | * |
||
22 | * @param \stdClass $schema A JSON-decoded object-representation of the schema. |
||
23 | */ |
||
24 | public function __construct(\stdClass $schema) |
||
28 | |||
29 | /** |
||
30 | * @param \stdClass $schema |
||
31 | * @return static|callable |
||
32 | */ |
||
33 | public static function fromDecodedObject(\stdClass $schema) |
||
37 | |||
38 | /** |
||
39 | * @param \SplFileObject $file |
||
40 | * @return static|callable |
||
41 | */ |
||
42 | public static function fromFile(\SplFileObject $file) |
||
50 | |||
51 | /** |
||
52 | * @param string $json |
||
53 | * @return static|callable |
||
54 | */ |
||
55 | public static function fromEncodedString($json) |
||
59 | |||
60 | /** |
||
61 | * @param array $json |
||
62 | * @return static|callable |
||
63 | */ |
||
64 | public static function fromArray(array $json) |
||
68 | |||
69 | /** |
||
70 | * Execute the middleware. |
||
71 | * |
||
72 | * @param ServerRequestInterface $request |
||
73 | * @param ResponseInterface $response |
||
74 | * @param callable $next |
||
75 | * |
||
76 | * @return ResponseInterface |
||
77 | * @throws \RuntimeException |
||
78 | * @throws \InvalidArgumentException |
||
79 | * @throws \JsonSchema\Exception\ExceptionInterface |
||
80 | */ |
||
81 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
107 | |||
108 | /** |
||
109 | * @param ResponseInterface $response |
||
110 | * @param string $reason |
||
111 | * @param string[] $headers |
||
112 | * @param string|null $body |
||
113 | * |
||
114 | * @return ResponseInterface |
||
115 | * @throws \RuntimeException |
||
116 | * @throws \InvalidArgumentException |
||
117 | */ |
||
118 | private function invalidateResponse(ResponseInterface $response, $reason, array $headers = [], $body = null) |
||
133 | } |
||
134 |