Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F27327028
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
Illuminate\Events\Dispatcher
;
use
Config
;
class
AMQPEventListener
{
///
/// Notifications
///
/**
* Handles a notification event.
*
* @param NotificationEvent $event
*/
public
function
onNotification
(
NotificationEvent
$event
)
:
void
{
$this
->
sendNotification
(
$event
->
notification
);
}
/**
* Gets routing key, to allow consumers to select the topic they subscribe to.
*
* @param Notification The $notification from where the keys must be extracted
*/
protected
static
function
getNotificationRoutingKey
(
Notification
$notification
)
:
string
{
$keyParts
=
[
$notification
->
project
,
$notification
->
group
,
$notification
->
service
,
$notification
->
type
,
];
return
strtolower
(
implode
(
'.'
,
$keyParts
));
}
/**
* Sends the notification to the broker target for distilled notifications.
*
* @param Notification The notification to send
*/
protected
function
sendNotification
(
Notification
$notification
)
:
void
{
$target
=
Config
::
get
(
'broker.targets.notifications'
);
$routingKey
=
static
::
getNotificationRoutingKey
(
$notification
);
$message
=
json_encode
(
$notification
);
$job
=
new
SendMessageToBroker
(
$target
,
$routingKey
,
$message
);
$job
->
handle
();
}
///
/// Events listening
///
/**
* Registers the listeners for the subscriber.
*
* @param Dispatcher $events
*/
public
function
subscribe
(
Dispatcher
$events
)
:
void
{
$class
=
AMQPEventListener
::
class
;
$events
->
listen
(
NotificationEvent
::
class
,
"$class@onNotification"
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, May 5, 11:47 (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3666857
Default Alt Text
AMQPEventListener.php (1 KB)
Attached To
Mode
rNOTIF Notifications center
Attached
Detach File
Event Timeline
Log In to Comment