Skip to content

Commit 9f4d2ff

Browse files
committed
[TASK] Initial changes for typo3 v10 & v11 support
1 parent eb80e50 commit 9f4d2ff

17 files changed

Lines changed: 147 additions & 228 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.ddev
12
/.Build/
23
/.idea/
34
/composer.lock
Lines changed: 27 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace KamiYang\ProjectVersion\Configuration;
@@ -25,124 +26,98 @@
2526
*/
2627
final class ExtensionConfiguration implements SingletonInterface
2728
{
29+
private const DEFAULT_VERSION_FILE = 'VERSION';
30+
2831
/**
2932
* Extension configuration.
3033
*
3134
* @var array
3235
*/
33-
private static $configuration = [];
36+
private $configuration;
3437

3538
/**
3639
* Relative file path of the VERSION-file. Blank equals const 'PATH_site'.
3740
*
3841
* @var string
3942
*/
40-
private static $versionFilePath = '';
43+
private $versionFilePath;
4144

4245
/**
4346
* Indicator for the fetching method.
4447
*
4548
* @var string
4649
* @see \KamiYang\ProjectVersion\Enumeration\ProjectVersionModeEnumeration
4750
*/
48-
private static $mode = ProjectVersionModeEnumeration::FILE;
51+
private $mode;
4952

5053
/**
5154
* @var string
5255
*/
53-
private static $gitFormat = '';
56+
private $gitFormat;
5457

5558
/**
5659
* @var string
5760
*/
58-
private static $staticVersion = '';
61+
private $staticVersion;
5962

6063
/**
6164
* Fetch absolute version filename.
6265
*
6366
* @return string
6467
*/
65-
public static function getAbsVersionFilePath(): string
68+
public function getAbsVersionFilePath(): string
6669
{
67-
return GeneralUtility::getFileAbsFileName(self::getVersionFilePath());
70+
return GeneralUtility::getFileAbsFileName($this->getVersionFilePath());
6871
}
6972

70-
/**
71-
* @return string
72-
*/
73-
public static function getVersionFilePath(): string
73+
public function getVersionFilePath(): string
7474
{
75-
return self::$versionFilePath;
75+
return $this->versionFilePath;
7676
}
7777

78-
/**
79-
* @return string
80-
*/
81-
public static function getMode(): string
78+
public function getMode(): string
8279
{
83-
return self::$mode;
80+
return $this->mode;
8481
}
8582

86-
/**
87-
* @return string
88-
*/
89-
public static function getGitFormat(): string
83+
public function getGitFormat(): string
9084
{
91-
return self::$gitFormat;
85+
return $this->gitFormat;
9286
}
9387

94-
/**
95-
* @return string
96-
*/
97-
public static function getStaticVersion(): string
88+
public function getStaticVersion(): string
9889
{
99-
return self::$staticVersion;
90+
return $this->staticVersion;
10091
}
10192

10293
public function __construct()
10394
{
104-
self::$configuration = $this->getExtensionConfigurationFromGlobals();
95+
$this->configuration = $this->getExtensionConfigurationFromGlobals();
10596

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'] ?? '';
110101
}
111102

112-
/**
113-
* @return array
114-
*/
115103
private function getExtensionConfigurationFromGlobals(): array
116104
{
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'] ?? [];
124106
}
125107

126-
/**
127-
* @return string
128-
*/
129108
private function resolveVersionFilePath(): string
130109
{
131-
$pathFromConfiguration = self::$configuration['versionFilePath'] ?? '';
110+
$pathFromConfiguration = $this->configuration['versionFilePath'] ?? '';
132111

133112
if (empty($pathFromConfiguration) || $this->isDirectory($pathFromConfiguration)) {
134-
$pathFromConfiguration .= 'VERSION';
113+
$pathFromConfiguration .= self::DEFAULT_VERSION_FILE;
135114
}
136115

137116
return $pathFromConfiguration;
138117
}
139118

140-
/**
141-
* @param string $pathFromConfiguration
142-
* @return bool
143-
*/
144119
private function isDirectory(string $pathFromConfiguration): bool
145120
{
146-
return StringUtility::endsWith($pathFromConfiguration, '/') === true;
121+
return StringUtility::endsWith($pathFromConfiguration, '/');
147122
}
148123
}

Classes/Enumeration/GitCommandEnumeration.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace KamiYang\ProjectVersion\Enumeration;
@@ -20,13 +21,13 @@
2021
*/
2122
final class GitCommandEnumeration
2223
{
23-
const CMD_BRANCH = 'git rev-parse --abbrev-ref HEAD';
24-
const CMD_REVISION = 'git rev-parse --short HEAD';
25-
const CMD_TAG = 'git describe --tags';
24+
public const CMD_BRANCH = 'git rev-parse --abbrev-ref HEAD';
25+
public const CMD_REVISION = 'git rev-parse --short HEAD';
26+
public const CMD_TAG = 'git describe --tags';
2627

27-
const FORMAT_REVISION = '0';
28-
const FORMAT_REVISION_BRANCH = '1';
29-
const FORMAT_REVISION_TAG = '2';
30-
const FORMAT_BRANCH = '3';
31-
const FORMAT_TAG = '4';
28+
public const FORMAT_REVISION = '0';
29+
public const FORMAT_REVISION_BRANCH = '1';
30+
public const FORMAT_REVISION_TAG = '2';
31+
public const FORMAT_BRANCH = '3';
32+
public const FORMAT_TAG = '4';
3233
}

