Page MenuHomeDevCentral

HandleMethodExampleForNotificationListener.php

Authored By
dereckson
May 7 2022, 17:22
Size
590 B
Referenced Files
None
Subscribers
None

HandleMethodExampleForNotificationListener.php

<?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

Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1030346
Default Alt Text
HandleMethodExampleForNotificationListener.php (590 B)

Event Timeline