-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLongTimeNoSeeDetector.php
More file actions
68 lines (55 loc) · 1.73 KB
/
Copy pathLongTimeNoSeeDetector.php
File metadata and controls
68 lines (55 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
declare(strict_types=1);
/*
* This file is part of the "typo3_login_warning" TYPO3 CMS extension.
*
* (c) 2025-2026 Konrad Michalik <km@move-elevator.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MoveElevator\Typo3LoginWarning\Detector;
use DateTime;
use Doctrine\DBAL\Exception;
use MoveElevator\Typo3LoginWarning\Configuration;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Context\Context;
/**
* LongTimeNoSeeDetector.
*
* @author Konrad Michalik <km@move-elevator.de>
* @license GPL-2.0-or-later
*/
class LongTimeNoSeeDetector extends AbstractDetector
{
private const DEFAULT_THRESHOLD_DAYS = 365;
public function __construct(
private readonly Context $context,
) {}
/**
* @param array<string, mixed> $userArray
* @param array<string, mixed> $configuration
*
* @throws Exception
*/
public function detect(array $userArray, array $configuration = [], ?ServerRequestInterface $request = null): bool
{
if (!$this->context->hasAspect(Configuration::EXT_KEY)) {
return false;
}
$lastLogin = $this->context->getPropertyFromAspect(Configuration::EXT_KEY, 'last_login');
if (!$lastLogin instanceof DateTime) {
return false;
}
$currentDate = new DateTime();
$days = $lastLogin->diff($currentDate)->days;
$thresholdDays = (int) ($configuration['thresholdDays'] ?? self::DEFAULT_THRESHOLD_DAYS);
if ($days <= $thresholdDays) {
return false;
}
$this->additionalData = [
'daysSinceLastLogin' => $days,
];
return true;
}
}