Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F22589751
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
Illuminate\Queue\InteractsWithQueue
;
use
Illuminate\Contracts\Queue\ShouldQueue
;
use
Keruald\Broker\AMQPBroker
;
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."
;
$broker
=
new
AMQPBroker
();
$broker
->
connect
()
->
setExchangeTarget
(
'github_events'
)
->
routeTo
(
$routingKey
)
->
sendMessage
(
$message
);
}
///
/// 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
Sat, Jan 31, 17:43 (22 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3403927
Default Alt Text
AMQPEventListener.php (2 KB)
Attached To
Mode
rNOTIF Notifications center
Attached
Detach File
Event Timeline
Log In to Comment