Skip to content

Commit aa72f89

Browse files
committed
BugFix composer loading for the update-psl script #265
1 parent 2af033c commit aa72f89

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

bin/update-psl

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,17 @@ use Pdp\Logger;
1818
use Pdp\Installer;
1919
use Pdp\Manager;
2020

21-
require dirname(__DIR__).'/vendor/autoload.php';
21+
function get_vendor_path(): ?string
22+
{
23+
for ($i = 1; $i <= 5; $i++) {
24+
$vendor = dirname(__DIR__, $i).'/vendor';
25+
if (is_dir($vendor) && file_exists($vendor.'/autoload.php')) {
26+
return $vendor;
27+
}
28+
}
29+
30+
return null;
31+
}
2232

2333
function writeln(array $messages, $output): int
2434
{
@@ -41,6 +51,20 @@ function fail(string $message, $output = STDERR): int
4151
return writeln($messages, $output);
4252
}
4353

54+
$vendor = get_vendor_path();
55+
if (null === $vendor) {
56+
$message = <<<TEXT
57+
You must set up the project dependencies using composer
58+
see https://getcomposer.org
59+
TEXT;
60+
61+
fail($message);
62+
63+
die(1);
64+
}
65+
66+
require $vendor.'/autoload.php';
67+
4468
/**
4569
* CLI colors
4670
*/
@@ -72,7 +96,7 @@ if (isset($arguments['help']) || isset($arguments['h'])) {
7296
$helpText = <<<HELP
7397
{$yellow}Usage:$reset
7498
$script [options]
75-
99+
76100
{$yellow}Options:$reset
77101
$green --%s$reset refreshes the Public Suffix List cache
78102
$green --%s=URL$reset set the URL to use to refresh the PSL cache ({$yellow}default:$reset %s)
@@ -84,15 +108,15 @@ if (isset($arguments['help']) || isset($arguments['h'])) {
84108
85109
{$yellow}Help:$reset
86110
The {$green}update-psl$reset command updates your PDP local cache.
87-
111+
88112
{$yellow}Examples:$reset
89113
90114
Refresh all caches using the default settings
91115
$green$script$reset
92-
93-
Refresh only the PSL cache for a TTL of 3 DAY
116+
117+
Refresh only the PSL cache for a TTL of 3 DAY
94118
$green$script --psl --ttl="3 DAYS"$reset
95-
119+
96120
Refresh all caches using another cache directory
97121
$green$script --cache-dir=/temp$reset
98122

data/pdp-PSL_FULL_5a3cc7f81795bb2e48e848af42d287b4.cache

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)