Completed
Push — master ( efcbbc...1b7a17 )
by Julito
08:40
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\Manager\SettingsManager;
10
use Chamilo\CoreBundle\Repository\ResourceFactory;
11
use Knp\Menu\FactoryInterface as MenuFactoryInterface;
12
use Sylius\Bundle\SettingsBundle\Form\Factory\SettingsFormFactory;
13
use Symfony\Component\HttpFoundation\Request;
14
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
15
use Symfony\Contracts\Translation\TranslatorInterface;
16
17
trait ControllerTrait
18
{
19
    public static function getSubscribedServices(): array
20
    {
21
        $services = parent::getSubscribedServices();
22
        $services['translator'] = TranslatorInterface::class;
23
        //$services['breadcrumb'] = BreadcrumbBlockService::class;
24
        $services['resource_factory'] = ResourceFactory::class;
25
        $services['glide'] = Glide::class;
26
        $services['chamilo.settings.manager'] = SettingsManager::class;
27
        $services['chamilo_settings.form_factory.settings'] = SettingsFormFactory::class;
28
29
        return $services;
30
    }
31
32
    /**
33
     * @return Request|null
34
     */
35
    public function getRequest()
36
    {
37
        return $this->container->get('request_stack')->getCurrentRequest();
38
    }
39
40
    /*public function getBreadCrumb(): BreadcrumbBlockService
41
    {
42
        return $this->container->get('breadcrumb');
43
    }*/
44
45
    /**
46
     * @return MenuFactoryInterface
47
     */
48
    public function getMenuFactory()
49
    {
50
        return $this->container->get('knp_menu.factory');
51
    }
52
53
    /**
54
     * @param string $message
55
     *
56
     * @return NotFoundHttpException
57
     */
58
    public function abort($message = '')
59
    {
60
        return new NotFoundHttpException($message);
61
    }
62
63
    /**
64
     * Translator shortcut.
65
     *
66
     * @param string $variable
67
     *
68
     * @return string
69
     */
70
    public function trans($variable)
71
    {
72
        /** @var TranslatorInterface $translator */
73
        $translator = $this->container->get('translator');
74
75
        return $translator->trans($variable);
76
    }
77
78
    /**
79
     * @return SettingsManager
80
     */
81
    protected function getSettingsManager()
82
    {
83
        return $this->get('chamilo.settings.manager');
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

83
        return $this->/** @scrutinizer ignore-call */ get('chamilo.settings.manager');
Loading history...
84
    }
85
86
    protected function getSettingsFormFactory()
87
    {
88
        return $this->get('chamilo_settings.form_factory.settings');
89
    }
90
}
91