1 | <?php |
||
2 | |||
3 | namespace Cohensive\OEmbed; |
||
4 | |||
5 | use \Exception; |
||
0 ignored issues
–
show
|
|||
6 | |||
7 | class ImportProviders |
||
8 | { |
||
9 | public function generateProviders() |
||
10 | { |
||
11 | $response = file_get_contents('https://oembed.com/providers.json'); |
||
12 | |||
13 | if (!$response) { |
||
14 | throw new Exception('Error reteriving providers list.'); |
||
15 | } |
||
16 | |||
17 | $providers = json_decode($response, true); |
||
18 | |||
19 | $providerFormat = <<<END |
||
20 | [ |
||
21 | 'provider_name' => '%s', |
||
22 | 'provider_url' => '%s', |
||
23 | 'endpoints' => [ |
||
24 | %s |
||
25 | ] |
||
26 | ], |
||
27 | |||
28 | END; |
||
29 | |||
30 | $endpointFormat = <<<END |
||
31 | [ |
||
32 | 'schemes' => [ |
||
33 | %s |
||
34 | ], |
||
35 | 'url' => '%s', |
||
36 | ], |
||
37 | END; |
||
38 | |||
39 | $schemeFormat = <<<END |
||
40 | '%s', |
||
41 | END; |
||
42 | |||
43 | $formattedProviders = ''; |
||
44 | foreach ($providers as $provider) { |
||
45 | $endpoints = ''; |
||
46 | foreach ($provider['endpoints'] as $ekey => $endpoint) { |
||
47 | if (!isset($endpoint['schemes'])) { |
||
48 | continue; |
||
49 | } |
||
50 | |||
51 | $schemes = ''; |
||
52 | $url = str_replace('.{format}', '.json', $endpoint['url']); |
||
53 | $url = str_replace('?format={format}', '?format=json', $url); |
||
0 ignored issues
–
show
|
|||
54 | foreach ($endpoint['schemes'] as $skey => $url) { |
||
55 | $scheme = '|^' . $url; |
||
56 | $scheme = preg_replace('/([.=?#-])/i', '\\\\\\\\${1}', $scheme); |
||
57 | $scheme = str_replace('http:', 'https?:', $scheme); |
||
58 | $scheme = str_replace('https:', 'https?:', $scheme); |
||
59 | $scheme = str_replace('*', '.*', $scheme); |
||
60 | $scheme .= '$|i'; |
||
61 | $schemes .= ($skey > 0 ? "\n " : "") . sprintf($schemeFormat, $scheme); |
||
62 | } |
||
63 | $endpoints .= ($ekey > 0 ? "\n " : "") . sprintf($endpointFormat, $schemes, $endpoint['url']); |
||
64 | } |
||
65 | |||
66 | $formattedProviders .= sprintf( |
||
67 | $providerFormat, |
||
68 | $provider['provider_name'], |
||
69 | $provider['provider_url'], |
||
70 | $endpoints |
||
71 | ); |
||
72 | } |
||
73 | |||
74 | file_put_contents('providers.txt', $formattedProviders); |
||
75 | } |
||
76 | |||
77 | public function generateSimpleProviders() |
||
78 | { |
||
79 | $response = file_get_contents('https://oembed.com/providers.json'); |
||
80 | |||
81 | if (!$response) { |
||
82 | throw new Exception('Error reteriving providers list.'); |
||
83 | } |
||
84 | |||
85 | $providers = json_decode($response, true); |
||
86 | |||
87 | $providerFormat = <<<END |
||
88 | '%s' => [ |
||
89 | 'schemes' => [ |
||
90 | %s |
||
91 | ] |
||
92 | ], |
||
93 | |||
94 | END; |
||
95 | |||
96 | $schemeFormat = <<<END |
||
97 | '%s', |
||
98 | END; |
||
99 | |||
100 | $formattedProviders = ''; |
||
101 | foreach ($providers as $provider) { |
||
102 | foreach ($provider['endpoints'] as $endpoint) { |
||
103 | if (!isset($endpoint['schemes'])) { |
||
104 | continue; |
||
105 | } |
||
106 | |||
107 | $schemes = ''; |
||
108 | $url = str_replace('.{format}', '.json', $endpoint['url']); |
||
109 | $url = str_replace('?format={format}', '?format=json', $url); |
||
0 ignored issues
–
show
|
|||
110 | foreach ($endpoint['schemes'] as $skey => $url) { |
||
111 | $scheme = '|^' . $url; |
||
112 | $scheme = preg_replace('/([.=?#-])/i', '\\\\\\\\${1}', $scheme); |
||
113 | $scheme = str_replace('http:', 'https?:', $scheme); |
||
114 | $scheme = str_replace('https:', 'https?:', $scheme); |
||
115 | $scheme = str_replace('*', '.*', $scheme); |
||
116 | $scheme .= '$|i'; |
||
117 | $schemes .= ($skey > 0 ? "\n " : "") . sprintf($schemeFormat, $scheme); |
||
118 | } |
||
119 | |||
120 | $formattedProviders .= sprintf( |
||
121 | $providerFormat, |
||
122 | $endpoint['url'], |
||
123 | $schemes |
||
124 | ); |
||
125 | } |
||
126 | } |
||
127 | |||
128 | file_put_contents('simple_providers.txt', $formattedProviders); |
||
129 | } |
||
130 | } |
||
131 | |||
132 | (new ImportProviders)->generateProviders(); |
||
133 | (new ImportProviders)->generateSimpleProviders(); |
||
134 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths