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|null|\string[] |
26
|
|
|
*/ |
27
|
|
|
private $filters; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var bool |
31
|
|
|
*/ |
32
|
|
|
private $force; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $path |
36
|
|
|
* @param string[]|null $filters |
37
|
|
|
* @param bool $force |
38
|
|
|
*/ |
39
|
|
|
public function __construct(string $path, array $filters = null, bool $force = false) |
40
|
|
|
{ |
41
|
|
|
$this->path = $path; |
42
|
|
|
$this->filters = $filters; |
43
|
|
|
$this->force = $force; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
public function getPath(): string |
50
|
|
|
{ |
51
|
|
|
return $this->path; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return null|\string[] |
56
|
|
|
*/ |
57
|
|
|
public function getFilters() |
58
|
|
|
{ |
59
|
|
|
return $this->filters; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return bool |
64
|
|
|
*/ |
65
|
|
|
public function isForce(): bool |
66
|
|
|
{ |
67
|
|
|
return $this->force; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
|
|
public function jsonSerialize(): array |
74
|
|
|
{ |
75
|
|
|
return ['path' => $this->path, 'filters' => $this->filters, 'force' => $this->force]; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $json |
80
|
|
|
* |
81
|
|
|
* @return self |
82
|
|
|
*/ |
83
|
|
|
public static function jsonDeserialize(string $json): self |
84
|
|
|
{ |
85
|
|
|
$data = array_replace(['path' => null, 'filters' => null, 'force' => false], JSON::decode($json)); |
86
|
|
|
|
87
|
|
|
if (false == $data['path']) { |
88
|
|
|
throw new LogicException('The message does not contain "path" but it is required.'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
if (false == (is_null($data['filters']) || is_array($data['filters']))) { |
|
|
|
|
92
|
|
|
throw new LogicException('The message filters could be either null or array.'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return new static($data['path'], $data['filters'], $data['force']); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
When comparing two booleans, it is generally considered safer to use the strict comparison operator.