Classes/Enumeration/ProjectVersionModeEnumeration.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace KamiYang\ProjectVersion\Enumeration;
@@ -20,8 +21,8 @@
2021
*/
2122
final class ProjectVersionModeEnumeration
2223
{
23-
const FILE = '0';
24-
const GIT = '1';
25-
const GIT_FILE_FALLBACK = '2';
26-
const STATIC_VERSION = '3';
24+
public const FILE = '0';
25+
public const GIT = '1';
26+
public const GIT_FILE_FALLBACK = '2';
27+
public const STATIC_VERSION = '3';
2728
}

Classes/Backend/ToolbarItems/ProjectVersionSlot.php renamed to Classes/EventListener/ProjectVersionEventListener.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
2+
23
declare(strict_types=1);
34

4-
namespace KamiYang\ProjectVersion\Backend\ToolbarItems;
5+
namespace KamiYang\ProjectVersion\EventListener;
56

67
/*
78
* This file is part of the ProjectVersion project.
@@ -17,33 +18,30 @@
1718

1819
use KamiYang\ProjectVersion\Facade\LocalizationUtilityFacade;
1920
use KamiYang\ProjectVersion\Service\ProjectVersionService;
20-
use TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem;
21-
use TYPO3\CMS\Core\SingletonInterface;
21+
use TYPO3\CMS\Backend\Backend\Event\SystemInformationToolbarCollectorEvent;
2222
use TYPO3\CMS\Core\Utility\GeneralUtility;
2323
use TYPO3\CMS\Core\Utility\StringUtility;
24-
use TYPO3\CMS\Extbase\Object\ObjectManager;
2524

26-
/**
27-
* Class ProjectVersionSlot
28-
*/
29-
final class ProjectVersionSlot implements SingletonInterface
25+
final class ProjectVersionEventListener
3026
{
31-
/**
32-
* @param \TYPO3\CMS\Backend\Backend\ToolbarItems\SystemInformationToolbarItem $pObj
33-
*/
34-
public function getProjectVersion(SystemInformationToolbarItem $pObj)
27+
private $projectVersionService;
28+
29+
public function __construct(ProjectVersionService $projectVersionService)
30+
{
31+
$this->projectVersionService = $projectVersionService;
32+
}
33+
34+
public function __invoke(SystemInformationToolbarCollectorEvent $event)
3535
{
36-
$projectVersion = GeneralUtility::makeInstance(ObjectManager::class)
37-
->get(ProjectVersionService::class)
38-
->getProjectVersion();
36+
$projectVersion = $this->projectVersionService->getProjectVersion();
3937

4038
$version = $projectVersion->getVersion();
4139

4240
if (StringUtility::beginsWith($version, 'LLL:')) {
4341
$version = GeneralUtility::makeInstance(LocalizationUtilityFacade::class)->translate($version);
4442
}
4543

46-
$pObj->addSystemInformation(
44+
$event->getToolbarItem()->addSystemInformation(
4745
$projectVersion->getTitle(),
4846
$version,
4947
$projectVersion->getIconIdentifier()

Classes/Facade/CommandUtilityFacade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace KamiYang\ProjectVersion\Facade;

Classes/Facade/LocalizationUtilityFacade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace KamiYang\ProjectVersion\Facade;

Classes/Facade/SystemEnvironmentBuilderFacade.php

Lines changed: 0 additions & 39 deletions
This file was deleted.

Classes/Service/ProjectVersion.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace KamiYang\ProjectVersion\Service;
@@ -22,12 +23,13 @@
2223
*/
2324
class ProjectVersion implements SingletonInterface
2425
{
25-
const UNKNOWN_VERSION = 'LLL:EXT:project_version/Resources/Private/Language/Backend.xlf:toolbarItems.sysinfo.project-version.unknown';
26+
public const UNKNOWN_VERSION = self::LLL . ':toolbarItems.sysinfo.project-version.unknown';
27+
private const LLL = 'LLL:EXT:project_version/Resources/Private/Language/Backend.xlf';
2628

2729
/**
2830
* @var string $title
2931
*/
30-
protected $title = 'LLL:EXT:project_version/Resources/Private/Language/Backend.xlf:toolbarItems.sysinfo.project-version';
32+
protected $title = self::LLL . ':toolbarItems.sysinfo.project-version';
3133

3234
/**
3335
* @var string $version
@@ -50,7 +52,7 @@ public function getTitle(): string
5052
/**
5153
* @param string $title
5254
*/
53-
public function setTitle(string $title)
55+
public function setTitle(string $title): void
5456
{
5557
$this->title = $title;
5658
}
@@ -66,7 +68,7 @@ public function getVersion(): string
6668
/**
6769
* @param string $version
6870
*/
69-
public function setVersion(string $version)
71+
public function setVersion(string $version): void
7072
{
7173
$this->version = $version;
7274
}
@@ -82,7 +84,7 @@ public function getIconIdentifier(): string
8284
/**
8385
* @param string $iconIdentifier
8486
*/
85-
public function setIconIdentifier(string $iconIdentifier)
87+
public function setIconIdentifier(string $iconIdentifier): void
8688
{
8789
$this->iconIdentifier = $iconIdentifier;
8890
}

0 commit comments

Comments
 (0)