Passed
Push — master ( eeb046...442ea1 )
by Julito
09:25 queued 26s
created

ControllerTrait::getMenuFactory()   A

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 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Traits;
6
7
use Chamilo\CoreBundle\Block\BreadcrumbBlockService;
8
use Knp\Menu\FactoryInterface as MenuFactoryInterface;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
11
use Symfony\Contracts\Translation\TranslatorInterface;
12
13
trait ControllerTrait
14
{
15
    /**
16
     * @return Request|null
17
     */
18
    public function getRequest()
19
    {
20
        return $this->container->get('request_stack')->getCurrentRequest();
21
    }
22
23
    public function getBreadCrumb(): BreadcrumbBlockService
24
    {
25
        return $this->container->get('breadcrumb');
26
    }
27
28
    /**
29
     * @return MenuFactoryInterface
30
     */
31
    public function getMenuFactory()
32
    {
33
        return $this->container->get('knp_menu.factory');
34
    }
35
36
    /**
37
     * @param string $message
38
     *
39
     * @return NotFoundHttpException
40
     */
41
    public function abort($message = '')
42
    {
43
        return new NotFoundHttpException($message);
44
    }
45
46
    /**
47
     * Translator shortcut.
48
     *
49
     * @param string $variable
50
     *
51
     * @return string
52
     */
53
    public function trans($variable)
54
    {
55
        /** @var TranslatorInterface $translator */
56
        $translator = $this->container->get('translator');
57
58
        return $translator->trans($variable);
59
    }
60
}
61