1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the vseth-semesterly-reports 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\Model\Breadcrumb; |
15
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
16
|
|
|
use Symfony\Component\HttpFoundation\Response; |
17
|
|
|
use Symfony\Component\Security\Csrf\TokenStorage\TokenStorageInterface; |
18
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
19
|
|
|
|
20
|
|
|
class BaseController extends AbstractController |
21
|
|
|
{ |
22
|
|
|
public static function getSubscribedServices() |
23
|
|
|
{ |
24
|
|
|
return parent::getSubscribedServices() + |
25
|
|
|
[ |
26
|
|
|
'security.token_storage' => TokenStorageInterface::class, |
27
|
|
|
'translator' => TranslatorInterface::class, |
28
|
|
|
]; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return TranslatorInterface |
33
|
|
|
*/ |
34
|
|
|
protected function getTranslator() |
35
|
|
|
{ |
36
|
|
|
return $this->get('translator'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param string $message the translation message to display |
41
|
|
|
* @param string $link |
42
|
|
|
*/ |
43
|
|
|
protected function displayError($message, $link = null) |
44
|
|
|
{ |
45
|
|
|
$this->displayFlash('danger', $message, $link); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param string $message the translation message to display |
50
|
|
|
* @param string $link |
51
|
|
|
*/ |
52
|
|
|
protected function displaySuccess($message, $link = null) |
53
|
|
|
{ |
54
|
|
|
$this->displayFlash('success', $message, $link); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $message the translation message to display |
59
|
|
|
* @param string $link |
60
|
|
|
*/ |
61
|
|
|
protected function displayInfo($message, $link = null) |
62
|
|
|
{ |
63
|
|
|
$this->displayFlash('info', $message, $link); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param $type |
68
|
|
|
* @param $message |
69
|
|
|
* @param string $link |
70
|
|
|
*/ |
71
|
|
|
private function displayFlash($type, $message, $link = null) |
72
|
|
|
{ |
73
|
|
|
if (null !== $link) { |
74
|
|
|
$message = '<a href="' . $link . '">' . $message . '</a>'; |
75
|
|
|
} |
76
|
|
|
$this->get('session')->getFlashBag()->set($type, $message); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return Breadcrumb[]|array |
81
|
|
|
*/ |
82
|
|
|
protected function getIndexBreadcrumbs() |
83
|
|
|
{ |
84
|
|
|
return []; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Renders a view. |
89
|
|
|
* |
90
|
|
|
* @param Breadcrumb[] $breadcrumbs |
91
|
|
|
*/ |
92
|
|
|
protected function render(string $view, array $parameters = [], Response $response = null, array $breadcrumbs = []): Response |
|
|
|
|
93
|
|
|
{ |
94
|
|
|
$parameters['breadcrumbs'] = array_merge($this->getIndexBreadcrumbs(), $breadcrumbs); |
95
|
|
|
|
96
|
|
|
return parent::render($view, $parameters); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.