1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the TheAlternativeZurich/events project. |
5
|
|
|
* |
6
|
|
|
* (c) Florian Moser <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace App\Controller\Base; |
13
|
|
|
|
14
|
|
|
use App\Entity\User; |
15
|
|
|
use App\Security\UserToken; |
16
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
17
|
|
|
use Symfony\Component\HttpFoundation\Session\SessionInterface; |
18
|
|
|
|
19
|
|
|
class BaseController extends AbstractController |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @return User|null |
23
|
|
|
*/ |
24
|
|
|
protected function getUser() |
25
|
|
|
{ |
26
|
|
|
$token = $this->container->get('security.token_storage')->getToken(); |
27
|
|
|
|
28
|
|
|
if (!($token instanceof UserToken)) { |
29
|
|
|
return null; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$userRepository = $this->getDoctrine()->getRepository(User::class); |
|
|
|
|
33
|
|
|
|
34
|
|
|
return $userRepository->findOneBy(['email' => $token->getUser()]); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public static function getSubscribedServices() |
38
|
|
|
{ |
39
|
|
|
return parent::getSubscribedServices() + ['session' => '?'.SessionInterface::class]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param string $message the translation message to display |
44
|
|
|
* @param string $link |
45
|
|
|
*/ |
46
|
|
|
protected function displayError($message, $link = null) |
47
|
|
|
{ |
48
|
|
|
$this->displayFlash('danger', $message, $link); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param string $message the translation message to display |
53
|
|
|
* @param string $link |
54
|
|
|
*/ |
55
|
|
|
protected function displaySuccess($message, $link = null) |
56
|
|
|
{ |
57
|
|
|
$this->displayFlash('success', $message, $link); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param string $message the translation message to display |
62
|
|
|
* @param string $link |
63
|
|
|
*/ |
64
|
|
|
protected function displayDanger($message, $link = null) |
65
|
|
|
{ |
66
|
|
|
$this->displayFlash('danger', $message, $link); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $message the translation message to display |
71
|
|
|
* @param string $link |
72
|
|
|
*/ |
73
|
|
|
protected function displayInfo($message, $link = null) |
74
|
|
|
{ |
75
|
|
|
$this->displayFlash('info', $message, $link); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param $type |
80
|
|
|
* @param $message |
81
|
|
|
* @param string $link |
82
|
|
|
*/ |
83
|
|
|
private function displayFlash($type, $message, $link = null) |
84
|
|
|
{ |
85
|
|
|
if (null !== $link) { |
86
|
|
|
$message = '<a href="'.$link.'">'.$message.'</a>'; |
87
|
|
|
} |
88
|
|
|
$this->get('session')->getFlashBag()->set($type, $message); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.