-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathAbstractDrawModifier.php
More file actions
69 lines (58 loc) · 1.91 KB
/
AbstractDrawModifier.php
File metadata and controls
69 lines (58 loc) · 1.91 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
58
59
60
61
62
63
64
65
66
67
68
69
<?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Color;
use Intervention\Image\Drivers\SpecializableModifier;
use Intervention\Image\Exceptions\ColorDecoderException;
use Intervention\Image\Exceptions\ModifierException;
use Intervention\Image\Exceptions\StateException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DrawableInterface;
abstract class AbstractDrawModifier extends SpecializableModifier
{
/**
* Return the drawable object which will be rendered by the modifier.
*/
abstract protected function drawable(): DrawableInterface;
/**
* Return the background color of the object rendered by the modifier.
*
* @throws StateException
* @throws ColorDecoderException
*/
protected function backgroundColor(): ColorInterface
{
$backgroundColor = $this->drawable()->backgroundColor();
if ($backgroundColor === null) {
return Color::transparent();
}
return $this->driver()->decodeColor($backgroundColor);
}
/**
* Return the border color of the object rendered by the modifier.
*
* @throws StateException
* @throws ColorDecoderException
*/
protected function borderColor(): ColorInterface
{
$borderColor = $this->drawable()->borderColor();
if ($borderColor === null || $this->drawable()->hasBorder() === false) {
return Color::transparent();
}
return $this->driver()->decodeColor($borderColor);
}
/**
* Throw ModifierException with given message if result is false.
*
* @throws ModifierException
*/
protected function abortUnless(mixed $result, string $message): void
{
if ($result === false) {
throw new ModifierException(
'Failed to apply ' . self::class . ', ' . $message,
);
}
}
}