Passed
Push — master ( 8276d9...eeb046 )
by Julito
11:16
created

ControllerTrait::trans()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Traits;
6
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9
use Symfony\Contracts\Translation\TranslatorInterface;
10
11
trait ControllerTrait
12
{
13
    /**
14
     * @return Request|null
15
     */
16
    public function getRequest()
17
    {
18
        return $this->container->get('request_stack')->getCurrentRequest();
19
    }
20
21
    /**
22
     * @param string $message
23
     *
24
     * @return NotFoundHttpException
25
     */
26
    public function abort($message = '')
27
    {
28
        return new NotFoundHttpException($message);
29
    }
30
31
    /**
32
     * Translator shortcut.
33
     *
34
     * @param string $variable
35
     *
36
     * @return string
37
     */
38
    public function trans($variable)
39
    {
40
        /** @var TranslatorInterface $translator */
41
        $translator = $this->container->get('translator');
42
43
        return $translator->trans($variable);
44
    }
45
}
46