forked from iamcal/oembed
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.php
98 lines (82 loc) · 2.31 KB
/
test.php
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
$num_files = 0;
$num_entries = 0;
$expected_keys = array(
'#' => 1,
'#/provider_name' => 1,
'#/provider_url' => 1,
'#/endpoints' => 1,
'#/endpoints/#' => 1,
'#/endpoints/#/schemes' => 1,
'#/endpoints/#/schemes/#' => 1,
'#/endpoints/#/url' => 1,
'#/endpoints/#/example_urls' => 1,
'#/endpoints/#/example_urls/#' => 1,
'#/endpoints/#/discovery' => 1,
'#/endpoints/#/formats' => 1,
'#/endpoints/#/formats/#' => 1,
'#/endpoints/#/notes' => 1,
'#/endpoints/#/notes/#' => 1,
'#/endpoints/#/docs_url' => 1,
);
$dh = opendir('providers');
while (($file = readdir($dh)) !== false){
if (preg_match('!\.yml$!', $file)){
$partial = yaml_parse_file("providers/$file");
if (!$partial || !is_array($partial)){
echo "Unable to parse provider file providers/$file\n";
exit(1);
}
$num_files++;
$num_entries += count($partial);
#
# check for any unexpected keys
#
$keys = check_keys($partial);
foreach ($keys as $k){
if (!isset($expected_keys[$k])){
echo "Unexpected key {$k} in provider file providers/$file\n";
exit(1);
}
}
#
# check that we define at least one endpoint and that each endpoint has a scheme and a url
#
foreach ($partial as $def){
if (!isset($def['endpoints']) || !count($def['endpoints'])){
echo "No endpoints defined in provider file providers/$file\n";
exit(1);
}
foreach ($def['endpoints'] as $endpoint){
# NOTE: this is disabled because it counts e.g. wordpress as broken.
# maybe it is?
# if (!isset($endpoint['schemes']) || !count($endpoint['schemes'])){
# echo "Endpoint without schemes found in provider file providers/$file\n";
# print_r($endpoint);
# exit(1);
# }
if (!isset($endpoint['url'])){
echo "Endpoint without URL found in provider file providers/$file\n";
print_r($endpoint);
exit(1);
}
}
}
}
}
echo "Loaded $num_files provider files, containing $num_entries entries\n";
exit(0);
function check_keys($a){
$out = array();
check_keys_inner('', $a, $out);
return array_keys($out);
}
function check_keys_inner($prefix, $a, &$out){
foreach ($a as $k => $v){
$key = is_int($k) ? '#' : $k;
$out[$prefix.$key] = 1;
if (is_array($v)){
check_keys_inner($prefix.$key.'/', $v, $out);
}
}
}