HmacViewHelper::injectHashService()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Extension "sf_event_mgt" 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
12
namespace DERHANSEN\SfEventMgt\ViewHelpers\Registration;
13
14
use DERHANSEN\SfEventMgt\Domain\Model\Registration;
15
use DERHANSEN\SfEventMgt\Security\HashScope;
16
use TYPO3\CMS\Core\Crypto\HashService;
17
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
18
19
/**
20
 * Hmac ViewHelper for registrations
21
 */
22
class HmacViewHelper extends AbstractViewHelper
23
{
24
    protected HashService $hashService;
25
26
    public function injectHashService(HashService $hashService): void
27
    {
28
        $this->hashService = $hashService;
29
    }
30
31
    public function initializeArguments(): void
32
    {
33
        parent::initializeArguments();
34
        $this->registerArgument('registration', 'object', 'Registration', true);
35
    }
36
37
    /**
38
     * Returns the hmac for the given registration in order to cancel the registration
39
     */
40
    public function render(): string
41
    {
42
        $registration = $this->arguments['registration'];
43
        $result = '';
44
        if (is_a($registration, Registration::class)) {
45
            $result = $this->hashService->hmac('reg-' . $registration->getUid(), HashScope::RegistrationUid->value);
46
        }
47
48
        return $result;
49
    }
50
}
51