summaryrefslogtreecommitdiff
path: root/src/Renderer/Twig/Extensions/Legacy.php
blob: dc0c477570b678cd978d52ea0fb2da8899f3daee (plain)
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
<?php

namespace Engelsystem\Renderer\Twig\Extensions;

use Engelsystem\Http\Request;
use Twig\Extension\AbstractExtension as TwigExtension;
use Twig\TwigFunction;

class Legacy extends TwigExtension
{
    /** @var Request */
    protected $request;

    /**
     * @param Request $request
     */
    public function __construct(Request $request)
    {
        $this->request = $request;
    }

    /**
     * @return TwigFunction[]
     */
    public function getFunctions(): array
    {
        $isSafeHtml = ['is_safe' => ['html']];
        return [
            new TwigFunction('menu', 'make_navigation', $isSafeHtml),
            new TwigFunction('menuUserShiftState', 'User_shift_state_render', $isSafeHtml),
            new TwigFunction('menuUserMessages', 'user_unread_messages', $isSafeHtml),
            new TwigFunction('menuUserHints', 'header_render_hints', $isSafeHtml),
            new TwigFunction('menuUserSubmenu', 'make_user_submenu', $isSafeHtml),
            new TwigFunction('page', [$this, 'getPage']),
            new TwigFunction('msg', 'msg', $isSafeHtml),
        ];
    }

    /**
     * @return string
     */
    public function getPage(): string
    {
        if ($this->request->has('p')) {
            return $this->request->get('p');
        }

        return $this->request->path();
    }
}