Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F1836679
HandleMethodExampleForNotificationListener.php
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
dereckson
May 7 2022, 17:22
2022-05-07 17:22:04 (UTC+0)
Size
590 B
Referenced Files
None
Subscribers
None
HandleMethodExampleForNotificationListener.php
View Options
<?php
// NotificationListener: how to call the right on...... method?
use
Nasqueron\Notifications\Events\Event
;
private
static
function
getEventHandlerMethod
(
string
$eventClasss
)
:
string
{
$parts
=
explode
(
'
\\
'
,
$class
);
$className
=
end
(
$parts
);
if
(!
str_ends_with
(
$className
,
"Event"
))
{
throw
new
InvalidArgumentException
(
"Events classes must be ended by 'Event'"
);
}
return
"on"
.
substr
(
$className
,
0
,
16
);
}
public
function
handle
(
Event
$event
)
:
void
{
$callable
=
[
$this
,
self
::
getEventHandlerMethod
(
$event
::
class
)]
$callable
(
$event
);
}
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1030346
Default Alt Text
HandleMethodExampleForNotificationListener.php (590 B)
Attached To
Mode
P307 HandleMethodExampleForNotificationListener.php
Attached
Detach File
Event Timeline
Log In to Comment