Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F11722342
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/app/Jobs/FireGitHubNotification.php b/app/Jobs/FireGitHubNotification.php
new file mode 100644
index 0000000..6ad8b49
--- /dev/null
+++ b/app/Jobs/FireGitHubNotification.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace Nasqueron\Notifications\Jobs;
+
+use Illuminate\Contracts\Bus\SelfHandling;
+use Nasqueron\Notifications\Notifications\GitHubNotification;
+use Nasqueron\Notifications\Events\GitHubPayloadEvent;
+use Nasqueron\Notifications\Events\NotificationEvent;
+use Nasqueron\Notifications\Jobs\Job;
+
+use Event;
+
+class FireGitHubNotification extends Job implements SelfHandling {
+
+ /**
+ * @var GitHubPayloadEvent;
+ */
+ private $event;
+
+ /**
+ * Initializes a new instance of FireGitHubNotification
+ *
+ * @param GitHubPayloadEvent $event The event to notify
+ */
+ public function __construct (GitHubPayloadEvent $event) {
+ $this->event = $event;
+ }
+
+ ///
+ /// Task
+ ///
+
+ /**
+ * Executes the job.
+ *
+ * @return void
+ */
+ public function handle() {
+ $notification = $this->createNotification();
+ Event::fire(new NotificationEvent($notification));
+ }
+
+ /**
+ * Creates a GitHub notification
+ *
+ * @param GitHubPayloadEvent $event
+ * @return Notification the notification
+ */
+ protected function createNotification() {
+ return new GitHubNotification(
+ $this->event->door, // project
+ $this->event->event, // event type
+ $this->event->payload // raw content
+ );
+ }
+}
diff --git a/app/Listeners/NotificationListener.php b/app/Listeners/NotificationListener.php
index 66f037b..092082f 100644
--- a/app/Listeners/NotificationListener.php
+++ b/app/Listeners/NotificationListener.php
@@ -1,62 +1,46 @@
<?php
namespace Nasqueron\Notifications\Listeners;
use Nasqueron\Notifications\Events\GitHubPayloadEvent;
use Nasqueron\Notifications\Events\NotificationEvent;
+use Nasqueron\Notifications\Jobs\FireGitHubNotification;
use Nasqueron\Notifications\Notifications\GitHubNotification;
use Event;
class NotificationListener {
///
/// Distill GitHub payloads into notifications
///
/**
* Handles a GitHub payload event.
*
* @param GitHubPayloadEvent $event
* @return void
*/
public function onGitHubPayload(GitHubPayloadEvent $event) {
- $notification = $this->createNotification($event);
- $event = new NotificationEvent($notification);
- Event::fire($event);
- }
-
- /**
- * Creates a GitHub notification
- *
- * @param GitHubPayloadEvent $event
- * @return Notification the notification
- */
- protected function createNotification(GitHubPayloadEvent $event) {
- $notification = new GitHubNotification(
- $event->door, // project
- $event->event, // event type
- $event->payload // raw content
- );
-
- return $notification;
+ $job = new FireGitHubNotification($event);
+ $job->handle();
}
///
/// Events listening
///
/**
* Register the listeners for the subscriber.
*
* @param Illuminate\Events\Dispatcher $events
*/
public function subscribe ($events) {
$class = 'Nasqueron\Notifications\Listeners\NotificationListener';
$events->listen(
'Nasqueron\Notifications\Events\GitHubPayloadEvent',
"$class@onGitHubPayload"
);
}
}
\ No newline at end of file
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Sep 18, 02:07 (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2989807
Default Alt Text
(3 KB)
Attached To
Mode
rNOTIF Notifications center
Attached
Detach File
Event Timeline
Log In to Comment