Skip to content

Commit a10e98a

Browse files
committed
wrap event_dispatcher in private method
1 parent d410477 commit a10e98a

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

Controller/TicketController.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Hackzilla\Bundle\TicketBundle\Event\TicketEvent;
66
use Hackzilla\Bundle\TicketBundle\Form\Type\TicketMessageType;
77
use Hackzilla\Bundle\TicketBundle\Form\Type\TicketType;
8+
use Hackzilla\Bundle\TicketBundle\Model\TicketInterface;
89
use Hackzilla\Bundle\TicketBundle\Model\TicketMessageInterface;
910
use Hackzilla\Bundle\TicketBundle\TicketEvents;
1011
use Hackzilla\Bundle\TicketBundle\TicketRole;
@@ -75,7 +76,7 @@ public function createAction(Request $request)
7576
->setUser($this->getUserManager()->getCurrentUser());
7677

7778
$ticketManager->updateTicket($ticket, $message);
78-
$this->get('event_dispatcher')->dispatch(TicketEvents::TICKET_CREATE, new TicketEvent($ticket));
79+
$this->dispatchTicketEvent(TicketEvents::TICKET_CREATE, $ticket);
7980

8081
return $this->redirect($this->generateUrl('hackzilla_ticket_show', ['ticketId' => $ticket->getId()]));
8182
}
@@ -174,8 +175,7 @@ public function replyAction(Request $request, $ticketId)
174175
if ($form->isValid()) {
175176
$message->setUser($user);
176177
$ticketManager->updateTicket($ticket, $message);
177-
178-
$this->get('event_dispatcher')->dispatch(TicketEvents::TICKET_UPDATE, new TicketEvent($ticket));
178+
$this->dispatchTicketEvent(TicketEvents::TICKET_UPDATE, $ticket);
179179

180180
return $this->redirect($this->generateUrl('hackzilla_ticket_show', ['ticketId' => $ticket->getId()]));
181181
}
@@ -224,14 +224,19 @@ public function deleteAction(Request $request, $ticketId)
224224
}
225225

226226
$ticketManager->deleteTicket($ticket);
227-
$event = new TicketEvent($ticket);
228-
$this->get('event_dispatcher')->dispatch(TicketEvents::TICKET_DELETE, $event);
227+
$this->dispatchTicketEvent(TicketEvents::TICKET_DELETE, $ticket);
229228
}
230229
}
231230

232231
return $this->redirect($this->generateUrl('hackzilla_ticket'));
233232
}
234233

234+
private function dispatchTicketEvent($ticketEvent, TicketInterface $ticket)
235+
{
236+
$event = new TicketEvent($ticket);
237+
$this->get('event_dispatcher')->dispatch($ticketEvent, $event);
238+
}
239+
235240
/**
236241
* Creates a form to delete a Ticket entity by id.
237242
*

0 commit comments

Comments
 (0)