Skip to content

Instantly share code, notes, and snippets.

@koyablue
Last active January 29, 2021 09:39
Show Gist options
  • Save koyablue/2827cf75afe3b75752b8cac027728e34 to your computer and use it in GitHub Desktop.
Save koyablue/2827cf75afe3b75752b8cac027728e34 to your computer and use it in GitHub Desktop.
<?php
interface NotificationServiceInterface
{
public function send(int $notificationCode);
}
class UserNotificationService implements NotificationServiceInterface
{
//略
public function send(int $notificationCode)
{
if (is_null($notificationCode)) {
NormalUserNotification::notify();
return;
}
foreach ($this->notifications as $notification) {
if ($notification::code() === $notificationCode) {
if ((new $notification) instanceof NotificationToAdminInterface) {
$this->sendToAdmin();
}
$notification::notify();
return;
}
}
throw new InvalidArgumentException();
}
private function sendToAdmin()
{
//logic
}
}
interface NotificationInterface
{
public static function code() : int;
public static function notify();
}
interface NotificationToAdminInterface
{
//空のInterface
}
//略
class TypeBUserNotification implements NotificationToAdminInterface, NotificationInterface
{
public static function code() : int
{
return config('notification.type.b.value');
}
public static function notify()
{
//logic
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment