1 | <?php |
||
12 | final class GlideConversion |
||
13 | { |
||
14 | /** @var string */ |
||
15 | private $inputImage; |
||
16 | |||
17 | /** @var string */ |
||
18 | private $imageDriver = 'gd'; |
||
19 | |||
20 | /** @var string */ |
||
21 | private $conversionResult = null; |
||
22 | |||
23 | /** @var string */ |
||
24 | private $temporaryDirectory = null; |
||
25 | |||
26 | public static function create(string $inputImage): self |
||
27 | { |
||
28 | return new self($inputImage); |
||
29 | } |
||
30 | |||
31 | public function setTemporaryDirectory(string $temporaryDirectory) |
||
32 | { |
||
33 | if (! isset($temporaryDirectory)) { |
||
34 | return $this; |
||
35 | } |
||
36 | |||
37 | if (! is_dir($temporaryDirectory)) { |
||
38 | try { |
||
39 | mkdir($temporaryDirectory); |
||
40 | } catch (Exception $exception) { |
||
41 | throw InvalidTemporaryDirectory::temporaryDirectoryNotCreatable($temporaryDirectory); |
||
42 | } |
||
43 | } |
||
44 | |||
45 | if (! is_writable($temporaryDirectory)) { |
||
46 | throw InvalidTemporaryDirectory::temporaryDirectoryNotWritable($temporaryDirectory); |
||
47 | } |
||
48 | |||
49 | $this->temporaryDirectory = $temporaryDirectory; |
||
50 | |||
51 | return $this; |
||
52 | } |
||
53 | |||
54 | public function getTemporaryDirectory(): string |
||
58 | |||
59 | public function __construct(string $inputImage) |
||
60 | { |
||
61 | $this->temporaryDirectory = sys_get_temp_dir(); |
||
62 | |||
63 | $this->inputImage = $inputImage; |
||
64 | } |
||
65 | |||
66 | public function useImageDriver(string $imageDriver): self |
||
72 | |||
73 | public function performManipulations(Manipulations $manipulations) |
||
74 | { |
||
75 | foreach ($manipulations->getManipulationSequence() as $manipulationGroup) { |
||
98 | |||
99 | /** |
||
100 | * Removes the watermark path from the manipulationGroup and returns it. This way it can be injected into the Glide |
||
101 | * server as the `watermarks` path. |
||
102 | * |
||
103 | * @param $manipulationGroup |
||
104 | * |
||
105 | * @return null|string |
||
106 | */ |
||
107 | private function extractWatermarkPath(&$manipulationGroup) |
||
117 | |||
118 | private function createGlideServer($inputFile, string $watermarkPath = null): Server |
||
132 | |||
133 | public function save(string $outputFile) |
||
151 | |||
152 | private function prepareManipulations(array $manipulationGroup): array |
||
164 | |||
165 | private function convertToGlideParameter(string $manipulationName): string |
||
203 | |||
204 | private function directoryIsEmpty(string $directory): bool |
||
210 | } |
||
211 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: