From d6fe156e8985eeb435055b0800f6bda28798cb23 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Mon, 27 Jul 2015 11:54:44 +0930 Subject: [PATCH] PERF: avoid reinstantiation of event subscribers --- .../subscriptions/src/Listeners/AddApiAttributes.php | 2 +- .../subscriptions/src/Listeners/AddClientAssets.php | 6 +++--- .../src/Listeners/HideIgnoredDiscussions.php | 4 ++-- .../subscriptions/src/Listeners/NotifyNewPosts.php | 10 +++++----- .../src/Listeners/PersistSubscriptionData.php | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/extensions/subscriptions/src/Listeners/AddApiAttributes.php b/extensions/subscriptions/src/Listeners/AddApiAttributes.php index e1dec1972..cd9c18aaf 100755 --- a/extensions/subscriptions/src/Listeners/AddApiAttributes.php +++ b/extensions/subscriptions/src/Listeners/AddApiAttributes.php @@ -8,7 +8,7 @@ class AddApiAttributes { public function subscribe(Dispatcher $events) { - $events->listen(ApiAttributes::class, __CLASS__.'@addAttributes'); + $events->listen(ApiAttributes::class, [$this, 'addAttributes']); } public function addAttributes(ApiAttributes $event) diff --git a/extensions/subscriptions/src/Listeners/AddClientAssets.php b/extensions/subscriptions/src/Listeners/AddClientAssets.php index 6be04ed67..312af47e1 100755 --- a/extensions/subscriptions/src/Listeners/AddClientAssets.php +++ b/extensions/subscriptions/src/Listeners/AddClientAssets.php @@ -9,9 +9,9 @@ class AddClientAssets { public function subscribe(Dispatcher $events) { - $events->listen(RegisterLocales::class, __CLASS__.'@addLocale'); - $events->listen(BuildClientView::class, __CLASS__.'@addAssets'); - $events->listen(RegisterForumRoutes::class, __CLASS__.'@addRoutes'); + $events->listen(RegisterLocales::class, [$this, 'addLocale']); + $events->listen(BuildClientView::class, [$this, 'addAssets']); + $events->listen(RegisterForumRoutes::class, [$this, 'addRoutes']); } public function addLocale(RegisterLocales $event) diff --git a/extensions/subscriptions/src/Listeners/HideIgnoredDiscussions.php b/extensions/subscriptions/src/Listeners/HideIgnoredDiscussions.php index 057af21e1..f95985edf 100755 --- a/extensions/subscriptions/src/Listeners/HideIgnoredDiscussions.php +++ b/extensions/subscriptions/src/Listeners/HideIgnoredDiscussions.php @@ -7,8 +7,8 @@ class HideIgnoredDiscussions { public function subscribe($events) { - $events->listen(RegisterDiscussionGambits::class, __CLASS__.'@addGambit'); - $events->listen(DiscussionSearchWillBePerformed::class, __CLASS__.'@filterIgnored'); + $events->listen(RegisterDiscussionGambits::class, [$this, 'addGambit']); + $events->listen(DiscussionSearchWillBePerformed::class, [$this, 'filterIgnored']); } public function addGambit(RegisterDiscussionGambits $event) diff --git a/extensions/subscriptions/src/Listeners/NotifyNewPosts.php b/extensions/subscriptions/src/Listeners/NotifyNewPosts.php index 16bd1bfe9..999901e3b 100755 --- a/extensions/subscriptions/src/Listeners/NotifyNewPosts.php +++ b/extensions/subscriptions/src/Listeners/NotifyNewPosts.php @@ -20,15 +20,15 @@ class NotifyNewPosts 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 // is updated, as we need to compare the user's last read number to that // of the previous post. - $events->listen(PostWasPosted::class, __CLASS__.'@whenPostWasPosted', 1); - $events->listen(PostWasHidden::class, __CLASS__.'@whenPostWasHidden'); - $events->listen(PostWasRestored::class, __CLASS__.'@whenPostWasRestored'); - $events->listen(PostWasDeleted::class, __CLASS__.'@whenPostWasDeleted'); + $events->listen(PostWasPosted::class, [$this, 'whenPostWasPosted'], 1); + $events->listen(PostWasHidden::class, [$this, 'whenPostWasHidden']); + $events->listen(PostWasRestored::class, [$this, 'whenPostWasRestored']); + $events->listen(PostWasDeleted::class, [$this, 'whenPostWasDeleted']); } public function addNotificationType(RegisterNotificationTypes $event) diff --git a/extensions/subscriptions/src/Listeners/PersistSubscriptionData.php b/extensions/subscriptions/src/Listeners/PersistSubscriptionData.php index a4e8f66f8..69c247017 100755 --- a/extensions/subscriptions/src/Listeners/PersistSubscriptionData.php +++ b/extensions/subscriptions/src/Listeners/PersistSubscriptionData.php @@ -6,7 +6,7 @@ class PersistSubscriptionData { public function subscribe($events) { - $events->listen(DiscussionWillBeSaved::class, __CLASS__.'@whenDiscussionWillBeSaved'); + $events->listen(DiscussionWillBeSaved::class, [$this, 'whenDiscussionWillBeSaved']); } public function whenDiscussionWillBeSaved(DiscussionWillBeSaved $event)