Skip to content

Commit 27ed872

Browse files
authored
Merge pull request #267 from jeremykendall/bugfix/update-psl-script
BugFix composer loading for the update-psl script #265
2 parents 2af033c + 8244548 commit 27ed872

13 files changed

+43
-38
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

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"require": {
4040
"php": "^7.2.5",
4141
"ext-intl": "*",
42+
"ext-json": "*",
4243
"psr/log": "^1.1",
4344
"psr/simple-cache": "^1.0.1"
4445
},

data/.gitignore

Whitespace-only changes.

data/pdp-PSL_FULL_5a3cc7f81795bb2e48e848af42d287b4.cache

Lines changed: 0 additions & 1 deletion
This file was deleted.

data/pdp-RZD_FULL_f18a70477d29d525b9220612e2115345.cache

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/Converter.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ final class Converter implements PublicSuffixListSection
3535
{
3636
use IDNAConverterTrait;
3737

38-
/**
39-
* @internal
40-
*/
41-
const PSL_SECTION = [
38+
private const PSL_SECTION = [
4239
'ICANN' => [
4340
'BEGIN' => self::ICANN_DOMAINS,
4441
'END' => '',
@@ -49,10 +46,7 @@ final class Converter implements PublicSuffixListSection
4946
],
5047
];
5148

52-
/**
53-
* @internal
54-
*/
55-
const REGEX_PSL_SECTION = ',^// ===(?<point>BEGIN|END) (?<type>ICANN|PRIVATE) DOMAINS===,';
49+
private const REGEX_PSL_SECTION = ',^// ===(?<point>BEGIN|END) (?<type>ICANN|PRIVATE) DOMAINS===,';
5650

5751
/**
5852
* Convert the Public Suffix List into

src/Domain.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ final class Domain implements DomainInterface, JsonSerializable
5454
{
5555
use IDNAConverterTrait;
5656

57-
/**
58-
* @internal
59-
*/
60-
const REGEXP_IDN_PATTERN = '/[^\x20-\x7f]/';
57+
private const REGEXP_IDN_PATTERN = '/[^\x20-\x7f]/';
6158

6259
/**
6360
* @var string|null

src/Logger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
final class Logger extends AbstractLogger
2828
{
29-
const ERRORS_LEVELS = [
29+
private const ERRORS_LEVELS = [
3030
LogLevel::EMERGENCY => 1,
3131
LogLevel::ALERT => 1,
3232
LogLevel::CRITICAL => 1,

src/Manager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
*/
5050
final class Manager
5151
{
52-
const PSL_URL = 'https://publicsuffix.org/list/public_suffix_list.dat';
53-
const RZD_URL = 'https://data.iana.org/TLD/tlds-alpha-by-domain.txt';
52+
public const PSL_URL = 'https://publicsuffix.org/list/public_suffix_list.dat';
53+
public const RZD_URL = 'https://data.iana.org/TLD/tlds-alpha-by-domain.txt';
5454

5555
/**
5656
* @var CacheInterface

src/PublicSuffix.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ final class PublicSuffix implements DomainInterface, JsonSerializable, PublicSuf
4444
{
4545
use IDNAConverterTrait;
4646

47-
/**
48-
* @internal
49-
*/
50-
const PSL_SECTION = [self::PRIVATE_DOMAINS, self::ICANN_DOMAINS, ''];
47+
private const PSL_SECTION = [self::PRIVATE_DOMAINS, self::ICANN_DOMAINS, ''];
5148

5249
/**
5350
* @var string|null

0 commit comments

Comments
 (0)