1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace KamiYang\ProjectVersion\Configuration; |
5
|
|
|
|
6
|
|
|
/* |
7
|
|
|
* This file is part of the ProjectVersion project. |
8
|
|
|
* |
9
|
|
|
* It is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU General Public License as published by |
11
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
12
|
|
|
* (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* For the full copyright and license information, please read |
15
|
|
|
* LICENSE file that was distributed with this source code. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
use KamiYang\ProjectVersion\Enumeration\ProjectVersionModeEnumeration; |
19
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
20
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
21
|
|
|
use TYPO3\CMS\Core\Utility\StringUtility; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class ExtensionConfiguration |
25
|
|
|
*/ |
26
|
|
|
final class ExtensionConfiguration implements SingletonInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Extension configuration. |
30
|
|
|
* |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
private static $configuration = []; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Relative file path of the VERSION-file. Blank equals const 'PATH_site'. |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
private static $versionFilePath = ''; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Indicator for the fetching method. |
44
|
|
|
* |
45
|
|
|
* @var string |
46
|
|
|
* @see \KamiYang\ProjectVersion\Enumeration\ProjectVersionModeEnumeration |
47
|
|
|
*/ |
48
|
|
|
private static $mode = ProjectVersionModeEnumeration::FILE; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
private static $gitFormat = ''; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
private static $staticVersion = ''; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Fetch absolute version filename. |
62
|
|
|
* |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
public static function getAbsVersionFilePath(): string |
66
|
|
|
{ |
67
|
|
|
return GeneralUtility::getFileAbsFileName(self::getVersionFilePath()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
public static function getVersionFilePath(): string |
74
|
|
|
{ |
75
|
|
|
return self::$versionFilePath; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
|
|
public static function getMode(): string |
82
|
|
|
{ |
83
|
|
|
return self::$mode; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public static function getGitFormat(): string |
90
|
|
|
{ |
91
|
|
|
return self::$gitFormat; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
|
|
public static function getStaticVersion(): string |
98
|
|
|
{ |
99
|
|
|
return self::$staticVersion; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function __construct() |
103
|
|
|
{ |
104
|
|
|
self::$configuration = $this->getExtensionConfigurationFromGlobals(); |
105
|
|
|
|
106
|
|
|
self::$versionFilePath = $this->resolveVersionFilePath(); |
107
|
|
|
self::$mode = self::$configuration['mode']; |
108
|
|
|
self::$gitFormat = self::$configuration['gitFormat']; |
109
|
|
|
self::$staticVersion = self::$configuration['staticVersion']; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return array |
114
|
|
|
*/ |
115
|
|
|
private function getExtensionConfigurationFromGlobals(): array |
116
|
|
|
{ |
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 ?? []; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return string |
128
|
|
|
*/ |
129
|
|
|
private function resolveVersionFilePath(): string |
130
|
|
|
{ |
131
|
|
|
$pathFromConfiguration = self::$configuration['versionFilePath'] ?? ''; |
132
|
|
|
|
133
|
|
|
if (empty($pathFromConfiguration) || $this->isDirectory($pathFromConfiguration)) { |
134
|
|
|
$pathFromConfiguration .= 'VERSION'; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
return $pathFromConfiguration; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param string $pathFromConfiguration |
142
|
|
|
* @return bool |
143
|
|
|
*/ |
144
|
|
|
private function isDirectory(string $pathFromConfiguration): bool |
145
|
|
|
{ |
146
|
|
|
return StringUtility::endsWith($pathFromConfiguration, '/') === true; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|