Skip to content

Commit 1795530

Browse files
committed
Load locks that look like urls and notify on missing stream wrapper
1 parent 3fe72c0 commit 1795530

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,5 @@ Thanks to everyone who has shared ideas and code! In particular,
102102
- https://github.com/nclavaud
103103
- https://github.com/cafferata
104104
- https://github.com/ihor-sviziev
105+
- https://github.com/wiese
105106

composer-lock-diff

+14
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ function load($fileish, $base_path = '') {
150150
$fileish = $base_path . 'composer.lock';
151151
}
152152

153+
if (isUrl($fileish)) {
154+
if (! in_array(parse_url($fileish, PHP_URL_SCHEME), stream_get_wrappers())) {
155+
error_log("Error: no stream wrapper to open '$fileish'");
156+
exit(1);
157+
}
158+
159+
return mustDecodeJson(file_get_contents($fileish), $fileish);
160+
}
161+
153162
if (file_exists($fileish)) {
154163
return mustDecodeJson(file_get_contents($fileish), $fileish);
155164
}
@@ -170,6 +179,11 @@ function load($fileish, $base_path = '') {
170179
return mustDecodeJson(implode("\n", $lines), $fileish);
171180
}
172181

182+
function isUrl($string) {
183+
return filter_var($string, FILTER_VALIDATE_URL,
184+
FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED | FILTER_FLAG_PATH_REQUIRED);
185+
}
186+
173187
function mustDecodeJson($json, $context) {
174188
$data = json_decode($json);
175189

0 commit comments

Comments
 (0)