Completed
Push — master ( eba3fc...7f8ec6 )
by Tim
16s queued 11s
created

EventMapper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 57
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A generate() 0 7 1
A resolve() 0 24 2
1
<?php
2
/**
3
 * EventMapper.
4
 */
5
6
declare(strict_types=1);
7
8
namespace HDNET\Calendarize\Routing\Aspect;
9
10
use HDNET\Calendarize\Service\Url\Typo3Route;
11
use TYPO3\CMS\Core\Context\Context;
12
use TYPO3\CMS\Core\Context\LanguageAspectFactory;
13
use TYPO3\CMS\Core\Routing\Aspect\PersistedMappableAspectInterface;
14
use TYPO3\CMS\Core\Routing\Aspect\StaticMappableAspectInterface;
15
use TYPO3\CMS\Core\Routing\RouteNotFoundException;
16
use TYPO3\CMS\Core\Site\SiteLanguageAwareInterface;
17
use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait;
18
use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20
/**
21
 * EventMapper.
22
 *
23
 * @deprecated
24
 */
25
class EventMapper implements PersistedMappableAspectInterface, StaticMappableAspectInterface, SiteLanguageAwareInterface
26
{
27
    use SiteLanguageAwareTrait;
28
29
    public function __construct()
30
    {
31
        @trigger_error(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
32
            'EventMapper will be removed. Use the slug field with PersistedAliasMapper instead.',
33
            \E_USER_DEPRECATED
34
        );
35
    }
36
37
    /**
38
     * @param string $value
39
     *
40
     * @return string|null
41
     */
42
    public function generate(string $value): ?string
43
    {
44
        $route = GeneralUtility::makeInstance(Typo3Route::class);
45
        $speaking = $route->convert(['generate' => $value], null);
46
47
        return $speaking;
48
    }
49
50
    /**
51
     * @param string $value
52
     *
53
     * @throws \Exception
54
     *
55
     * @return string|null
56
     */
57
    public function resolve(string $value): ?string
58
    {
59
        // Set the language in the context, so that the index repository fetches
60
        // the translated record (is set in Typo3QuerySettings->initializeObject(),
61
        // which is used by findByUid).
62
        // This is only required, when a existing url is resolved, since the
63
        // value is checked for correctness with $this->generate.
64
        // Alternative: Use overlay function of the pageRepository, similar to PersistedPatternMapper
65
        // @TODO: Warning: This may have unexpected site effects!
66
        $context = GeneralUtility::makeInstance(Context::class);
67
        $context->setAspect(
68
            'language',
69
            LanguageAspectFactory::createFromSiteLanguage($this->siteLanguage)
70
        );
71
72
        $route = GeneralUtility::makeInstance(Typo3Route::class);
73
        $id = (string)$route->convert(['resolve' => $value], null);
74
75
        if ($this->generate($id) !== $value) {
76
            throw new RouteNotFoundException('Wrong realurl segment', 12378);
77
        }
78
79
        return $id;
80
    }
81
}
82