1 | <?php |
||
35 | final class DefaultControllerHelper implements ControllerHelperInterface |
||
36 | { |
||
37 | |||
38 | /** |
||
39 | * @var EntityManagerInterface |
||
40 | */ |
||
41 | private $entityManager; |
||
42 | |||
43 | /** |
||
44 | * @var Twig_Environment |
||
45 | */ |
||
46 | private $twig; |
||
47 | |||
48 | /** |
||
49 | * @var AuthorizationCheckerInterface |
||
50 | */ |
||
51 | private $authorization; |
||
52 | |||
53 | /** |
||
54 | * @var UrlGeneratorInterface |
||
55 | */ |
||
56 | private $urlGenerator; |
||
57 | |||
58 | /** |
||
59 | * @var Session |
||
60 | */ |
||
61 | private $session; |
||
62 | |||
63 | /** |
||
64 | * @var LoggerInterface |
||
65 | */ |
||
66 | private $logger; |
||
67 | |||
68 | /** |
||
69 | * @var EventDispatcherInterface |
||
70 | */ |
||
71 | private $eventDispatcher; |
||
72 | |||
73 | /** |
||
74 | * @var RequestStack |
||
75 | */ |
||
76 | private $requestStack; |
||
77 | |||
78 | 15 | public function __construct( |
|
97 | |||
98 | 1 | public function renderTemplate(string $templatePath, array $arguments = array()): Response |
|
99 | { |
||
100 | 1 | return new Response($this->twig->render($templatePath, $arguments)); |
|
101 | } |
||
102 | |||
103 | 1 | public function findEntity(string $entityClass, string $id) |
|
104 | { |
||
105 | 1 | return $this->entityManager->find($entityClass, $id); |
|
106 | } |
||
107 | |||
108 | 1 | public function findEntities(string $entityClass, array $criteria): array |
|
109 | { |
||
110 | /** @var ObjectRepository $repository */ |
||
111 | 1 | $repository = $this->entityManager->getRepository($entityClass); |
|
112 | |||
113 | 1 | return $repository->findBy($criteria); |
|
114 | } |
||
115 | |||
116 | 1 | public function persistEntity($entity): void |
|
120 | |||
121 | 1 | public function removeEntity($entity): void |
|
125 | |||
126 | 1 | public function flushORM(): void |
|
130 | |||
131 | 1 | public function handleException(Throwable $exception): void |
|
135 | |||
136 | 1 | public function addFlashMessage(string $message, string $type = "default"): void |
|
140 | |||
141 | 2 | public function redirectToRoute(string $route, array $parameters = array(), int $status = 301): Response |
|
148 | |||
149 | 1 | public function getRequestStack(): RequestStack |
|
150 | { |
||
151 | 1 | return $this->requestStack; |
|
153 | |||
154 | 1 | public function getCurrentRequest(): ?Request |
|
158 | |||
159 | 2 | public function denyAccessUnlessGranted(string $attribute, $subject): void |
|
160 | { |
||
161 | 2 | if (!$this->authorization->isGranted($attribute, $subject)) { |
|
162 | 1 | $exception = new AccessDeniedException('Access Denied.'); |
|
163 | 1 | $exception->setSubject($subject); |
|
164 | 1 | $exception->setAttributes($attribute); |
|
165 | |||
166 | 1 | throw $exception; |
|
167 | } |
||
168 | 1 | } |
|
169 | |||
170 | 1 | public function dispatchEvent(string $eventName, Event $event = null): Event |
|
174 | |||
175 | } |
||
176 |