public function customSender($customMethod, $notification)
{
if (array_key_exists($customMethod, $this->senders)) {
// get the extended method
$extendedSender = $this->senders[$customMethod];
// If is a closure means that i'll return an instance
// with the
if ($extendedSender instanceof Closure) {
// I invoke the closure expecting an Instance of a custom
// Sender
$invoker = call_user_func_array($extendedSender, [$notification, $this->container]);
// If the invoker is a custom sender
// then I invoke it passing the sender class
if ($invoker instanceof Sender) {
return $invoker->send($this);
}
// If the dev is attempting to create a custom
// way of storing notifications then
// i'll pass the store notification contract
if ($invoker instanceof DefaultSender) {
return $invoker->send($this->storeNotification);
}
}
$error = 'The extension must be an instance of Closure';
throw new LogicException($error);
}
$error = "The method {$customMethod} does not exists on the class " . get_class($this);
throw new BadMethodCallException($error);
}