-
Notifications
You must be signed in to change notification settings - Fork 380
/
ResolveCache.php
97 lines (82 loc) · 2.08 KB
/
ResolveCache.php
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/*
* This file is part of the `liip/LiipImagineBundle` project.
*
* (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Liip\ImagineBundle\Async;
use Enqueue\Util\JSON;
use Liip\ImagineBundle\Exception\LogicException;
class ResolveCache implements \JsonSerializable
{
/**
* @var string
*/
private $path;
/**
* @var array|null|\string[]
*/
private $filters;
/**
* @var bool
*/
private $force;
/**
* @param string $path
* @param string[]|null $filters
* @param bool $force
*/
public function __construct(string $path, array $filters = null, bool $force = false)
{
$this->path = $path;
$this->filters = $filters;
$this->force = $force;
}
/**
* @return string
*/
public function getPath(): string
{
return $this->path;
}
/**
* @return null|\string[]
*/
public function getFilters()
{
return $this->filters;
}
/**
* @return bool
*/
public function isForce(): bool
{
return $this->force;
}
/**
* {@inheritdoc}
*/
public function jsonSerialize(): array
{
return ['path' => $this->path, 'filters' => $this->filters, 'force' => $this->force];
}
/**
* @param string $json
*
* @return self
*/
public static function jsonDeserialize(string $json): self
{
$data = array_replace(['path' => null, 'filters' => null, 'force' => false], JSON::decode($json));
if (!$data['path']) {
throw new LogicException('The message does not contain "path" but it is required.');
}
if (!(null === $data['filters'] || is_array($data['filters']))) {
throw new LogicException('The message filters could be either null or array.');
}
return new static($data['path'], $data['filters'], $data['force']);
}
}