-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLegacyMethodsTrait.php
More file actions
50 lines (40 loc) · 1.11 KB
/
LegacyMethodsTrait.php
File metadata and controls
50 lines (40 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
declare(strict_types=1);
/*
* Studio 107 (c) 2017 Maxim Falaleev
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mindy\Application;
@trigger_error('The '.__NAMESPACE__.' class is deprecated since version 3.0 and will be removed in 4.2.', E_USER_DEPRECATED);
/**
* Class LegacyMethodsTrait.
*
* @method \Symfony\Component\DependencyInjection\ContainerInterface getContainer()
*/
trait LegacyMethodsTrait
{
public function hasComponent($id)
{
return $this->getContainer()->has($id);
}
public function getComponent($id)
{
return $this->getContainer()->get($id);
}
public function getUser()
{
if (!$this->getContainer()->has('security.token_storage')) {
return;
}
if (null === $token = $this->getContainer()->get('security.token_storage')->getToken()) {
return;
}
if (!is_object($user = $token->getUser())) {
// e.g. anonymous authentication
return;
}
return $user;
}
}