|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the ekino Drupal Debug project. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) ekino |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Ekino\Drupal\Debug\Resource\Model; |
|
15
|
|
|
|
|
16
|
|
|
use Ekino\Drupal\Debug\Extension\Model\CustomExtensionInterface; |
|
17
|
|
|
use Symfony\Component\Config\Resource\SelfCheckingResourceInterface; |
|
18
|
|
|
|
|
19
|
|
|
class CustomExtensionFileResource implements SelfCheckingResourceInterface, \Serializable |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
private $filePath; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var CustomExtensionInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
private $customExtension; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var bool |
|
33
|
|
|
*/ |
|
34
|
|
|
private $existed; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string $filePath |
|
38
|
|
|
* @param CustomExtensionInterface $customExtension |
|
39
|
|
|
*/ |
|
40
|
33 |
|
public function __construct(string $filePath, CustomExtensionInterface $customExtension) |
|
41
|
|
|
{ |
|
42
|
33 |
|
$this->filePath = $filePath; |
|
43
|
33 |
|
$this->customExtension = $customExtension; |
|
44
|
|
|
|
|
45
|
33 |
|
$this->existed = \is_file($filePath); |
|
46
|
33 |
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritdoc} |
|
50
|
|
|
*/ |
|
51
|
7 |
|
public function __toString(): string |
|
52
|
|
|
{ |
|
53
|
7 |
|
return $this->filePath; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return string |
|
58
|
|
|
*/ |
|
59
|
15 |
|
public function getFilePath(): string |
|
60
|
|
|
{ |
|
61
|
15 |
|
return $this->filePath; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return CustomExtensionInterface |
|
66
|
|
|
*/ |
|
67
|
3 |
|
public function getCustomExtension(): CustomExtensionInterface |
|
68
|
|
|
{ |
|
69
|
3 |
|
return $this->customExtension; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* {@inheritdoc} |
|
74
|
|
|
*/ |
|
75
|
11 |
|
public function isFresh($timestamp): bool |
|
76
|
|
|
{ |
|
77
|
11 |
|
if (!\is_file($this->filePath)) { |
|
78
|
2 |
|
return !$this->existed; |
|
79
|
9 |
|
} elseif (!$this->existed) { |
|
80
|
1 |
|
return false; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
8 |
|
return false !== ($filemtime = @\filemtime($this->filePath)) && $filemtime <= $timestamp; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @return bool |
|
88
|
|
|
*/ |
|
89
|
4 |
|
public function isNew(): bool |
|
90
|
|
|
{ |
|
91
|
4 |
|
return false === $this->existed && \is_file($this->filePath); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* {@inheritdoc} |
|
96
|
|
|
*/ |
|
97
|
15 |
|
public function serialize(): ?string |
|
98
|
|
|
{ |
|
99
|
15 |
|
return \serialize(array( |
|
100
|
15 |
|
$this->filePath, |
|
101
|
15 |
|
$this->customExtension, |
|
102
|
15 |
|
$this->existed, |
|
103
|
|
|
)); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* {@inheritdoc} |
|
108
|
|
|
*/ |
|
109
|
11 |
|
public function unserialize($serialized): void |
|
110
|
|
|
{ |
|
111
|
11 |
|
list($this->filePath, $this->customExtension, $this->existed) = \unserialize($serialized); |
|
112
|
11 |
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|