|
1 | 1 | <?php |
| 2 | + |
2 | 3 | declare(strict_types=1); |
3 | 4 |
|
4 | 5 | namespace KamiYang\ProjectVersion\Configuration; |
|
25 | 26 | */ |
26 | 27 | final class ExtensionConfiguration implements SingletonInterface |
27 | 28 | { |
| 29 | + private const DEFAULT_VERSION_FILE = 'VERSION'; |
| 30 | + |
28 | 31 | /** |
29 | 32 | * Extension configuration. |
30 | 33 | * |
31 | 34 | * @var array |
32 | 35 | */ |
33 | | - private static $configuration = []; |
| 36 | + private $configuration; |
34 | 37 |
|
35 | 38 | /** |
36 | 39 | * Relative file path of the VERSION-file. Blank equals const 'PATH_site'. |
37 | 40 | * |
38 | 41 | * @var string |
39 | 42 | */ |
40 | | - private static $versionFilePath = ''; |
| 43 | + private $versionFilePath; |
41 | 44 |
|
42 | 45 | /** |
43 | 46 | * Indicator for the fetching method. |
44 | 47 | * |
45 | 48 | * @var string |
46 | 49 | * @see \KamiYang\ProjectVersion\Enumeration\ProjectVersionModeEnumeration |
47 | 50 | */ |
48 | | - private static $mode = ProjectVersionModeEnumeration::FILE; |
| 51 | + private $mode; |
49 | 52 |
|
50 | 53 | /** |
51 | 54 | * @var string |
52 | 55 | */ |
53 | | - private static $gitFormat = ''; |
| 56 | + private $gitFormat; |
54 | 57 |
|
55 | 58 | /** |
56 | 59 | * @var string |
57 | 60 | */ |
58 | | - private static $staticVersion = ''; |
| 61 | + private $staticVersion; |
59 | 62 |
|
60 | 63 | /** |
61 | 64 | * Fetch absolute version filename. |
62 | 65 | * |
63 | 66 | * @return string |
64 | 67 | */ |
65 | | - public static function getAbsVersionFilePath(): string |
| 68 | + public function getAbsVersionFilePath(): string |
66 | 69 | { |
67 | | - return GeneralUtility::getFileAbsFileName(self::getVersionFilePath()); |
| 70 | + return GeneralUtility::getFileAbsFileName($this->getVersionFilePath()); |
68 | 71 | } |
69 | 72 |
|
70 | | - /** |
71 | | - * @return string |
72 | | - */ |
73 | | - public static function getVersionFilePath(): string |
| 73 | + public function getVersionFilePath(): string |
74 | 74 | { |
75 | | - return self::$versionFilePath; |
| 75 | + return $this->versionFilePath; |
76 | 76 | } |
77 | 77 |
|
78 | | - /** |
79 | | - * @return string |
80 | | - */ |
81 | | - public static function getMode(): string |
| 78 | + public function getMode(): string |
82 | 79 | { |
83 | | - return self::$mode; |
| 80 | + return $this->mode; |
84 | 81 | } |
85 | 82 |
|
86 | | - /** |
87 | | - * @return string |
88 | | - */ |
89 | | - public static function getGitFormat(): string |
| 83 | + public function getGitFormat(): string |
90 | 84 | { |
91 | | - return self::$gitFormat; |
| 85 | + return $this->gitFormat; |
92 | 86 | } |
93 | 87 |
|
94 | | - /** |
95 | | - * @return string |
96 | | - */ |
97 | | - public static function getStaticVersion(): string |
| 88 | + public function getStaticVersion(): string |
98 | 89 | { |
99 | | - return self::$staticVersion; |
| 90 | + return $this->staticVersion; |
100 | 91 | } |
101 | 92 |
|
102 | 93 | public function __construct() |
103 | 94 | { |
104 | | - self::$configuration = $this->getExtensionConfigurationFromGlobals(); |
| 95 | + $this->configuration = $this->getExtensionConfigurationFromGlobals(); |
105 | 96 |
|
106 | | - self::$versionFilePath = $this->resolveVersionFilePath(); |
107 | | - self::$mode = self::$configuration['mode']; |
108 | | - self::$gitFormat = self::$configuration['gitFormat']; |
109 | | - self::$staticVersion = self::$configuration['staticVersion']; |
| 97 | + $this->versionFilePath = $this->resolveVersionFilePath(); |
| 98 | + $this->mode = $this->configuration['mode'] ?? ProjectVersionModeEnumeration::FILE; |
| 99 | + $this->gitFormat = $this->configuration['gitFormat'] ?? ''; |
| 100 | + $this->staticVersion = $this->configuration['staticVersion'] ?? ''; |
110 | 101 | } |
111 | 102 |
|
112 | | - /** |
113 | | - * @return array |
114 | | - */ |
115 | 103 | private function getExtensionConfigurationFromGlobals(): array |
116 | 104 | { |
117 | | - $configuration = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['project_version']; |
118 | | - |
119 | | - if (is_string($configuration)) { |
120 | | - $configuration = @unserialize($configuration); |
121 | | - } |
122 | | - |
123 | | - return $configuration ?? []; |
| 105 | + return $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['project_version'] ?? []; |
124 | 106 | } |
125 | 107 |
|
126 | | - /** |
127 | | - * @return string |
128 | | - */ |
129 | 108 | private function resolveVersionFilePath(): string |
130 | 109 | { |
131 | | - $pathFromConfiguration = self::$configuration['versionFilePath'] ?? ''; |
| 110 | + $pathFromConfiguration = $this->configuration['versionFilePath'] ?? ''; |
132 | 111 |
|
133 | 112 | if (empty($pathFromConfiguration) || $this->isDirectory($pathFromConfiguration)) { |
134 | | - $pathFromConfiguration .= 'VERSION'; |
| 113 | + $pathFromConfiguration .= self::DEFAULT_VERSION_FILE; |
135 | 114 | } |
136 | 115 |
|
137 | 116 | return $pathFromConfiguration; |
138 | 117 | } |
139 | 118 |
|
140 | | - /** |
141 | | - * @param string $pathFromConfiguration |
142 | | - * @return bool |
143 | | - */ |
144 | 119 | private function isDirectory(string $pathFromConfiguration): bool |
145 | 120 | { |
146 | | - return StringUtility::endsWith($pathFromConfiguration, '/') === true; |
| 121 | + return StringUtility::endsWith($pathFromConfiguration, '/'); |
147 | 122 | } |
148 | 123 | } |
0 commit comments