Completed
Push — development ( ef0625...f79737 )
by Torben
04:11
created

HmacViewHelper::render()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 3
nc 2
nop 0
1
<?php
2
namespace DERHANSEN\SfEventMgt\ViewHelpers\Registration;
3
4
/*
5
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.txt file that was distributed with this source code.
9
 */
10
11
use DERHANSEN\SfEventMgt\Domain\Model\Registration;
12
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
13
14
/**
15
 * Hmac ViewHelper for registrations
16
 *
17
 * @author Torben Hansen <[email protected]>
18
 */
19
class HmacViewHelper extends AbstractViewHelper
20
{
21
    /**
22
     * Hash Service
23
     *
24
     * @var \TYPO3\CMS\Extbase\Security\Cryptography\HashService
25
     * */
26
    protected $hashService;
27
28
    /**
29
     * DI for $hashService
30
     *
31
     * @param \TYPO3\CMS\Extbase\Security\Cryptography\HashService $hashService
32
     */
33
    public function injectHashService(\TYPO3\CMS\Extbase\Security\Cryptography\HashService $hashService)
34
    {
35
        $this->hashService = $hashService;
36
    }
37
38
    /**
39
     * Initialize arguments
40
     */
41
    public function initializeArguments()
42
    {
43
        parent::initializeArguments();
44
        $this->registerArgument('registration', 'object', 'Registration', false);
45
    }
46
47
    /**
48
     * Returns the hmac for the given registration in order to cancel the registration
49
     *
50
     * @return string
51
     */
52
    public function render()
53
    {
54
        /** @var Registration $registration */
55
        $registration = $this->arguments['registration'];
56
        $result = '';
57
        if ($registration && is_a(Registration::class, $registration)) {
58
            $result = $this->hashService->generateHmac('reg-' . $registration->getUid());
59
        }
60
61
        return $result;
62
    }
63
}
64