blob: 50b25cc38c61e28d50d5b180110a13c287d0dc08 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
<?php
declare(strict_types = 1);
namespace Williamdes\MariaDBMySQLKBS\Test;
use \Swaggest\JsonSchema\RemoteRefProvider;
class RefProvider implements RemoteRefProvider
{
/**
* Preloaded urn schemas
*
* @var \stdClass[]
*/
private $urnSchemas = [];
/**
* Create a new RefProvider instance
*/
public function __construct()
{
$files = glob(__DIR__ . "/../schemas/*.json");
if ($files === false) {
return;
} else {
foreach ($files as $filename) {
$schema = json_decode((string) file_get_contents($filename));
if (isset($schema) && isset($schema->{'$id'}) && $schema !== null) {
$this->urnSchemas[$schema->{'$id'}] = $schema;
}
}
}
}
/**
* @param string $url The file url
* @return \stdClass|false json_decode of $url resource content
*/
public function getSchemaData($url)
{
if (isset($this->urnSchemas[$url])) {// Handle urn: urls
return $this->urnSchemas[$url];
} elseif (is_file($url)) {// Handle file
return json_decode((string) file_get_contents($url));
} else {// Handle URL
return json_decode((string) file_get_contents(rawurldecode($url)));
}
}
}
|