Completed
Push — master ( 81aee3...0e26f5 )
by Tim
02:28
created

Typo3Route::id2alias()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * Typo3Route.
5
 */
6
declare(strict_types=1);
7
8
namespace HDNET\Calendarize\Service\Url;
9
10
use HDNET\Calendarize\Domain\Model\Index;
11
use TYPO3\CMS\Core\DataHandling\SlugHelper;
12
use TYPO3\CMS\Core\Utility\GeneralUtility;
13
14
/**
15
 * Typo3Route.
16
 */
17
class Typo3Route extends AbstractUrl
18
{
19
    /**
20
     * Convert the given information.
21
     *
22
     * @param $param1
23
     * @param $param2
24
     *
25
     * @return string
26
     */
27
    public function convert($param1, $param2)
28
    {
29
        if (isset($param1['generate'])) {
30
            return $this->id2alias($param1['generate']);
31
        }
32
33
        return $this->alias2id($param1['resolve']);
34
    }
35
36
    /**
37
     * Handle the alias to index ID convert.
38
     *
39
     * @param $value
40
     *
41
     * @return int
42
     */
43
    protected function alias2id($value): int
44
    {
45
        $parts = GeneralUtility::trimExplode('-', $value, true);
46
47
        return (int) \array_pop($parts);
48
    }
49
50
    /**
51
     * Handle the index ID to alias convert.
52
     *
53
     * @param $value
54
     *
55
     * @return string
56
     */
57
    protected function id2alias($value): string
58
    {
59
        $alias = (string) $this->getIndexBase((int) $value);
60
61
        $slugHelper = GeneralUtility::makeInstance(SlugHelper::class, 'pages', 'uid', []);
62
        $alias = $slugHelper->sanitize($alias);
63
64
        return (string) $alias;
65
    }
66
}
67