Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F10813220
AMQPEventListener.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
AMQPEventListener.php
View Options
<?php
namespace
Nasqueron\Notifications\Listeners
;
use
Nasqueron\Notifications\Events\NotificationEvent
;
use
Nasqueron\Notifications\Jobs\SendMessageToBroker
;
use
Nasqueron\Notifications\Notifications\Notification
;
use
Config
;
class
AMQPEventListener
{
///
/// Notifications
///
/**
* Handles a notification event.
*
* @param NotificationEvent $event
*/
public
function
onNotification
(
NotificationEvent
$event
)
:
void
{
$this
->
sendNotification
(
$event
);
}
/**
* Gets routing key, to allow consumers to select the topic they subscribe to.
*
* @param NotificationEvent $event
*/
protected
static
function
getNotificationRoutingKey
(
Notification
$notification
)
:
string
{
$key
=
[
$notification
->
project
,
$notification
->
group
,
$notification
->
service
,
$notification
->
type
];
return
strtolower
(
implode
(
'.'
,
$key
));
}
/**
* This is our gateway specialized for distilled notifications
*
* @param NotificationEvent $event
*/
protected
function
sendNotification
(
NotificationEvent
$event
)
:
void
{
$notification
=
$event
->
notification
;
$target
=
Config
::
get
(
'broker.targets.notifications'
);
$routingKey
=
static
::
getNotificationRoutingKey
(
$notification
);
$message
=
json_encode
(
$notification
);
$job
=
new
SendMessageToBroker
(
$target
,
$routingKey
,
$message
);
$job
->
handle
();
}
///
/// Events listening
///
/**
* Register the listeners for the subscriber.
*
* @param \Illuminate\Events\Dispatcher $events
*/
public
function
subscribe
(
\Illuminate\Events\Dispatcher
$events
)
:
void
{
$class
=
'Nasqueron
\N
otifications
\L
isteners
\A
MQPEventListener'
;
$events
->
listen
(
'Nasqueron
\N
otifications
\E
vents
\N
otificationEvent'
,
"$class@onNotification"
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Jul 29, 13:49 (2 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2827413
Default Alt Text
AMQPEventListener.php (1 KB)
Attached To
Mode
rNOTIF Notifications center
Attached
Detach File
Event Timeline
Log In to Comment