forked from jeremykendall/php-domain-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSyntaxError.php
More file actions
57 lines (44 loc) · 1.7 KB
/
Copy pathSyntaxError.php
File metadata and controls
57 lines (44 loc) · 1.7 KB
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
<?php
declare(strict_types=1);
namespace Pdp;
use InvalidArgumentException;
final class SyntaxError extends InvalidArgumentException implements CannotProcessHost
{
private ?IdnaInfo $idnaInfo;
private function __construct(string $message, IdnaInfo $idnaInfo = null)
{
parent::__construct($message);
$this->idnaInfo = $idnaInfo;
}
public static function dueToInvalidCharacters(string $domain): self
{
return new self('The host `'.$domain.'` is invalid: it contains invalid characters.');
}
public static function dueToMalformedValue(string $domain): self
{
return new self('The host `'.$domain.'` is malformed; Verify its length and/or characters.');
}
public static function dueToIDNAError(string $domain, IdnaInfo $idnaInfo): self
{
return new self('The host `'.$domain.'` is invalid for IDN conversion.', $idnaInfo);
}
public static function dueToInvalidSuffix(Host $publicSuffix, string $type = ''): self
{
if ('' === $type) {
return new self('The suffix `"'.($publicSuffix->value() ?? 'NULL').'"` is invalid.');
}
return new self('The suffix `"'.($publicSuffix->value() ?? 'NULL').'"` is an invalid `'.$type.'` suffix.');
}
public static function dueToUnsupportedType(string $domain): self
{
return new self('The domain `'.$domain.'` is invalid: this is an IPv4 host.');
}
public static function dueToInvalidLabelKey(Host $domain, int $key): self
{
return new self('the given key `'.$key.'` is invalid for the domain `'.($domain->value() ?? 'NULL').'`.');
}
public function idnaInfo(): ?IdnaInfo
{
return $this->idnaInfo;
}
}