1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* |
5
|
|
|
* This file is part of Phpfastcache. |
6
|
|
|
* |
7
|
|
|
* @license MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files. |
10
|
|
|
* |
11
|
|
|
* @author Georges.L (Geolim4) <[email protected]> |
12
|
|
|
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
declare(strict_types=1); |
16
|
|
|
|
17
|
|
|
namespace Phpfastcache\Config; |
18
|
|
|
|
19
|
|
|
use Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException; |
20
|
|
|
use Phpfastcache\Exceptions\PhpfastcacheLogicException; |
21
|
|
|
|
22
|
|
|
class IOConfigurationOption extends ConfigurationOption |
23
|
|
|
{ |
24
|
|
|
protected bool $secureFileManipulation = false; |
25
|
|
|
|
26
|
|
|
protected string $securityKey = ''; |
27
|
|
|
|
28
|
|
|
protected string $cacheFileExtension = 'txt'; |
29
|
|
|
|
30
|
|
|
protected int $defaultChmod = 0777; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
|
public function getSecurityKey(): string |
36
|
|
|
{ |
37
|
|
|
return $this->securityKey; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $securityKey |
42
|
|
|
* @return static |
43
|
|
|
* @throws PhpfastcacheLogicException |
44
|
|
|
*/ |
45
|
|
|
public function setSecurityKey(string $securityKey): static |
46
|
|
|
{ |
47
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
48
|
|
|
$this->securityKey = $securityKey; |
49
|
|
|
|
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return bool |
55
|
|
|
*/ |
56
|
|
|
public function isSecureFileManipulation(): bool |
57
|
|
|
{ |
58
|
|
|
return $this->secureFileManipulation; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param bool $secureFileManipulation |
63
|
|
|
* @return self |
64
|
|
|
* @throws PhpfastcacheLogicException |
65
|
|
|
*/ |
66
|
|
|
public function setSecureFileManipulation(bool $secureFileManipulation): static |
67
|
|
|
{ |
68
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
69
|
|
|
$this->secureFileManipulation = $secureFileManipulation; |
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
public function getCacheFileExtension(): string |
78
|
|
|
{ |
79
|
|
|
return $this->cacheFileExtension; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param string $cacheFileExtension |
84
|
|
|
* @return static |
85
|
|
|
* @throws PhpfastcacheInvalidConfigurationException |
86
|
|
|
* @throws PhpfastcacheLogicException |
87
|
|
|
*/ |
88
|
|
|
public function setCacheFileExtension(string $cacheFileExtension): static |
89
|
|
|
{ |
90
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
91
|
|
|
$safeFileExtensions = \explode('|', IOConfigurationOptionInterface::SAFE_FILE_EXTENSIONS); |
92
|
|
|
|
93
|
|
|
if (\str_contains($cacheFileExtension, '.')) { |
94
|
|
|
throw new PhpfastcacheInvalidConfigurationException('cacheFileExtension cannot contain a dot "."'); |
95
|
|
|
} |
96
|
|
|
if (!\in_array($cacheFileExtension, $safeFileExtensions, true)) { |
97
|
|
|
throw new PhpfastcacheInvalidConfigurationException( |
98
|
|
|
"Extension \"$cacheFileExtension\" is unsafe, currently allowed extension names: " . \implode(', ', $safeFileExtensions) |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$this->cacheFileExtension = $cacheFileExtension; |
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return int |
108
|
|
|
*/ |
109
|
|
|
public function getDefaultChmod(): int |
110
|
|
|
{ |
111
|
|
|
return $this->defaultChmod; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param int $defaultChmod |
116
|
|
|
* @return self |
117
|
|
|
* @throws PhpfastcacheLogicException |
118
|
|
|
*/ |
119
|
|
|
public function setDefaultChmod(int $defaultChmod): static |
120
|
|
|
{ |
121
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
122
|
|
|
$this->defaultChmod = $defaultChmod; |
123
|
|
|
return $this; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|