Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12741087
AMQPEventListener.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
AMQPEventListener.php
View Options
<?php
namespace
Nasqueron\Notifications\Listeners
;
use
Nasqueron\Notifications\Events\GitHubPayloadEvent
;
use
Nasqueron\Notifications\Analyzers\GitHubPayloadAnalyzer
;
use
Nasqueron\Notifications\Jobs\SendMessageToBroker
;
use
Illuminate\Queue\InteractsWithQueue
;
use
Illuminate\Contracts\Queue\ShouldQueue
;
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
getRoutingKey
(
GitHubPayloadEvent
$event
)
{
$key
=
[
strtolower
(
$event
->
door
),
self
::
getGroup
(
$event
),
$event
->
event
];
return
implode
(
'.'
,
$key
);
}
protected
static
function
getAnalyzer
(
GitHubPayloadEvent
$event
)
{
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
)
{
$analyzer
=
self
::
getAnalyzer
(
$event
);
return
$analyzer
->
getGroup
();
}
/**
* Handles a GitHub payload event.
*
* @param GitHubPayloadEvent $event
* @return void
*/
public
function
onGitHubPayload
(
GitHubPayloadEvent
$event
)
{
$message
=
json_encode
(
$event
->
payload
);
$routingKey
=
static
::
getRoutingKey
(
$event
);
echo
"Event $event->event has been fired to GitHub $event->door door.
\n
Routing key is $routingKey."
;
$job
=
new
SendMessageToBroker
(
$routingKey
,
$message
);
$job
->
handle
();
}
///
/// Events listening
///
/**
* Register the listeners for the subscriber.
*
* @param Illuminate\Events\Dispatcher $events
*/
public
function
subscribe
(
$events
)
{
$class
=
'Nasqueron
\N
otifications
\L
isteners
\A
MQPEventListener'
;
$events
->
listen
(
'Nasqueron
\N
otifications
\E
vents
\G
itHubPayloadEvent'
,
"$class@onGitHubPayload"
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 16, 13:17 (1 d, 22 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3133166
Default Alt Text
AMQPEventListener.php (2 KB)
Attached To
Mode
rNOTIF Notifications center
Attached
Detach File
Event Timeline
Log In to Comment