1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright 2014-2016 Arnaud Bienvenu |
4
|
|
|
* |
5
|
|
|
* This file is part of Kyela. |
6
|
|
|
|
7
|
|
|
* Kyela is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU Affero General Public License as published by |
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
|
12
|
|
|
* Kyela is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
18
|
|
|
* along with Kyela. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace Abienvenu\KyelaBundle\Controller; |
23
|
|
|
|
24
|
|
|
use Symfony\Component\HttpFoundation\Request; |
25
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
26
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
27
|
|
|
use Abienvenu\KyelaBundle\Entity\Event; |
28
|
|
|
use Abienvenu\KyelaBundle\Form\Type\EventType; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Event controller. |
32
|
|
|
* |
33
|
|
|
* @Route("/{pollUrl}/event") |
34
|
|
|
*/ |
35
|
|
|
class EventController extends CRUDController |
36
|
|
|
{ |
37
|
|
|
protected $entityName = 'KyelaBundle:Event'; |
38
|
|
|
protected $cancelRoute = 'poll_show'; |
39
|
|
|
protected $successRoute = 'poll_show'; |
40
|
|
|
protected $deleteRoute = 'event_delete'; |
41
|
|
|
protected $deleteSuccessRoute = 'poll_show'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Displays poll events |
45
|
|
|
* |
46
|
|
|
* @Route("", methods="GET") |
47
|
|
|
* @Template() |
48
|
|
|
*/ |
49
|
|
|
public function showAction($isFuture) |
50
|
|
|
{ |
51
|
|
|
$em = $this->getDoctrine()->getManager(); |
52
|
|
|
$events = $em->getRepository('KyelaBundle:Event')->getFutureOrPastEvents($this->poll, $isFuture); |
|
|
|
|
53
|
|
|
return [ |
54
|
|
|
'poll' => $this->poll, |
55
|
|
|
'events' => $events, |
56
|
|
|
]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Displays a form to create a new Event entity. |
61
|
|
|
* |
62
|
|
|
* @Route("/new", name="event_new", methods={"GET", "POST"}) |
63
|
|
|
* @Template() |
64
|
|
|
*/ |
65
|
|
|
public function newAction(Request $request) |
66
|
|
|
{ |
67
|
|
|
return $this->doNewAction(EventType::class, new Event(), $request); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Displays a form to edit an existing Event entity. |
72
|
|
|
* |
73
|
|
|
* @Route("/{id}/edit", name="event_edit", methods={"GET", "PUT"}) |
74
|
|
|
* @Template() |
75
|
|
|
*/ |
76
|
|
|
public function editAction(Request $request, $id) |
77
|
|
|
{ |
78
|
|
|
return $this->doEditAction(EventType::class, $id, $request); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Deletes a Event entity. |
83
|
|
|
* |
84
|
|
|
* @Route("/{id}", name="event_delete", methods="DELETE") |
85
|
|
|
*/ |
86
|
|
|
public function deleteAction(Request $request, $id) |
87
|
|
|
{ |
88
|
|
|
return $this->doDeleteAction($request, $id); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: