create-prisma-php-app 2.0.0-beta.2 → 2.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -317,7 +317,7 @@ class Auth
|
|
|
317
317
|
private function findProvider(array $providers, string $type): ?object
|
|
318
318
|
{
|
|
319
319
|
foreach ($providers as $provider) {
|
|
320
|
-
if ($provider
|
|
320
|
+
if (is_object($provider) && get_class($provider) === $type) {
|
|
321
321
|
return $provider;
|
|
322
322
|
}
|
|
323
323
|
}
|
|
@@ -38,7 +38,8 @@ class Mailer
|
|
|
38
38
|
* @param string $to The recipient's email address.
|
|
39
39
|
* @param string $subject The subject of the email.
|
|
40
40
|
* @param string $body The HTML body of the email.
|
|
41
|
-
* @param array $options (optional) Additional email options like name, altBody, CC, and
|
|
41
|
+
* @param array $options (optional) Additional email options like name, altBody, CC, BCC, and attachments.
|
|
42
|
+
* - attachments: A string or an array of file paths, or an array of associative arrays with keys 'path' and 'name'.
|
|
42
43
|
*
|
|
43
44
|
* @return bool Returns true if the email is sent successfully, false otherwise.
|
|
44
45
|
*
|
|
@@ -60,6 +61,7 @@ class Mailer
|
|
|
60
61
|
$name = $options['name'] ?? '';
|
|
61
62
|
$addCC = $options['addCC'] ?? [];
|
|
62
63
|
$addBCC = $options['addBCC'] ?? [];
|
|
64
|
+
$attachments = $options['attachments'] ?? [];
|
|
63
65
|
|
|
64
66
|
$name = Validator::string($name);
|
|
65
67
|
|
|
@@ -67,6 +69,10 @@ class Mailer
|
|
|
67
69
|
$this->handleRecipients($addCC, 'CC');
|
|
68
70
|
// Handle BCC recipients
|
|
69
71
|
$this->handleRecipients($addBCC, 'BCC');
|
|
72
|
+
// Handle file attachments if provided
|
|
73
|
+
if (!empty($attachments)) {
|
|
74
|
+
$this->handleAttachments($attachments);
|
|
75
|
+
}
|
|
70
76
|
|
|
71
77
|
// Set the main recipient and other email properties
|
|
72
78
|
$this->mail->addAddress($to, $name);
|
|
@@ -115,6 +121,41 @@ class Mailer
|
|
|
115
121
|
}
|
|
116
122
|
}
|
|
117
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Handle adding file attachments.
|
|
126
|
+
*
|
|
127
|
+
* @param string|array $attachments File path(s) to attach.
|
|
128
|
+
* You can pass a string for a single file or an array of file paths.
|
|
129
|
+
* Alternatively, each attachment can be an array with keys 'path' and 'name' for custom naming.
|
|
130
|
+
*
|
|
131
|
+
* @throws Exception Throws an exception if any attachment file is not found.
|
|
132
|
+
*/
|
|
133
|
+
private function handleAttachments(string|array $attachments): void
|
|
134
|
+
{
|
|
135
|
+
if (is_array($attachments)) {
|
|
136
|
+
foreach ($attachments as $attachment) {
|
|
137
|
+
if (is_array($attachment)) {
|
|
138
|
+
$file = $attachment['path'] ?? null;
|
|
139
|
+
$name = $attachment['name'] ?? '';
|
|
140
|
+
if (!$file || !file_exists($file)) {
|
|
141
|
+
throw new \Exception("Attachment file does not exist: " . ($file ?? 'unknown'));
|
|
142
|
+
}
|
|
143
|
+
$this->mail->addAttachment($file, $name);
|
|
144
|
+
} else {
|
|
145
|
+
if (!file_exists($attachment)) {
|
|
146
|
+
throw new \Exception("Attachment file does not exist: $attachment");
|
|
147
|
+
}
|
|
148
|
+
$this->mail->addAttachment($attachment);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
if (!file_exists($attachments)) {
|
|
153
|
+
throw new \Exception("Attachment file does not exist: $attachments");
|
|
154
|
+
}
|
|
155
|
+
$this->mail->addAttachment($attachments);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
118
159
|
/**
|
|
119
160
|
* Convert HTML content to plain text.
|
|
120
161
|
*
|