Last active
January 29, 2021 09:39
-
-
Save koyablue/2827cf75afe3b75752b8cac027728e34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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