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
|
|
|
declare(strict_types=1); |
15
|
|
|
|
16
|
|
|
namespace Phpfastcache\Config; |
17
|
|
|
|
18
|
|
|
use Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException; |
19
|
|
|
use Phpfastcache\Exceptions\PhpfastcacheLogicException; |
20
|
|
|
|
21
|
|
|
trait IOConfigurationOptionTrait |
22
|
|
|
{ |
23
|
|
|
protected bool $secureFileManipulation = false; |
24
|
|
|
|
25
|
|
|
protected string $securityKey = ''; |
26
|
|
|
|
27
|
|
|
protected string $cacheFileExtension = 'txt'; |
28
|
|
|
|
29
|
|
|
protected int $defaultChmod = 0777; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return string |
33
|
|
|
*/ |
34
|
|
|
public function getSecurityKey(): string |
35
|
|
|
{ |
36
|
|
|
return $this->securityKey; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param string $securityKey |
41
|
|
|
* @return static |
42
|
|
|
* @throws PhpfastcacheLogicException |
43
|
|
|
*/ |
44
|
|
|
public function setSecurityKey(string $securityKey): static |
45
|
|
|
{ |
46
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
|
|
|
|
47
|
|
|
$this->securityKey = $securityKey; |
48
|
|
|
|
49
|
|
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return bool |
54
|
|
|
*/ |
55
|
|
|
public function isSecureFileManipulation(): bool |
56
|
|
|
{ |
57
|
|
|
return $this->secureFileManipulation; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param bool $secureFileManipulation |
62
|
|
|
* @return self |
63
|
|
|
* @throws PhpfastcacheLogicException |
64
|
|
|
*/ |
65
|
|
|
public function setSecureFileManipulation(bool $secureFileManipulation): static |
66
|
|
|
{ |
67
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
68
|
|
|
$this->secureFileManipulation = $secureFileManipulation; |
69
|
|
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
public function getCacheFileExtension(): string |
77
|
|
|
{ |
78
|
|
|
return $this->cacheFileExtension; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param string $cacheFileExtension |
83
|
|
|
* @return static |
84
|
|
|
* @throws PhpfastcacheInvalidConfigurationException |
85
|
|
|
* @throws PhpfastcacheLogicException |
86
|
|
|
*/ |
87
|
|
|
public function setCacheFileExtension(string $cacheFileExtension): static |
88
|
|
|
{ |
89
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
90
|
|
|
$safeFileExtensions = \explode('|', IOConfigurationOptionInterface::SAFE_FILE_EXTENSIONS); |
91
|
|
|
|
92
|
|
|
if (str_contains($cacheFileExtension, '.')) { |
93
|
|
|
throw new PhpfastcacheInvalidConfigurationException('cacheFileExtension cannot contain a dot "."'); |
94
|
|
|
} |
95
|
|
|
if (!\in_array($cacheFileExtension, $safeFileExtensions, true)) { |
96
|
|
|
throw new PhpfastcacheInvalidConfigurationException( |
97
|
|
|
"Extension \"$cacheFileExtension\" is not safe, currently allowed extension names: " . \implode(', ', $safeFileExtensions) |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$this->cacheFileExtension = $cacheFileExtension; |
102
|
|
|
return $this; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return int |
107
|
|
|
*/ |
108
|
|
|
public function getDefaultChmod(): int |
109
|
|
|
{ |
110
|
|
|
return $this->defaultChmod; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param int $defaultChmod |
115
|
|
|
* @return self |
116
|
|
|
* @throws PhpfastcacheLogicException |
117
|
|
|
*/ |
118
|
|
|
public function setDefaultChmod(int $defaultChmod): static |
119
|
|
|
{ |
120
|
|
|
$this->enforceLockedProperty(__FUNCTION__); |
121
|
|
|
$this->defaultChmod = $defaultChmod; |
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|