Skip to content

Commit 20683ae

Browse files
committed
[TASK] Replace deprecated hook with event listener, code style fixes
1 parent 0e51e4b commit 20683ae

10 files changed

+71
-41
lines changed

Classes/Domain/DTO/Configuration.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the "Locate" extension for TYPO3 CMS.
5+
*
6+
* For the full copyright and license information, please read the
7+
* LICENSE.txt file that was distributed with this source code.
8+
*
9+
* Team YD <[email protected]>, Leuchtfeuer Digital Marketing
10+
*/
11+
312
namespace Leuchtfeuer\Locate\Domain\DTO;
413

514
class Configuration
@@ -140,4 +149,4 @@ public function getSettings(): array
140149
'simulateIp' => $this->getSimulateIp(),
141150
];
142151
}
143-
}
152+
}

Classes/Hook/OverrideIconOverlayHook.php Classes/EventListener/ModifyRecordOverlayIconIdentifierEventListener.php

+19-7
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,30 @@
99
* Team YD <[email protected]>, Leuchtfeuer Digital Marketing
1010
*/
1111

12-
namespace Leuchtfeuer\Locate\Hook;
12+
namespace Leuchtfeuer\Locate\EventListener;
1313

1414
use Doctrine\DBAL\Exception;
15+
use Leuchtfeuer\Locate\Utility\TypeCaster;
16+
use TYPO3\CMS\Core\Attribute\AsEventListener;
1517
use TYPO3\CMS\Core\Database\ConnectionPool;
18+
use TYPO3\CMS\Core\Imaging\Event\ModifyRecordOverlayIconIdentifierEvent;
1619
use TYPO3\CMS\Core\Utility\GeneralUtility;
1720

18-
class OverrideIconOverlayHook
21+
final readonly class ModifyRecordOverlayIconIdentifierEventListener
1922
{
2023
/**
2124
* @throws Exception
2225
*/
23-
public function postOverlayPriorityLookup(string $table, array $row, array $status, string $iconName): string
26+
#[AsEventListener(
27+
identifier: 'locate/modify-record-overlay-icon-identifier',
28+
event: ModifyRecordOverlayIconIdentifierEvent::class
29+
)]
30+
public function __invoke(ModifyRecordOverlayIconIdentifierEvent $event): void
2431
{
32+
$table = $event->getTable();
33+
$row = $event->getRow();
34+
$iconName = $event->getOverlayIconIdentifier();
35+
2536
if ($table === 'pages' && !empty($row) && !str_contains((string)$row['uid'], 'NEW')) {
2637
// since tx_locate_regions is not included in the row array (PageTreeRepository is initialized with empty additionalFields)
2738
// we need to get the necessary information on our own
@@ -40,10 +51,11 @@ public function postOverlayPriorityLookup(string $table, array $row, array $stat
4051
}
4152
}
4253

43-
return $iconName;
54+
$event->setOverlayIconIdentifier($iconName);
4455
}
4556

4657
/**
58+
* @param array<string, mixed> $row
4759
* @throws Exception
4860
*/
4961
private function countRegions(string $table, array $row): int
@@ -54,9 +66,9 @@ private function countRegions(string $table, array $row): int
5466

5567
$qb = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
5668

57-
return (int)$qb
69+
return TypeCaster::toInt($qb
5870
->select('tx_locate_regions')
59-
->from($table)->where($qb->expr()->eq('uid', $row['uid']))->executeQuery()
60-
->fetchOne();
71+
->from($table)->where($qb->expr()->eq('uid', TypeCaster::toInt($row['uid'])))->executeQuery()
72+
->fetchOne());
6173
}
6274
}

Classes/Middleware/LanguageRedirectMiddleware.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@
1515

