1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\Color\Exceptions; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
|
7
|
|
|
class InvalidColorValue extends Exception |
8
|
|
|
{ |
9
|
|
|
public static function rgbChannelValueNotInRange(int $value, string $channel): self |
10
|
|
|
{ |
11
|
|
|
return new static("An rgb values must be an integer between 0 and 255, `{$value}` provided for channel {$channel}."); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
public static function alphaChannelValueNotInRange(int $value): self |
15
|
|
|
{ |
16
|
|
|
return new static("An alpha values must be a float between 0 and 1, `{$value}` provided."); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public static function hexChannelValueHasInvalidLength(string $value): self |
20
|
|
|
{ |
21
|
|
|
$length = strlen($value); |
22
|
|
|
|
23
|
|
|
return new static("Hex values must contain exactly 2 characters, `{$value}` contains {$length} characters."); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public static function hexValueContainsInvalidCharacters(string $value): self |
27
|
|
|
{ |
28
|
|
|
return new static("Hex values can only contain numbers or letters from A-F, `{$value}` contains invalid characters."); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public static function malformedHexColorString(string $string): self |
32
|
|
|
{ |
33
|
|
|
return new static("Hex color string `{$string}` is malformed. A hex color string starts with a `#` and contains exactly six characters, e.g. `#aabbcc`."); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public static function malformedRgbColorString(string $string): self |
37
|
|
|
{ |
38
|
|
|
return new static("Rgb color string `{$string}` is malformed. An rgb color contains 3 comma separated values between 0 and 255, wrapped in `rgb()`, e.g. `rgb(0,0,255)`."); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public static function malformedRgbaColorString(string $string): self |
42
|
|
|
{ |
43
|
|
|
return new static("Rgba color string `{$string}` is malformed. An rgba color contains 3 comma separated values between 0 and 255 with an alpha value between 0 and 1, wrapped in `rgba()`, e.g. `rgb(0,0,255,0.5)`."); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public static function malformedColorString(string $string): self |
47
|
|
|
{ |
48
|
|
|
return new static("Color string `{$string}` doesn't match any of the available colors."); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|