@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | private readonly ResponseFactoryInterface $responseFactory, |
| 26 | 26 | private readonly StreamFactoryInterface $streamFactory, |
| 27 | 27 | private readonly FilesInterface $files |
| 28 | - ) { |
|
| 28 | + ){ |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | public function create(int $code): ResponseInterface |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @throws ResponseException |
| 40 | 40 | */ |
| 41 | 41 | public function redirect( |
| 42 | - string|UriInterface $uri, |
|
| 42 | + string | UriInterface $uri, |
|
| 43 | 43 | int $code = 302 |
| 44 | 44 | ): ResponseInterface { |
| 45 | 45 | return $this->responseFactory->createResponse($code)->withHeader('Location', (string)$uri); |
@@ -67,8 +67,8 @@ discard block |
||
| 67 | 67 | string $name = '', |
| 68 | 68 | string $mime = 'application/octet-stream' |
| 69 | 69 | ): ResponseInterface { |
| 70 | - if (empty($name)) { |
|
| 71 | - if (!\is_string($filename)) { |
|
| 70 | + if (empty($name)){ |
|
| 71 | + if (!\is_string($filename)){ |
|
| 72 | 72 | throw new ResponseException('Unable to resolve public filename'); |
| 73 | 73 | } |
| 74 | 74 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | $response = $response->withHeader('Content-Length', (string)$stream->getSize()); |
| 83 | 83 | $response = $response->withHeader( |
| 84 | 84 | 'Content-Disposition', |
| 85 | - 'attachment; filename="' . \addcslashes($name, '"') . '"' |
|
| 85 | + 'attachment; filename="'.\addcslashes($name, '"').'"' |
|
| 86 | 86 | ); |
| 87 | 87 | |
| 88 | 88 | return $response->withBody($stream); |
@@ -67,8 +67,10 @@ |
||
| 67 | 67 | string $name = '', |
| 68 | 68 | string $mime = 'application/octet-stream' |
| 69 | 69 | ): ResponseInterface { |
| 70 | - if (empty($name)) { |
|
| 71 | - if (!\is_string($filename)) { |
|
| 70 | + if (empty($name)) |
|
| 71 | + { |
|
| 72 | + if (!\is_string($filename)) |
|
| 73 | + { |
|
| 72 | 74 | throw new ResponseException('Unable to resolve public filename'); |
| 73 | 75 | } |
| 74 | 76 | |
@@ -15,14 +15,14 @@ discard block |
||
| 15 | 15 | { |
| 16 | 16 | public function __construct( |
| 17 | 17 | private readonly ViewsInterface $views |
| 18 | - ) { |
|
| 18 | + ){ |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public function render(MessageInterface $message): Email |
| 22 | 22 | { |
| 23 | - try { |
|
| 23 | + try{ |
|
| 24 | 24 | $view = $this->views->get($message->getSubject()); |
| 25 | - } catch (ViewException $e) { |
|
| 25 | + }catch (ViewException $e){ |
|
| 26 | 26 | throw new MailerException( |
| 27 | 27 | \sprintf('Invalid email template `%s`: %s', $message->getSubject(), $e->getMessage()), |
| 28 | 28 | $e->getCode(), |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | $msg = new Email(); |
| 34 | 34 | |
| 35 | - if ($message->getFrom() !== null) { |
|
| 35 | + if ($message->getFrom() !== null){ |
|
| 36 | 36 | $msg->from($message->getFrom()); |
| 37 | 37 | } |
| 38 | 38 | |
@@ -40,10 +40,10 @@ discard block |
||
| 40 | 40 | $msg->cc(...$message->getCC()); |
| 41 | 41 | $msg->bcc(...$message->getBCC()); |
| 42 | 42 | |
| 43 | - try { |
|
| 43 | + try{ |
|
| 44 | 44 | // render message partials |
| 45 | 45 | $view->render(\array_merge(['_msg_' => $msg], $message->getData())); |
| 46 | - } catch (ViewException $e) { |
|
| 46 | + }catch (ViewException $e){ |
|
| 47 | 47 | throw new MailerException( |
| 48 | 48 | \sprintf('Unable to render email `%s`: %s', $message->getSubject(), $e->getMessage()), |
| 49 | 49 | $e->getCode(), |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | public static function escapeSubject(string $subject): string |
| 65 | 65 | { |
| 66 | - if (!preg_match('/[^\x20-\x7e]/', $subject)) { |
|
| 66 | + if (!preg_match('/[^\x20-\x7e]/', $subject)){ |
|
| 67 | 67 | // ascii-only subject, return as-is |
| 68 | 68 | return $subject; |
| 69 | 69 | } |
@@ -73,6 +73,6 @@ discard block |
||
| 73 | 73 | $prefix = '=?UTF-8?B?'; |
| 74 | 74 | $suffix = '?='; |
| 75 | 75 | |
| 76 | - return $prefix . \str_replace("=\r\n", $suffix . "\r\n " . $prefix, $encoded) . $suffix; |
|
| 76 | + return $prefix.\str_replace("=\r\n", $suffix."\r\n ".$prefix, $encoded).$suffix; |
|
| 77 | 77 | } |
| 78 | 78 | } |
@@ -20,9 +20,12 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | public function render(MessageInterface $message): Email |
| 22 | 22 | { |
| 23 | - try { |
|
| 23 | + try |
|
| 24 | + { |
|
| 24 | 25 | $view = $this->views->get($message->getSubject()); |
| 25 | - } catch (ViewException $e) { |
|
| 26 | + } |
|
| 27 | + catch (ViewException $e) |
|
| 28 | + { |
|
| 26 | 29 | throw new MailerException( |
| 27 | 30 | \sprintf('Invalid email template `%s`: %s', $message->getSubject(), $e->getMessage()), |
| 28 | 31 | $e->getCode(), |
@@ -32,7 +35,8 @@ discard block |
||
| 32 | 35 | |
| 33 | 36 | $msg = new Email(); |
| 34 | 37 | |
| 35 | - if ($message->getFrom() !== null) { |
|
| 38 | + if ($message->getFrom() !== null) |
|
| 39 | + { |
|
| 36 | 40 | $msg->from($message->getFrom()); |
| 37 | 41 | } |
| 38 | 42 | |
@@ -40,10 +44,13 @@ discard block |
||
| 40 | 44 | $msg->cc(...$message->getCC()); |
| 41 | 45 | $msg->bcc(...$message->getBCC()); |
| 42 | 46 | |
| 43 | - try { |
|
| 47 | + try |
|
| 48 | + { |
|
| 44 | 49 | // render message partials |
| 45 | 50 | $view->render(\array_merge(['_msg_' => $msg], $message->getData())); |
| 46 | - } catch (ViewException $e) { |
|
| 51 | + } |
|
| 52 | + catch (ViewException $e) |
|
| 53 | + { |
|
| 47 | 54 | throw new MailerException( |
| 48 | 55 | \sprintf('Unable to render email `%s`: %s', $message->getSubject(), $e->getMessage()), |
| 49 | 56 | $e->getCode(), |
@@ -63,7 +70,8 @@ discard block |
||
| 63 | 70 | */ |
| 64 | 71 | public static function escapeSubject(string $subject): string |
| 65 | 72 | { |
| 66 | - if (!preg_match('/[^\x20-\x7e]/', $subject)) { |
|
| 73 | + if (!preg_match('/[^\x20-\x7e]/', $subject)) |
|
| 74 | + { |
|
| 67 | 75 | // ascii-only subject, return as-is |
| 68 | 76 | return $subject; |
| 69 | 77 | } |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | 'queue' => null, |
| 18 | 18 | 'queueConnection' => null, |
| 19 | 19 | ] |
| 20 | - ) { |
|
| 20 | + ){ |
|
| 21 | 21 | parent::__construct($config); |
| 22 | 22 | } |
| 23 | 23 | |
@@ -17,14 +17,14 @@ |
||
| 17 | 17 | public function __construct( |
| 18 | 18 | private readonly MailerConfig $config, |
| 19 | 19 | private readonly QueueInterface $queue |
| 20 | - ) { |
|
| 20 | + ){ |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | public function send(MessageInterface ...$message): void |
| 24 | 24 | { |
| 25 | 25 | $options = Options::onQueue($this->config->getQueue()); |
| 26 | 26 | |
| 27 | - foreach ($message as $msg) { |
|
| 27 | + foreach ($message as $msg){ |
|
| 28 | 28 | $this->queue->push( |
| 29 | 29 | self::JOB_NAME, |
| 30 | 30 | MessageSerializer::pack($msg), |
@@ -24,7 +24,8 @@ |
||
| 24 | 24 | { |
| 25 | 25 | $options = Options::onQueue($this->config->getQueue()); |
| 26 | 26 | |
| 27 | - foreach ($message as $msg) { |
|
| 27 | + foreach ($message as $msg) |
|
| 28 | + { |
|
| 28 | 29 | $this->queue->push( |
| 29 | 30 | self::JOB_NAME, |
| 30 | 31 | MessageSerializer::pack($msg), |
@@ -10,6 +10,6 @@ |
||
| 10 | 10 | { |
| 11 | 11 | public function __construct( |
| 12 | 12 | public readonly Email $message |
| 13 | - ) { |
|
| 13 | + ){ |
|
| 14 | 14 | } |
| 15 | 15 | } |
@@ -11,6 +11,6 @@ |
||
| 11 | 11 | public function __construct( |
| 12 | 12 | public readonly Email $message, |
| 13 | 13 | public readonly \Throwable $exception |
| 14 | - ) { |
|
| 14 | + ){ |
|
| 15 | 15 | } |
| 16 | 16 | } |
@@ -32,11 +32,13 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public function handle(string $name, string $id, string|array $payload): void |
| 34 | 34 | { |
| 35 | - if (\is_string($payload)) { |
|
| 35 | + if (\is_string($payload)) |
|
| 36 | + { |
|
| 36 | 37 | $payload = \json_decode($payload, true, 512, JSON_THROW_ON_ERROR); |
| 37 | 38 | } |
| 38 | 39 | |
| 39 | - if (!\is_array($payload)) { |
|
| 40 | + if (!\is_array($payload)) |
|
| 41 | + { |
|
| 40 | 42 | throw new InvalidArgumentException('Mail job payload should be an array.'); |
| 41 | 43 | } |
| 42 | 44 | |
@@ -44,13 +46,17 @@ discard block |
||
| 44 | 46 | |
| 45 | 47 | $email = $this->renderer->render($message); |
| 46 | 48 | |
| 47 | - if ($email->getFrom() === []) { |
|
| 49 | + if ($email->getFrom() === []) |
|
| 50 | + { |
|
| 48 | 51 | $email->from(Address::create($this->config->getFromAddress())); |
| 49 | 52 | } |
| 50 | 53 | |
| 51 | - try { |
|
| 54 | + try |
|
| 55 | + { |
|
| 52 | 56 | $this->mailer->send($email); |
| 53 | - } catch (TransportExceptionInterface $e) { |
|
| 57 | + } |
|
| 58 | + catch (TransportExceptionInterface $e) |
|
| 59 | + { |
|
| 54 | 60 | $this->dispatcher?->dispatch(new MessageNotSent($email, $e)); |
| 55 | 61 | |
| 56 | 62 | throw $e; |
@@ -21,20 +21,20 @@ discard block |
||
| 21 | 21 | private readonly SymfonyMailer $mailer, |
| 22 | 22 | private readonly RendererInterface $renderer, |
| 23 | 23 | private readonly ?EventDispatcherInterface $dispatcher = null |
| 24 | - ) { |
|
| 24 | + ){ |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * @throws TransportExceptionInterface |
| 29 | 29 | * @throws InvalidArgumentException |
| 30 | 30 | */ |
| 31 | - public function handle(string $name, string $id, string|array $payload): void |
|
| 31 | + public function handle(string $name, string $id, string | array $payload): void |
|
| 32 | 32 | { |
| 33 | - if (\is_string($payload)) { |
|
| 33 | + if (\is_string($payload)){ |
|
| 34 | 34 | $payload = \json_decode($payload, true, 512, JSON_THROW_ON_ERROR); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - if (!\is_array($payload)) { |
|
| 37 | + if (!\is_array($payload)){ |
|
| 38 | 38 | throw new InvalidArgumentException('Mail job payload should be an array.'); |
| 39 | 39 | } |
| 40 | 40 | |
@@ -42,13 +42,13 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | $email = $this->renderer->render($message); |
| 44 | 44 | |
| 45 | - if ($email->getFrom() === []) { |
|
| 45 | + if ($email->getFrom() === []){ |
|
| 46 | 46 | $email->from(Address::create($this->config->getFromAddress())); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - try { |
|
| 49 | + try{ |
|
| 50 | 50 | $this->mailer->send($email); |
| 51 | - } catch (TransportExceptionInterface $e) { |
|
| 51 | + }catch (TransportExceptionInterface $e){ |
|
| 52 | 52 | $this->dispatcher?->dispatch(new MessageNotSent($email, $e)); |
| 53 | 53 | |
| 54 | 54 | throw $e; |
@@ -25,6 +25,6 @@ |
||
| 25 | 25 | |
| 26 | 26 | public function init(ViewsBootloader $views): void |
| 27 | 27 | { |
| 28 | - $views->addDirectory('sendit', __DIR__ . '/../../views'); |
|
| 28 | + $views->addDirectory('sendit', __DIR__.'/../../views'); |
|
| 29 | 29 | } |
| 30 | 30 | } |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | { |
| 15 | 15 | public function __construct( |
| 16 | 16 | private readonly LoggerInterface $logger |
| 17 | - ) { |
|
| 17 | + ){ |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | public function onMessageSent(MessageSent $event): void |