1616
use Leuchtfeuer\Locate\Domain\DTO\Configuration;
1717
use Leuchtfeuer\Locate\Processor\Court;
18-
use Leuchtfeuer\Locate\Verdict\Redirect;
1918
use Psr\Http\Message\ResponseInterface;
2019
use Psr\Http\Message\ServerRequestInterface;
2120
use Psr\Http\Server\MiddlewareInterface;
2221
use Psr\Http\Server\RequestHandlerInterface;
23-
use TYPO3\CMS\Backend\Routing\RouteResult;
2422
use TYPO3\CMS\Core\LinkHandling\Exception\UnknownLinkHandlerException;
2523
use TYPO3\CMS\Core\LinkHandling\LinkService;
2624
use TYPO3\CMS\Core\Routing\PageArguments;
27-
use TYPO3\CMS\Core\Routing\SiteRouteResult;
2825
use TYPO3\CMS\Core\Site\Entity\Site;
29-
use TYPO3\CMS\Core\Utility\GeneralUtility;
3026
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
3127
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
3228

@@ -59,8 +55,8 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
5955
$config->setExcludeBots((bool)($locateSetup['excludeBots'] ?? 1));
6056
$config->setSimulateIp((string)($locateSetup['simulateIp'] ?? ''));
6157
$config->setJudges($locateSetup['judges.'] ?? []);
62-
$config->setFacts( $locateSetup['facts.'] ?? []);
63-
$config->setVerdicts( $locateSetup['verdicts.'] ?? []);
58+
$config->setFacts($locateSetup['facts.'] ?? []);
59+
$config->setVerdicts($locateSetup['verdicts.'] ?? []);
6460

6561
return $this->court->withConfiguration($config)->run() ?? $handler->handle($request);
6662
}

Classes/Processor/Court.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ class Court implements ProcessorInterface
3838
*/
3939
protected array $facts = [];
4040

41-
public function __construct(private readonly LoggerInterface $logger)
42-
{
43-
44-
}
41+
public function __construct(private readonly LoggerInterface $logger) {}
4542

4643
public function withConfiguration(Configuration $configuration): self
4744
{

Classes/Processor/ProcessorInterface.php

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
interface ProcessorInterface
2121
{
22-
2322
public function __construct(LoggerInterface $logger);
2423

2524
public function withConfiguration(Configuration $configuration): self;

Classes/Utility/TypeCaster.php

+18-11
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22

33
declare(strict_types=1);
44

5-
namespace Leuchtfeuer\Locate\Utility;
5+
/*
6+
* This file is part of the "Locate" extension for TYPO3 CMS.
7+
*
8+
* For the full copyright and license information, please read the
9+
* LICENSE.txt file that was distributed with this source code.
10+
*
11+
* Team YD <[email protected]>, Leuchtfeuer Digital Marketing
12+
*/
613

7-
use Exception;
14+
namespace Leuchtfeuer\Locate\Utility;
815

916
class TypeCaster
1017
{
@@ -17,7 +24,7 @@ public static function toInt(mixed $value): int
1724
return (int)$value;
1825
}
1926

20-
throw new Exception(sprintf('Value of type "%s" can not be casted to integer.', gettype($value)), 1727337294);
27+
throw new \Exception(sprintf('Value of type "%s" can not be casted to integer.', gettype($value)), 1727337294);
2128
}
2229

2330
public static function toString(mixed $value): string
@@ -32,10 +39,10 @@ public static function toString(mixed $value): string
3239
return (string)$value;
3340
}
3441
if (is_object($value) && !method_exists($value, '__toString')) {
35-
throw new Exception(sprintf('Object of type "%s" is not stringable.', get_class($value)), 1727337280);
42+
throw new \Exception(sprintf('Object of type "%s" is not stringable.', get_class($value)), 1727337280);
3643
}
3744

38-
throw new Exception(sprintf('Value of type "%s" can not be casted to string.', gettype($value)), 1727337295);
45+
throw new \Exception(sprintf('Value of type "%s" can not be casted to string.', gettype($value)), 1727337295);
3946
}
4047

4148
public static function toBool(mixed $value): bool
@@ -47,14 +54,14 @@ public static function toBool(mixed $value): bool
4754
return (bool)$value;
4855
}
4956

50-
throw new Exception(sprintf('Value of type "%s" can not be casted to boolean.', gettype($value)), 1727337296);
57+
throw new \Exception(sprintf('Value of type "%s" can not be casted to boolean.', gettype($value)), 1727337296);
5158
}
5259

