Last active
August 26, 2022 18:34
-
-
Save mikemix/1ef4eee498609436074df9cb349924bb to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
declare(strict_types=1); | |
namespace App\Notification\Implementation; | |
use App\Notification\NotificationInterface; | |
use App\Notification\TransportInterface; | |
/** | |
* {@inheritDoc} | |
* | |
* @template-implements TransportInterface<TransportInterface> | |
*/ | |
final class RepeatableTransportDecorator implements TransportInterface | |
{ | |
private TransportInterface $transport; | |
private int $retryCount; | |
public function __construct(TransportInterface $transport, int $retryCount) | |
{ | |
$this->transport = $transport; | |
$this->retryCount = $retryCount; | |
} | |
public function supports(NotificationInterface $notification): bool | |
{ | |
return $this->transport->supports($notification); | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
public function deliver(NotificationInterface $notification): void | |
{ | |
$tryCounter = 0; | |
do { | |
try { | |
$this->transport->deliver($notification); | |
return; | |
} catch (\Exception $exception) { | |
++$tryCounter; | |
} | |
} while ($tryCounter < $this->retryCount); | |
throw NotificationSendException::duringDelivery($exception); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fix: