create-prisma-php-app 1.5.8 → 1.6.1
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.
- package/composer.json +2 -1
- package/composer.lock +101 -29
- package/dist/index.js +1 -1
- package/dist/prisma-client-php/index.enc +1 -1
- package/dist/src/lib/phpmailer/Mailer.php +91 -0
- package/dist/src/lib/prisma/model/IModel.php +4 -3
- package/package.json +1 -1
- package/dist/src/lib/phpmailer/SendEmail.php +0 -47
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Lib\PHPMailer;
|
|
4
|
+
|
|
5
|
+
use PHPMailer\PHPMailer\PHPMailer;
|
|
6
|
+
use PHPMailer\PHPMailer\Exception;
|
|
7
|
+
use Lib\Prisma\Classes\Validator;
|
|
8
|
+
use Dotenv\Dotenv;
|
|
9
|
+
|
|
10
|
+
class Mailer
|
|
11
|
+
{
|
|
12
|
+
private PHPMailer $mail;
|
|
13
|
+
private Validator $validator;
|
|
14
|
+
|
|
15
|
+
public function __construct()
|
|
16
|
+
{
|
|
17
|
+
$dotenv = Dotenv::createImmutable(\DOCUMENT_PATH);
|
|
18
|
+
$dotenv->load();
|
|
19
|
+
|
|
20
|
+
$this->mail = new PHPMailer(true);
|
|
21
|
+
$this->setup();
|
|
22
|
+
|
|
23
|
+
$this->validator = new Validator();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private function setup(): void
|
|
27
|
+
{
|
|
28
|
+
$this->mail->isSMTP();
|
|
29
|
+
$this->mail->SMTPDebug = 0;
|
|
30
|
+
$this->mail->Host = $_ENV['SMTP_HOST'];
|
|
31
|
+
$this->mail->SMTPAuth = true;
|
|
32
|
+
$this->mail->Username = $_ENV['SMTP_USERNAME'];
|
|
33
|
+
$this->mail->Password = $_ENV['SMTP_PASSWORD'];
|
|
34
|
+
$this->mail->SMTPSecure = $_ENV['SMTP_ENCRYPTION'];
|
|
35
|
+
$this->mail->Port = (int) $_ENV['SMTP_PORT'];
|
|
36
|
+
$this->mail->setFrom($_ENV['MAIL_FROM'], $_ENV['MAIL_FROM_NAME']);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Send an email.
|
|
41
|
+
*
|
|
42
|
+
* @param string $to The recipient's email address.
|
|
43
|
+
* @param string $subject The subject of the email.
|
|
44
|
+
* @param string $body The HTML body of the email.
|
|
45
|
+
* @param string $name (optional) The name of the recipient.
|
|
46
|
+
* @param string $altBody (optional) The plain text alternative body of the email.
|
|
47
|
+
*
|
|
48
|
+
* @return bool Returns true if the email is sent successfully, false otherwise.
|
|
49
|
+
*
|
|
50
|
+
* @throws Exception Throws an exception if the email could not be sent.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* $mailer = new Mailer();
|
|
54
|
+
* $to = 'recipient@example.com';
|
|
55
|
+
* $subject = 'Hello';
|
|
56
|
+
* $body = '<h1>Example Email</h1><p>This is the HTML body of the email.</p>';
|
|
57
|
+
* $name = 'John Doe';
|
|
58
|
+
* $altBody = 'This is the plain text alternative body of the email.';
|
|
59
|
+
*
|
|
60
|
+
* try {
|
|
61
|
+
* $result = $mailer->send($to, $subject, $body, $name, $altBody);
|
|
62
|
+
* if ($result) {
|
|
63
|
+
* echo 'Email sent successfully.';
|
|
64
|
+
* } else {
|
|
65
|
+
* echo 'Failed to send email.';
|
|
66
|
+
* }
|
|
67
|
+
* } catch (Exception $e) {
|
|
68
|
+
* echo 'An error occurred: ' . $e->getMessage();
|
|
69
|
+
* }
|
|
70
|
+
*/
|
|
71
|
+
public function send(string $to, string $subject, string $body, string $name = '', string $altBody = ''): bool
|
|
72
|
+
{
|
|
73
|
+
try {
|
|
74
|
+
$this->validator->validateString($to);
|
|
75
|
+
$this->validator->validateString($subject);
|
|
76
|
+
$this->validator->validateString($body);
|
|
77
|
+
$this->validator->validateString($name);
|
|
78
|
+
$this->validator->validateString($altBody);
|
|
79
|
+
|
|
80
|
+
$this->mail->addAddress($to, $name);
|
|
81
|
+
$this->mail->isHTML(true);
|
|
82
|
+
$this->mail->Subject = $subject;
|
|
83
|
+
$this->mail->Body = $body;
|
|
84
|
+
$this->mail->AltBody = $altBody;
|
|
85
|
+
|
|
86
|
+
return $this->mail->send();
|
|
87
|
+
} catch (\Exception) {
|
|
88
|
+
echo "Message could not be sent. Mailer Error: {$this->mail->ErrorInfo}";
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -5,15 +5,16 @@ namespace Lib\Prisma\Model;
|
|
|
5
5
|
interface IModel
|
|
6
6
|
{
|
|
7
7
|
public function create(array $data);
|
|
8
|
+
public function createMany(array $data);
|
|
8
9
|
public function findUnique(array $criteria);
|
|
9
|
-
public function findMany(array $
|
|
10
|
+
public function findMany(array $criteria);
|
|
10
11
|
public function findFirst(array $criteria);
|
|
11
12
|
public function update(array $data);
|
|
13
|
+
public function updateMany(array $data);
|
|
12
14
|
public function delete(array $criteria);
|
|
15
|
+
public function deleteMany(array $criteria);
|
|
13
16
|
public function upsert(array $data);
|
|
14
17
|
public function aggregate(array $operation);
|
|
15
18
|
public function groupBy(array $by);
|
|
16
|
-
public function updateMany(array $data);
|
|
17
|
-
public function deleteMany(array $criteria);
|
|
18
19
|
public function count(array $criteria);
|
|
19
20
|
}
|
package/package.json
CHANGED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
//Import PHPMailer classes into the global namespace
|
|
3
|
-
//These must be at the top of your script, not inside a function
|
|
4
|
-
use PHPMailer\PHPMailer\PHPMailer;
|
|
5
|
-
use PHPMailer\PHPMailer\SMTP;
|
|
6
|
-
use PHPMailer\PHPMailer\Exception;
|
|
7
|
-
|
|
8
|
-
//Load Composer's autoloader
|
|
9
|
-
require 'vendor/autoload.php';
|
|
10
|
-
|
|
11
|
-
//Create an instance; passing `true` enables exceptions
|
|
12
|
-
$mail = new PHPMailer(true);
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
//Server settings
|
|
16
|
-
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
|
|
17
|
-
$mail->isSMTP(); //Send using SMTP
|
|
18
|
-
$mail->Host = 'smtp.example.com'; //Set the SMTP server to send through
|
|
19
|
-
$mail->SMTPAuth = true; //Enable SMTP authentication
|
|
20
|
-
$mail->Username = 'user@example.com'; //SMTP username
|
|
21
|
-
$mail->Password = 'secret'; //SMTP password
|
|
22
|
-
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
|
|
23
|
-
$mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
|
|
24
|
-
|
|
25
|
-
//Recipients
|
|
26
|
-
$mail->setFrom('from@example.com', 'Mailer');
|
|
27
|
-
$mail->addAddress('joe@example.net', 'Joe User'); //Add a recipient
|
|
28
|
-
$mail->addAddress('ellen@example.com'); //Name is optional
|
|
29
|
-
$mail->addReplyTo('info@example.com', 'Information');
|
|
30
|
-
$mail->addCC('cc@example.com');
|
|
31
|
-
$mail->addBCC('bcc@example.com');
|
|
32
|
-
|
|
33
|
-
//Attachments
|
|
34
|
-
$mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments
|
|
35
|
-
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name
|
|
36
|
-
|
|
37
|
-
//Content
|
|
38
|
-
$mail->isHTML(true); //Set email format to HTML
|
|
39
|
-
$mail->Subject = 'Here is the subject';
|
|
40
|
-
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
|
|
41
|
-
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
|
|
42
|
-
|
|
43
|
-
$mail->send();
|
|
44
|
-
echo 'Message has been sent';
|
|
45
|
-
} catch (\Exception $e) {
|
|
46
|
-
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
|
|
47
|
-
}
|