Skip to content

Commit 8e2a323

Browse files
committed
Minor tweaks
1 parent e26780b commit 8e2a323

File tree

2 files changed

+3
-17
lines changed

2 files changed

+3
-17
lines changed

src/Controller/BlogController.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,12 @@ public function commentNew(Request $request, Post $post, EventDispatcherInterfac
103103
$em->persist($comment);
104104
$em->flush();
105105

106-
// When triggering an event, you can optionally pass some information.
107-
// For simple applications, use the GenericEvent object provided by Symfony
108-
// to pass some PHP variables. For more complex applications, define your
109-
// own event object classes.
110-
// See https://symfony.com/doc/current/components/event_dispatcher/generic_event.html
111-
112-
// Since Symfony 4.3, it is better to use event object to make the calls to dispatch lighter
113-
// https://symfony.com/blog/new-in-symfony-4-3-simpler-event-dispatching
114-
$event = new CommentCreatedEvent($comment);
115-
116106
// When an event is dispatched, Symfony notifies it to all the listeners
117107
// and subscribers registered to it. Listeners can modify the information
118108
// passed in the event and they can even modify the execution flow, so
119109
// there's no guarantee that the rest of this controller will be executed.
120110
// See https://symfony.com/doc/current/components/event_dispatcher.html
121-
$eventDispatcher->dispatch($event);
111+
$eventDispatcher->dispatch(new CommentCreatedEvent($comment));
122112

123113
return $this->redirectToRoute('blog_post', ['slug' => $post->getSlug()]);
124114
}

src/Events/CommentCreatedEvent.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
use App\Entity\Comment;
1515
use Symfony\Contracts\EventDispatcher\Event;
1616

17-
/**
18-
* The comment.created event is dispatched each time a comment is created
19-
* in the system.
20-
*/
2117
class CommentCreatedEvent extends Event
2218
{
2319
protected $comment;
@@ -27,8 +23,8 @@ public function __construct(Comment $comment)
2723
$this->comment = $comment;
2824
}
2925

30-
public function getComment()
26+
public function getComment(): Comment
3127
{
3228
return $this->comment;
3329
}
34-
}
30+
}

0 commit comments

Comments
 (0)