MailerFactory.php
4 months ago
MailgunService.php
3 months ago
OutlookMiddlewareService.php
4 months ago
OutlookService.php
6 months ago
PHPMailService.php
6 months ago
SMTPService.php
6 months ago
WpMailService.php
6 months ago
OutlookService.php
81 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @copyright © Melograno Ventures. All rights reserved. |
| 5 | * @licence See LICENCE.md for license details. |
| 6 | */ |
| 7 | |
| 8 | namespace AmeliaBooking\Infrastructure\Services\Notification; |
| 9 | |
| 10 | use AmeliaBooking\Domain\Services\Notification\AbstractMailService; |
| 11 | use AmeliaBooking\Domain\Services\Notification\MailServiceInterface; |
| 12 | use AmeliaBooking\Infrastructure\Services\Outlook\AbstractOutlookCalendarService; |
| 13 | use Exception; |
| 14 | |
| 15 | /** |
| 16 | * Class OutlookService |
| 17 | */ |
| 18 | class OutlookService extends AbstractMailService implements MailServiceInterface |
| 19 | { |
| 20 | /** @var AbstractOutlookCalendarService */ |
| 21 | private $outlookCalendarService; |
| 22 | |
| 23 | /** |
| 24 | * OutlookService constructor. |
| 25 | * |
| 26 | * @param AbstractOutlookCalendarService $outlookCalendarService |
| 27 | * @param string $from |
| 28 | * @param string $fromName |
| 29 | * @param string $replyTo |
| 30 | */ |
| 31 | public function __construct($outlookCalendarService, $from, $fromName, $replyTo) |
| 32 | { |
| 33 | $this->outlookCalendarService = $outlookCalendarService; |
| 34 | |
| 35 | parent::__construct($from, $fromName, $replyTo); |
| 36 | } |
| 37 | |
| 38 | /** @noinspection MoreThanThreeArgumentsInspection */ |
| 39 | /** |
| 40 | * @param string $to |
| 41 | * @param string $subject |
| 42 | * @param string $body |
| 43 | * @param array $bcc |
| 44 | * @param array $attachments |
| 45 | * |
| 46 | * @return void |
| 47 | * @throws Exception |
| 48 | * @SuppressWarnings(PHPMD) |
| 49 | */ |
| 50 | public function send($to, $subject, $body, $bcc = [], $attachments = []) |
| 51 | { |
| 52 | $attachmentsList = []; |
| 53 | |
| 54 | foreach ($attachments as $attachment) { |
| 55 | if (!empty($attachment['content'])) { |
| 56 | $extension = pathinfo($attachment['name'], PATHINFO_EXTENSION); |
| 57 | $fileName = pathinfo($attachment['name'], PATHINFO_FILENAME); |
| 58 | $tmpFile = tempnam(sys_get_temp_dir(), $fileName . '_'); |
| 59 | if ( |
| 60 | $tmpFile && |
| 61 | file_put_contents($tmpFile, $attachment['content']) !== false && |
| 62 | @rename($tmpFile, $tmpFile .= '.' . $extension) !== false |
| 63 | ) { |
| 64 | $attachmentsList[] = ['filePath' => $tmpFile, 'fileName' => $attachment['name']]; |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | $this->outlookCalendarService->sendEmail( |
| 70 | $this->from, |
| 71 | $this->fromName, |
| 72 | $this->replyTo, |
| 73 | $to, |
| 74 | $subject, |
| 75 | $body, |
| 76 | $bcc, |
| 77 | $attachmentsList |
| 78 | ); |
| 79 | } |
| 80 | } |
| 81 |