|
1
|
|
|
<?php |
|
2
|
|
|
namespace Mezon\Security; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Class Security |
|
6
|
|
|
* |
|
7
|
|
|
* @package Mezon |
|
8
|
|
|
* @subpackage Security |
|
9
|
|
|
* @author Dodonov A.A. |
|
10
|
|
|
* @version v.1.0 (2019/10/08) |
|
11
|
|
|
* @copyright Copyright (c) 2019, aeon.org |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Security class |
|
16
|
|
|
* |
|
17
|
|
|
* @author Dodonov A.A. |
|
18
|
|
|
*/ |
|
19
|
|
|
class Security |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Security rules |
|
24
|
|
|
* |
|
25
|
|
|
* @var \Mezon\Security\SecurityRules |
|
26
|
|
|
*/ |
|
27
|
|
|
public static $securityRules = null; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Method returns security rules |
|
31
|
|
|
* |
|
32
|
|
|
* @return \Mezon\Security\SecurityRules |
|
33
|
|
|
*/ |
|
34
|
|
|
public static function getSecurityRules(): \Mezon\Security\SecurityRules |
|
35
|
|
|
{ |
|
36
|
|
|
if (self::$securityRules === null) { |
|
37
|
|
|
self::$securityRules = new \Mezon\Security\SecurityRules(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
return self::$securityRules; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Returning string value |
|
45
|
|
|
* |
|
46
|
|
|
* @param string $value |
|
47
|
|
|
* Value to be made secure |
|
48
|
|
|
* @return string Secure value |
|
49
|
|
|
* @codeCoverageIgnore |
|
50
|
|
|
*/ |
|
51
|
|
|
public static function getStringValue(string $value): string |
|
52
|
|
|
{ |
|
53
|
|
|
return self::getSecurityRules()->getStringValue($value); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Returning int value |
|
58
|
|
|
* |
|
59
|
|
|
* @param mixed $value |
|
60
|
|
|
* Value to be made secure |
|
61
|
|
|
* @return int Secure value |
|
62
|
|
|
* @codeCoverageIgnore |
|
63
|
|
|
*/ |
|
64
|
|
|
public static function getIntValue($value): int |
|
65
|
|
|
{ |
|
66
|
|
|
return self::getSecurityRules()->getIntValue($value); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Method returns file value |
|
71
|
|
|
* |
|
72
|
|
|
* @param mixed $value |
|
73
|
|
|
* Data about the uploaded file |
|
74
|
|
|
* @param bool $storeFiles |
|
75
|
|
|
* Must be the file stored in the file system of the service or not |
|
76
|
|
|
* @return string|array Path to the stored file or the array $value itself |
|
77
|
|
|
* @codeCoverageIgnore |
|
78
|
|
|
*/ |
|
79
|
|
|
public static function getFileValue($value, bool $storeFiles) |
|
80
|
|
|
{ |
|
81
|
|
|
return self::getSecurityRules()->getFileValue($value, $storeFiles); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Method stores file on disk |
|
86
|
|
|
* |
|
87
|
|
|
* @param string $fileContent |
|
88
|
|
|
* Content of the saving file |
|
89
|
|
|
* @param string $pathPrefix |
|
90
|
|
|
* Prefix to file |
|
91
|
|
|
* @param bool $decoded |
|
92
|
|
|
* If the file was not encodded in base64 |
|
93
|
|
|
* @return string Path to file |
|
94
|
|
|
* @codeCoverageIgnore |
|
95
|
|
|
*/ |
|
96
|
|
|
public static function storeFileContent(string $fileContent, string $pathPrefix, bool $decoded = false): string |
|
97
|
|
|
{ |
|
98
|
|
|
return self::getSecurityRules()->storeFileContent($fileContent, $pathPrefix, $decoded); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Method stores file on disk |
|
103
|
|
|
* |
|
104
|
|
|
* @param string $filePath |
|
105
|
|
|
* Path to the saving file |
|
106
|
|
|
* @param string $pathPrefix |
|
107
|
|
|
* Prefix to file |
|
108
|
|
|
* @param bool $decoded |
|
109
|
|
|
* If the file was not encodded in base64 |
|
110
|
|
|
* @return string Path to file or null if the image was not loaded |
|
111
|
|
|
* @codeCoverageIgnore |
|
112
|
|
|
*/ |
|
113
|
|
|
public static function storeFile(string $filePath, string $pathPrefix, bool $decoded = false): ?string |
|
114
|
|
|
{ |
|
115
|
|
|
return self::getSecurityRules()->storeFile($filePath, $pathPrefix, $decoded); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|