1
0
mirror of https://github.com/flarum/core.git synced 2025-08-08 09:26:34 +02:00

PERF: avoid reinstantiation of event subscribers

This commit is contained in:
Toby Zerner
2015-07-27 11:54:44 +09:30
parent 3729a91be3
commit d6fe156e89
5 changed files with 12 additions and 12 deletions

View File

@@ -8,7 +8,7 @@ class AddApiAttributes
{ {
public function subscribe(Dispatcher $events) public function subscribe(Dispatcher $events)
{ {
$events->listen(ApiAttributes::class, __CLASS__.'@addAttributes'); $events->listen(ApiAttributes::class, [$this, 'addAttributes']);
} }
public function addAttributes(ApiAttributes $event) public function addAttributes(ApiAttributes $event)

View File

@@ -9,9 +9,9 @@ class AddClientAssets
{ {
public function subscribe(Dispatcher $events) public function subscribe(Dispatcher $events)
{ {
$events->listen(RegisterLocales::class, __CLASS__.'@addLocale'); $events->listen(RegisterLocales::class, [$this, 'addLocale']);
$events->listen(BuildClientView::class, __CLASS__.'@addAssets'); $events->listen(BuildClientView::class, [$this, 'addAssets']);
$events->listen(RegisterForumRoutes::class, __CLASS__.'@addRoutes'); $events->listen(RegisterForumRoutes::class, [$this, 'addRoutes']);
} }
public function addLocale(RegisterLocales $event) public function addLocale(RegisterLocales $event)

View File

@@ -7,8 +7,8 @@ class HideIgnoredDiscussions
{ {
public function subscribe($events) public function subscribe($events)
{ {
$events->listen(RegisterDiscussionGambits::class, __CLASS__.'@addGambit'); $events->listen(RegisterDiscussionGambits::class, [$this, 'addGambit']);
$events->listen(DiscussionSearchWillBePerformed::class, __CLASS__.'@filterIgnored'); $events->listen(DiscussionSearchWillBePerformed::class, [$this, 'filterIgnored']);
} }
public function addGambit(RegisterDiscussionGambits $event) public function addGambit(RegisterDiscussionGambits $event)

View File

@@ -20,15 +20,15 @@ class NotifyNewPosts
public function subscribe(Dispatcher $events) public function subscribe(Dispatcher $events)
{ {
$events->listen(RegisterNotificationTypes::class, __CLASS__.'@addNotificationType'); $events->listen(RegisterNotificationTypes::class, [$this, 'addNotificationType']);
// Register with '1' as priority so this runs before discussion metadata // Register with '1' as priority so this runs before discussion metadata
// is updated, as we need to compare the user's last read number to that // is updated, as we need to compare the user's last read number to that
// of the previous post. // of the previous post.
$events->listen(PostWasPosted::class, __CLASS__.'@whenPostWasPosted', 1); $events->listen(PostWasPosted::class, [$this, 'whenPostWasPosted'], 1);
$events->listen(PostWasHidden::class, __CLASS__.'@whenPostWasHidden'); $events->listen(PostWasHidden::class, [$this, 'whenPostWasHidden']);
$events->listen(PostWasRestored::class, __CLASS__.'@whenPostWasRestored'); $events->listen(PostWasRestored::class, [$this, 'whenPostWasRestored']);
$events->listen(PostWasDeleted::class, __CLASS__.'@whenPostWasDeleted'); $events->listen(PostWasDeleted::class, [$this, 'whenPostWasDeleted']);
} }
public function addNotificationType(RegisterNotificationTypes $event) public function addNotificationType(RegisterNotificationTypes $event)

View File

@@ -6,7 +6,7 @@ class PersistSubscriptionData
{ {
public function subscribe($events) public function subscribe($events)
{ {
$events->listen(DiscussionWillBeSaved::class, __CLASS__.'@whenDiscussionWillBeSaved'); $events->listen(DiscussionWillBeSaved::class, [$this, 'whenDiscussionWillBeSaved']);
} }
public function whenDiscussionWillBeSaved(DiscussionWillBeSaved $event) public function whenDiscussionWillBeSaved(DiscussionWillBeSaved $event)