1 | <?php |
||
8 | class JsonSchema |
||
9 | { |
||
10 | /** @var string[] */ |
||
11 | private $schemas; |
||
12 | |||
13 | /** @var callable|null */ |
||
14 | private $errorHandler; |
||
15 | |||
16 | /** |
||
17 | * JsonSchema constructor. |
||
18 | * |
||
19 | * @param string[] $schemas [uri => file] An associative array of HTTP URI to validation schema |
||
20 | */ |
||
21 | public function __construct(array $schemas) |
||
25 | |||
26 | /** |
||
27 | * Execute the middleware. |
||
28 | * |
||
29 | * @param ServerRequestInterface $request |
||
30 | * @param ResponseInterface $response |
||
31 | * @param callable $next |
||
32 | * |
||
33 | * @return ResponseInterface |
||
34 | */ |
||
35 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
50 | |||
51 | /** |
||
52 | * @param ServerRequestInterface $request |
||
53 | * |
||
54 | * @return \SplFileObject|null |
||
55 | */ |
||
56 | private function getSchema(ServerRequestInterface $request) |
||
69 | |||
70 | /** |
||
71 | * @param string |
||
72 | * |
||
73 | * @return string |
||
74 | */ |
||
75 | private function normalizeFilePath($path) |
||
84 | |||
85 | /** |
||
86 | * Has the following method signature: |
||
87 | * function (ServerRequestInterface $request, ResponseInterface $response): ResponseInterface {} |
||
88 | * |
||
89 | * Validation errors are stored in a middleware attribute: |
||
90 | * $request->getAttribute(Middleware::KEY, [])[JsonValidator::KEY]; |
||
91 | * |
||
92 | * @param callable $errorHandler |
||
93 | * @return void |
||
94 | */ |
||
95 | public function errorHandler(callable $errorHandler) |
||
99 | } |
||
100 |