5360
/**
5461
* @template T
5562
* @param class-string<T> $className
5663
* @return T
57-
* @throws Exception
64+
* @throws \Exception
5865
*/
5966
public static function limitToClass(mixed $value, string $className)
6067
{
@@ -63,21 +70,21 @@ public static function limitToClass(mixed $value, string $className)
6370
}
6471

6572
if (gettype($value) === 'object') {
66-
throw new Exception(sprintf('Object of type "%s" is not instance of "%s"', get_class($value), $className), 1727337297);
73+
throw new \Exception(sprintf('Object of type "%s" is not instance of "%s"', get_class($value), $className), 1727337297);
6774
}
68-
throw new Exception(sprintf('Value of type "%s" is not instance of "%s"', gettype($value), $className), 1727337298);
75+
throw new \Exception(sprintf('Value of type "%s" is not instance of "%s"', gettype($value), $className), 1727337298);
6976
}
7077

7178
/**
7279
* @return array<int|string, mixed>
73-
* @throws Exception
80+
* @throws \Exception
7481
*/
7582
public static function limitToArray(mixed $value): array
7683
{
7784
if (is_array($value)) {
7885
return $value;
7986
}
8087

81-
throw new Exception(sprintf('Value of type "%s" is not an array.', gettype($value)), 1727337299);
88+
throw new \Exception(sprintf('Value of type "%s" is not an array.', gettype($value)), 1727337299);
8289
}
8390
}

Classes/Verdict/AbstractVerdict.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ abstract class AbstractVerdict
2828

2929
public function __construct(
3030
protected readonly LoggerInterface $logger,
31-
)
32-
{
31+
) {
3332
$this->session = new SessionStore();
3433
}
3534

ext_tables.php

-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,2 @@
11
<?php
22
defined('TYPO3') || die('Access denied.');
3-
4-
call_user_func(
5-
function ($extensionKey) {
6-
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][\TYPO3\CMS\Core\Imaging\IconFactory::class]['overrideIconOverlay'][$extensionKey]
7-
= \Leuchtfeuer\Locate\Hook\OverrideIconOverlayHook::class;
8-
}, 'locate'
9-
);

fractor.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the "Locate" extension for TYPO3 CMS.
5+
*
6+
* For the full copyright and license information, please read the
7+
* LICENSE.txt file that was distributed with this source code.
8+
*
9+
* Team YD <[email protected]>, Leuchtfeuer Digital Marketing
10+
*/
11+
312
use a9f\Fractor\Configuration\FractorConfiguration;
413
use a9f\FractorTypoScript\Configuration\TypoScriptProcessorOption;
514
use a9f\Typo3Fractor\Set\Typo3LevelSetList;
@@ -13,7 +22,7 @@
1322
__DIR__ . '/.Build',
1423
])
1524
->withSets([
16-
Typo3LevelSetList::UP_TO_TYPO3_13
25+
Typo3LevelSetList::UP_TO_TYPO3_13,
1726
])
1827
->withOptions([
1928
TypoScriptProcessorOption::INDENT_SIZE => 4,

rector.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
declare(strict_types=1);
44

5+
/*
6+
* This file is part of the "Locate" extension for TYPO3 CMS.
7+
*
8+
* For the full copyright and license information, please read the
9+
* LICENSE.txt file that was distributed with this source code.
10+
*
11+
* Team YD <[email protected]>, Leuchtfeuer Digital Marketing
12+
*/
13+
514
use Rector\Config\RectorConfig;
615
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;
716
use Ssch\TYPO3Rector\Set\Typo3LevelSetList;
@@ -16,7 +25,7 @@
1625
)
1726
->withPhpSets(php83: true)
1827
->withRules([
19-
TypedPropertyFromStrictConstructorRector::class
28+
TypedPropertyFromStrictConstructorRector::class,
2029
])
2130
->withSets([
2231
Typo3SetList::CODE_QUALITY,

0 commit comments

Comments
 (0)