1 | <?php |
||
35 | class CommentController extends CRUDController |
||
36 | { |
||
37 | protected $entityName = 'KyelaBundle:Comment'; |
||
38 | protected $cancelRoute = 'poll_show'; |
||
39 | protected $successRoute = 'poll_show'; |
||
40 | protected $deleteRoute = 'comment_delete'; |
||
41 | protected $deleteSuccessRoute = 'poll_show'; |
||
42 | |||
43 | /** |
||
44 | * Displays latest comments |
||
45 | * |
||
46 | * @Route("/", methods="GET") |
||
47 | * @Template() |
||
48 | */ |
||
49 | public function showAction() |
||
55 | |||
56 | /** |
||
57 | * Displays a form to create a new Comment entity. |
||
58 | * |
||
59 | * @Route("/new", name="comment_new", methods={"GET", "POST"}) |
||
60 | * @Template() |
||
61 | */ |
||
62 | public function newAction(Request $request) |
||
71 | |||
72 | /** |
||
73 | * Displays a form to edit an existing Comment entity. |
||
74 | * |
||
75 | * @Route("/{id}/edit", name="comment_edit", methods={"GET", "PUT"}) |
||
76 | * @Template() |
||
77 | */ |
||
78 | public function editAction(Request $request, $id) |
||
82 | |||
83 | /** |
||
84 | * Deletes a Comment entity. |
||
85 | * |
||
86 | * @Route("/{id}", name="comment_delete", methods="DELETE") |
||
87 | */ |
||
88 | public function deleteAction(Request $request, $id) |
||
92 | } |
||
93 |
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: