|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the `liip/LiipImagineBundle` project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) https://github.com/liip/LiipImagineBundle/graphs/contributors |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Liip\ImagineBundle\Async; |
|
13
|
|
|
|
|
14
|
|
|
use Enqueue\Util\JSON; |
|
15
|
|
|
use Liip\ImagineBundle\Exception\LogicException; |
|
16
|
|
|
|
|
17
|
|
|
class ResolveCache implements \JsonSerializable |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
private $path; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var array|\string[]|null |
|
26
|
|
|
*/ |
|
27
|
|
|
private $filters; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var bool |
|
31
|
|
|
*/ |
|
32
|
|
|
private $force; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param string[]|null $filters |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(string $path, array $filters = null, bool $force = false) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->path = $path; |
|
40
|
|
|
$this->filters = $filters; |
|
41
|
|
|
$this->force = $force; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function getPath(): string |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->path; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @return \string[]|null |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getFilters() |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->filters; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function isForce(): bool |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->force; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* {@inheritdoc} |
|
64
|
|
|
*/ |
|
65
|
|
|
public function jsonSerialize(): array |
|
66
|
|
|
{ |
|
67
|
|
|
return ['path' => $this->path, 'filters' => $this->filters, 'force' => $this->force]; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public static function jsonDeserialize(string $json): self |
|
71
|
|
|
{ |
|
72
|
|
|
$data = array_replace(['path' => null, 'filters' => null, 'force' => false], JSON::decode($json)); |
|
73
|
|
|
|
|
74
|
|
|
if (!$data['path']) { |
|
75
|
|
|
throw new LogicException('The message does not contain "path" but it is required.'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if (!(null === $data['filters'] || \is_array($data['filters']))) { |
|
79
|
|
|
throw new LogicException('The message filters could be either null or array.'); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return new static($data['path'], $data['filters'], $data['force']); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|