Passed
Push — master ( bdf7a9...a94470 )
by Julito
09:19
created

ControllerTrait::abort()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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 Chamilo\CoreBundle\Component\Utils\Glide;
9
use Chamilo\CoreBundle\Repository\ResourceFactory;
10
use Knp\Menu\FactoryInterface as MenuFactoryInterface;
11
use Symfony\Component\HttpFoundation\Request;
12
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
13
use Symfony\Contracts\Translation\TranslatorInterface;
14
15
trait ControllerTrait
16
{
17
    public static function getSubscribedServices(): array
18
    {
19
        $services = parent::getSubscribedServices();
20
        $services['translator'] = TranslatorInterface::class;
21
        $services['breadcrumb'] = BreadcrumbBlockService::class;
22
        $services['resource_factory'] = ResourceFactory::class;
23
        $services['glide'] = Glide::class;
24
25
        return $services;
26
    }
27
28
    /**
29
     * @return Request|null
30
     */
31
    public function getRequest()
32
    {
33
        return $this->container->get('request_stack')->getCurrentRequest();
34
    }
35
36
    public function getBreadCrumb(): BreadcrumbBlockService
37
    {
38
        return $this->container->get('breadcrumb');
39
    }
40
41
    /**
42
     * @return MenuFactoryInterface
43
     */
44
    public function getMenuFactory()
45
    {
46
        return $this->container->get('knp_menu.factory');
47
    }
48
49
    /**
50
     * @param string $message
51
     *
52
     * @return NotFoundHttpException
53
     */
54
    public function abort($message = '')
55
    {
56
        return new NotFoundHttpException($message);
57
    }
58
59
    /**
60
     * Translator shortcut.
61
     *
62
     * @param string $variable
63
     *
64
     * @return string
65
     */
66
    public function trans($variable)
67
    {
68
        /** @var TranslatorInterface $translator */
69
        $translator = $this->container->get('translator');
70
71
        return $translator->trans($variable);
72
    }
73
}
74