Completed
Push — master ( 815120...7a7e0c )
by Julito
46:08
created

Container::getRoles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Framework;
5
6
use Symfony\Component\DependencyInjection\ContainerInterface;
7
use Symfony\Component\HttpFoundation\Session\Session;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Session\SessionInterface;
10
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
11
use Symfony\Component\Security\Core\Role\RoleHierarchy;
12
use Symfony\Component\Security\Core\SecurityContextInterface;
13
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
14
use Symfony\Bundle\FrameworkBundle\Translation\Translator;
15
use Symfony\Component\Templating\Helper\CoreAssetsHelper;
16
use Chamilo\CoreBundle\Component\Editor\Editor;
17
use Symfony\Component\Translation\TranslatorInterface;
18
19
/**
20
 * Class Container
21
 * This class is a way to access Symfony2 services in legacy Chamilo code.
22
 * @package Chamilo\CoreBundle\Framework
23
 */
24
class Container
25
{
26
    /**
27
     * @var ContainerInterface
28
     */
29
    public static $container;
30
    public static $session;
31
    public static $request;
32
    public static $configuration;
33
    public static $environment;
34
    public static $urlGenerator;
35
    public static $checker;
36
    public static $translator;
37
    public static $mailer;
38
    public static $template;
39
40
    public static $rootDir;
41
    public static $logDir;
42
    public static $tempDir;
43
    public static $dataDir;
44
    public static $courseDir;
45
    public static $configDir;
46
    public static $assets;
47
    public static $htmlEditor;
48
    public static $twig;
49
    public static $roles;
50
    /** @var  string  */
51
    public static $legacyTemplate = '@ChamiloTheme/Layout/layout_one_col.html.twig';
52
53
    /**
54
     * @param ContainerInterface $container
55
     */
56
    public static function setContainer($container)
57
    {
58
        self::$container = $container;
59
    }
60
61
    /**
62
     * @return string
63
     */
64
    public static function getConfigDir()
65
    {
66
        return self::$configDir;
67
    }
68
69
    /**
70
     * @param string $parameter
71
     *
72
     * @return mixed
73
     */
74
    public static function getParameter($parameter)
75
    {
76
        if (self::$container->hasParameter($parameter)) {
77
            return self::$container->getParameter($parameter);
78
        }
79
80
        return false;
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public static function getEnvironment()
87
    {
88
        return self::$container->get('kernel')->getEnvironment();
89
    }
90
91
    /**
92
     * @return RoleHierarchy
93
     */
94
    public static function getRoles()
95
    {
96
        return self::$container->get('security.role_hierarchy');
97
    }
98
99
    /**
100
     * @return string
101
     */
102
    public static function getLogDir()
103
    {
104
        return self::$container->get('kernel')->getLogDir();
105
    }
106
107
    /**
108
     * @return string
109
     */
110
    public static function getTempDir()
111
    {
112
        return self::$container->get('kernel')->getCacheDir().'/';
113
    }
114
115
    /**
116
     * @return string
117
     */
118
    public static function getRootDir()
119
    {
120
        return self::$container->get('kernel')->getRealRootDir();
121
    }
122
123
    /**
124
     * @return string
125
     */
126
    public static function getUrlAppend()
127
    {
128
        return self::$container->get('kernel')->getUrlAppend();
129
    }
130
131
    /**
132
     * @return string
133
     */
134
    public static function isInstalled()
135
    {
136
        return self::$container->get('kernel')->isInstalled();
137
    }
138
139
    /**
140
     * @return string
141
     */
142
    public static function getDataDir()
143
    {
144
        return self::$dataDir;
145
    }
146
147
    /**
148
     * @return string
149
     */
150
    public static function getCourseDir()
151
    {
152
        return self::$courseDir;
153
    }
154
155
    /**
156
     * @return \Twig_Environment
157
     */
158
    public static function getTwig()
159
    {
160
        return self::$container->get('twig');
161
    }
162
163
    /**
164
     * @return \Symfony\Bundle\TwigBundle\TwigEngine
165
     */
166
    public static function getTemplating()
167
    {
168
        return self::$container->get('templating');
169
    }
170
171
    /**
172
     * @return Editor
173
     */
174
    public static function getHtmlEditor()
175
    {
176
        return self::$container->get('chamilo_core.html_editor');
177
    }
178
179
    /**
180
     * @return \Symfony\Bundle\FrameworkBundle\Routing\Router
181
     */
182
    public static function getUrlGenerator()
183
    {
184
        return self::$container->get('router');
185
    }
186
187
    /**
188
     * @return Request
189
     */
190
    public static function getRequest()
191
    {
192
        return self::$container->get('request');
193
    }
194
195
    /*public static function setRequest($request)
196
    {
197
        self::$request = $request;
198
    }*/
199
200
    /**
201
     * @return Session
202
     */
203
    public static function getSession()
204
    {
205
        return self::$container->get('session');
206
    }
207
208
    /**
209
     * @return AuthorizationChecker
210
     */
211
    public static function getAuthorizationChecker()
212
    {
213
        return self::$container->get('security.authorization_checker');
214
    }
215
216
    /**
217
     * @return object|\Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage
218
     */
219
    public static function getTokenStorage()
220
    {
221
        return self::$container->get('security.token_storage');
222
    }
223
224
    /**
225
     * @return TranslatorInterface
226
     */
227
    public static function getTranslator()
228
    {
229
        return self::$container->get('translator.default');
230
    }
231
232
    /**
233
     * @return CoreAssetsHelper
234
     */
235
    public static function getAsset()
236
    {
237
        return self::$container->get('templating.helper.assets');
238
    }
239
240
    /**
241
     * @return \Swift_Mailer
242
     */
243
    public static function getMailer()
244
    {
245
       return self::$container->get('mailer');
246
    }
247
248
    /**
249
     * @return \Elao\WebProfilerExtraBundle\TwigProfilerEngine
250
     */
251
    public static function getTemplate()
252
    {
253
        return self::$container->get('templating');
254
    }
255
256
    /**
257
     * @return \Chamilo\SettingsBundle\Manager\SettingsManager
258
     */
259
    public static function getSettingsManager()
260
    {
261
        return self::$container->get('chamilo.settings.manager');
262
    }
263
264
    /**
265
     * @return \Chamilo\CourseBundle\Manager\SettingsManager
266
     */
267
    public static function getCourseSettingsManager()
268
    {
269
        return self::$container->get('chamilo_course.settings.manager');
270
    }
271
272
    /**
273
     * @return \Doctrine\ORM\EntityManager
274
     */
275
    public static function getEntityManager()
276
    {
277
        return \Database::getManager();
278
    }
279
280
    /**
281
     * @return \Sonata\UserBundle\Entity\UserManager
282
     */
283
    public static function getUserManager()
284
    {
285
        //return self::$container->get('sonata.user.user_manager');
286
        return self::$container->get('fos_user.user_manager');
287
    }
288
289
    /**
290
     * @return \Sonata\UserBundle\Entity\GroupManager
291
     */
292
    public static function getGroupManager()
293
    {
294
        return self::$container->get('fos_user.group_manager');
295
    }
296
297
    /**
298
     * @return \Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher
299
     */
300
    public static function getEventDispatcher()
301
    {
302
        return self::$container->get('event_dispatcher');
303
    }
304
305
    /**
306
     * @return \Symfony\Component\Form\FormFactory
307
     */
308
    public static function getFormFactory()
309
    {
310
        return self::$container->get('form.factory');
311
    }
312
313
    /**
314
     * @param string $message
315
     * @param string $type error|success|warning|danger
316
     */
317
    public static function addFlash($message, $type = 'success')
318
    {
319
        $session = self::getSession();
320
        $session->getFlashBag()->add($type, $message);
321
    }
322
323
    /**
324
     * @return \Symfony\Bundle\FrameworkBundle\Routing\Router
325
     */
326
    public static function getRouter()
327
    {
328
        return self::$container->get('router');
329
    }
330
331
    /**
332
     * @return \Chamilo\CourseBundle\ToolChain
333
     */
334
    public static function getToolChain()
335
    {
336
        return self::$container->get('chamilo_course.tool_chain');
337
    }
338
}
339