Page MenuHomeDevCentral

D808.id2049.diff
No OneTemporary

D808.id2049.diff

diff --git a/app/Listeners/AMQPEventListener.php b/app/Listeners/AMQPEventListener.php
--- a/app/Listeners/AMQPEventListener.php
+++ b/app/Listeners/AMQPEventListener.php
@@ -2,73 +2,15 @@
namespace Nasqueron\Notifications\Listeners;
-use Nasqueron\Notifications\Events\GitHubPayloadEvent;
use Nasqueron\Notifications\Events\NotificationEvent;
-use Nasqueron\Notifications\Analyzers\GitHub\GitHubPayloadAnalyzer;
use Nasqueron\Notifications\Jobs\SendMessageToBroker;
use Nasqueron\Notifications\Notifications\Notification;
+use Illuminate\Events\Dispatcher;
+
use Config;
class AMQPEventListener {
- ///
- /// GitHub events
- ///
-
- /**
- * Gets routing key, to allow consumers to select the topic they subscribe to.
- *
- * @param GitHubPayloadEvent $event the payload event
- */
- protected static function getGitHubEventRoutingKey (GitHubPayloadEvent $event) : string {
- $key = [
- strtolower($event->door),
- self::getGroup($event),
- $event->event
- ];
- return implode('.', $key);
- }
-
- protected static function getAnalyzer (GitHubPayloadEvent $event) : GitHubPayloadAnalyzer {
- return new GitHubPayloadAnalyzer(
- $event->door,
- $event->event,
- $event->payload
- );
- }
-
- /**
- * Gets the group for a specific payload
- *
- * @return string the group, central part of the routing key
- */
- protected static function getGroup (GitHubPayloadEvent $event) : string {
- $analyzer = self::getAnalyzer($event);
- return $analyzer->getGroup();
- }
-
- /**
- * Handles a GitHub payload event.
- *
- * @param GitHubPayloadEvent $event
- */
- public function onGitHubPayload(GitHubPayloadEvent $event) : void {
- $this->sendRawPayload($event);
- }
-
- /**
- * This is our gateway GitHub Webhooks -> Broker
- *
- * @param GitHubPayloadEvent $event
- */
- protected function sendRawPayload(GitHubPayloadEvent $event) : void {
- $target = Config::get('broker.targets.github_events');
- $routingKey = static::getGitHubEventRoutingKey($event);
- $message = json_encode($event->payload);
-
- $job = new SendMessageToBroker($target, $routingKey, $message);
- $job->handle();
- }
///
/// Notifications
@@ -80,7 +22,7 @@
* @param NotificationEvent $event
*/
public function onNotification(NotificationEvent $event) : void {
- $this->sendNotification($event);
+ $this->sendNotification($event->notification);
}
/**
@@ -93,7 +35,7 @@
$notification->project,
$notification->group,
$notification->service,
- $notification->type
+ $notification->type,
];
return strtolower(implode('.', $key));
@@ -102,11 +44,9 @@
/**
* This is our gateway specialized for distilled notifications
*
- * @param NotificationEvent $event
+ * @param Notification The notification to send
*/
- protected function sendNotification(NotificationEvent $event) : void {
- $notification = $event->notification;
-
+ protected function sendNotification(Notification $notification) : void {
$target = Config::get('broker.targets.notifications');
$routingKey = static::getNotificationRoutingKey($notification);
$message = json_encode($notification);
@@ -122,17 +62,11 @@
/**
* Register the listeners for the subscriber.
*
- * @param \Illuminate\Events\Dispatcher $events
+ * @param Dispatcher $events
*/
- public function subscribe (\Illuminate\Events\Dispatcher $events) : void {
- $class = 'Nasqueron\Notifications\Listeners\AMQPEventListener';
- $events->listen(
- 'Nasqueron\Notifications\Events\GitHubPayloadEvent',
- "$class@onGitHubPayload"
- );
- $events->listen(
- 'Nasqueron\Notifications\Events\NotificationEvent',
- "$class@onNotification"
- );
+ public function subscribe (Dispatcher $events) : void {
+ $class = AMQPEventListener::class;
+ $events->listen(NotificationEvent::class, "$class@onNotification");
}
+
}

File Metadata

Mime Type
text/plain
Expires
Fri, Jan 31, 13:30 (10 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2387974
Default Alt Text
D808.id2049.diff (4 KB)

Event Timeline