PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Infrastructure / Services / Notification / OutlookMiddlewareService.php
ameliabooking / src / Infrastructure / Services / Notification Last commit date
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
OutlookMiddlewareService.php
83 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\Services\Notification;
4
5 use AmeliaBooking\Domain\Services\Notification\AbstractMailService;
6 use AmeliaBooking\Domain\Services\Notification\MailServiceInterface;
7 use AmeliaBooking\Infrastructure\Services\Outlook\AbstractOutlookCalendarMiddlewareService;
8 use Exception;
9
10 /**
11 * Class OutlookMiddlewareService
12 */
13 class OutlookMiddlewareService extends AbstractMailService implements MailServiceInterface
14 {
15 /** @var AbstractOutlookCalendarMiddlewareService */
16 private $outlookCalendarMiddlewareService;
17
18 /**
19 * OutlookMiddlewareService constructor.
20 *
21 * @param AbstractOutlookCalendarMiddlewareService $outlookCalendarMiddlewareService
22 * @param string $from
23 * @param string $fromName
24 * @param string $replyTo
25 */
26 public function __construct($outlookCalendarMiddlewareService, $from, $fromName, $replyTo)
27 {
28 $this->outlookCalendarMiddlewareService = $outlookCalendarMiddlewareService;
29
30 parent::__construct($from, $fromName, $replyTo);
31 }
32
33 /** @noinspection MoreThanThreeArgumentsInspection */
34 /**
35 * @param string $to
36 * @param string $subject
37 * @param string $body
38 * @param array $bcc
39 * @param array $attachments
40 *
41 * @return void
42 * @throws Exception
43 * @SuppressWarnings(PHPMD)
44 */
45 public function send($to, $subject, $body, $bcc = [], $attachments = [])
46 {
47 $attachmentsList = [];
48
49 foreach ($attachments as $attachment) {
50 if (!empty($attachment['content'])) {
51 $extension = pathinfo($attachment['name'], PATHINFO_EXTENSION);
52 $fileName = pathinfo($attachment['name'], PATHINFO_FILENAME);
53 $tmpFile = tempnam(sys_get_temp_dir(), $fileName . '_');
54 if (
55 $tmpFile &&
56 file_put_contents($tmpFile, $attachment['content']) !== false &&
57 @rename($tmpFile, $tmpFile .= '.' . $extension) !== false
58 ) {
59 $attachmentsList[] = ['filePath' => $tmpFile, 'fileName' => $attachment['name']];
60 }
61 }
62 }
63
64 $this->outlookCalendarMiddlewareService->sendEmail(
65 $this->from,
66 $this->fromName,
67 $this->replyTo,
68 $to,
69 $subject,
70 $body,
71 $bcc,
72 $attachmentsList
73 );
74
75 // Clean up temporary attachment files
76 foreach ($attachmentsList as $attachment) {
77 if (!empty($attachment['filePath']) && file_exists($attachment['filePath'])) {
78 @unlink($attachment['filePath']);
79 }
80 }
81 }
82 }
83