Skip to content

Commit f198e18

Browse files
Merge pull request #4 from narendravaghela/master
Upgrade base code for CakePHP 4
2 parents 39e2ac0 + 9591324 commit f198e18

12 files changed

Lines changed: 604 additions & 357 deletions

File tree

.gitignore

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
11
/composer.lock
2-
/phpunit.xml
3-
/vendor
2+
/vendor/*
3+
/coverage
4+
5+
# OS generated files #
6+
######################
7+
.DS_Store
8+
.DS_Store?
9+
._*
10+
.Spotlight-V100
11+
.Trashes
12+
# Icon must end with two \r
13+
Icon
14+
15+
ehthumbs.db
16+
Thumbs.db
17+
.directory
18+
19+
# Tool specific files #
20+
#######################
21+
# PHPUnit
22+
phpunit.xml
23+
.phpunit.result.cache
24+
tests.sqlite
25+
# vim
26+
*~
27+
*.swp
28+
*.swo
29+
# sublime text & textmate
30+
*.sublime-*
31+
*.stTheme.cache
32+
*.tmlanguage.cache
33+
*.tmPreferences.cache
34+
# Eclipse
35+
.settings/*
36+
# JetBrains, aka PHPStorm, IntelliJ IDEA
37+
.idea/*
38+
# NetBeans
39+
nbproject/*
40+
# Visual Studio Code
41+
.vscode
42+
# Sass preprocessor
43+
.sass-cache/

README.md

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SendGrid Plugin for CakePHP 3
1+
# SendGrid Plugin for CakePHP
22

33
[![Build Status](https://travis-ci.org/sprintcube/cakephp-sendgrid.svg?branch=master)](https://travis-ci.org/sprintcube/cakephp-sendgrid)
44
[![codecov](https://codecov.io/gh/sprintcube/cakephp-sendgrid/branch/master/graph/badge.svg)](https://codecov.io/gh/sprintcube/cakephp-sendgrid)
@@ -8,12 +8,14 @@
88

99
This plugin provides email delivery using [SendGrid](https://sendgrid.com/).
1010

11+
This branch is for use with CakePHP 4.0+. For CakePHP 3, please use cake-3.x branch.
12+
1113
## Requirements
1214

1315
This plugin has the following requirements:
1416

15-
* CakePHP 3.4.0 or greater.
16-
* PHP 5.6 or greater.
17+
* CakePHP 4.0 or greater.
18+
* PHP 7.2 or greater.
1719

1820
## Installation
1921

@@ -66,38 +68,33 @@ And create new delivery profile in `Email` settings.
6668
You can now simply use the CakePHP `Email` to send an email via SendGrid.
6769

6870
```php
69-
$email = new Email('sendgrid');
70-
71+
$email = new SendGridMailer();
7172
$email->setFrom(['you@yourdomain.com' => 'CakePHP SendGrid'])
7273
->setTo('foo@example.com.com')
7374
->addTo('bar@example.com')
7475
->addCc('john@example.com')
75-
->setHeaders(['X-Custom' => 'headervalue'])
7676
->setSubject('Email from CakePHP SendGrid plugin')
77-
->send('Message from CakePHP SendGrid plugin');
77+
->deliver('Message from CakePHP SendGrid plugin');
7878
```
7979

8080
That is it.
8181

8282
## Advance Use
83-
You can also use few more options to send email via SendGrid APIs. To do so, get the transport instance and call the appropriate methods before sending the email.
83+
You can also use few more options to send email via SendGrid APIs. To do so, just call the appropriate methods before sending the email.
8484

8585
### Custom Headers
8686
You can pass your own headers. It must be prefixed with "X-". Use the default `Email::setHeaders` method like,
8787

8888
```php
89-
$email = new Email('sendgrid');
90-
89+
$email = new SendGridMailer();
9190
$email->setFrom(['you@yourdomain.com' => 'CakePHP SendGrid'])
92-
->setSender('someone@example.com', 'Someone')
9391
->setTo('foo@example.com.com')
94-
->addTo('bar@example.com')
9592
->setHeaders([
9693
'X-Custom' => 'headervalue',
9794
'X-MyHeader' => 'myvalue'
9895
])
9996
->setSubject('Email from CakePHP SendGrid plugin')
100-
->send('Message from CakePHP SendGrid plugin');
97+
->deliver('Message from CakePHP SendGrid plugin');
10198
```
10299

103100
> When sending request, `X-` will be removed from header name e.g. X-MyHeader will become MyHeader
@@ -106,19 +103,16 @@ $email->setFrom(['you@yourdomain.com' => 'CakePHP SendGrid'])
106103
Set your attachments using `Email::setAttachments` method.
107104

108105
```php
109-
$email = new Email('sendgrid');
110-
106+
$email = new SendGridMailer();
111107
$email->setFrom(['you@yourdomain.com' => 'CakePHP SendGrid'])
112-
->setSender('someone@example.com', 'Someone')
113108
->setTo('foo@example.com.com')
114-
->addTo('bar@example.com')
109+
->setSubject('Email from CakePHP SendGrid plugin')
115110
->setAttachments([
116111
'cake_icon1.png' => Configure::read('App.imageBaseUrl') . 'cake.icon.png',
117112
'cake_icon2.png' => ['file' => Configure::read('App.imageBaseUrl') . 'cake.icon.png'],
118113
WWW_ROOT . 'favicon.ico'
119114
])
120-
->setSubject('Email from CakePHP SendGrid plugin')
121-
->send('Message from CakePHP SendGrid plugin');
115+
->deliver('Message from CakePHP SendGrid plugin');
122116
```
123117

124118
> To send inline attachment, use `contentId` parameter while setting attachment.
@@ -128,20 +122,20 @@ You can use the template created in SendGrid backend. Get the template id by eit
128122
Set the template id using `setTemplate` method.
129123

130124
```php
131-
$email = new Email('sendgrid');
132-
$emailInstance = $email->getTransport();
133-
$emailInstance->setTemplte(123);
134-
$email->send();
125+
$email = new SendGridMailer();
126+
$email->setTo('foo@example.com.com')
127+
->setTemplate('d-xxxxxx')
128+
->deliver();
135129
```
136130

137131
### Schedule
138-
You can schedule the email to be sent in future date. You can set upto 72 hours in future as per SendGrid documentation.
132+
You can schedule the email to be sent in future date. You can set upto 72 hours in future as per SendGrid documentation. You need to pass a unix timestamp value.
139133

140134
```php
141-
$email = new Email('sendgrid');
142-
$emailInstance = $email->getTransport();
143-
$emailInstance->setScheduleTime(1537958411);
144-
$email->send();
135+
$email = new SendGridMailer();
136+
$email->setTo('foo@example.com.com')
137+
->setSendAt(1649500630)
138+
->deliver();
145139
```
146140

147141
## Reporting Issues

composer.json

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sprintcube/cakephp-sendgrid",
3-
"description": "SendGrid plugin for CakePHP 3 - Send emails using SendGrid API",
3+
"description": "SendGrid plugin for CakePHP 4 - Send emails using SendGrid API",
44
"type": "cakephp-plugin",
55
"license": "MIT",
66
"keywords": [
@@ -16,7 +16,7 @@
1616
},
1717
{
1818
"name": "Narendra Vaghela",
19-
"homepage": "http://www.narendravaghela.com",
19+
"homepage": "https://www.sprintcube.com",
2020
"role": "Author"
2121
},
2222
{
@@ -29,11 +29,14 @@
2929
"issues": "https://github.com/sprintcube/cakephp-sendgrid/issues"
3030
},
3131
"require": {
32-
"cakephp/cakephp": "^3.4"
32+
"php": ">=7.2",
33+
"cakephp/cakephp": "^4.0.0"
3334
},
3435
"require-dev": {
35-
"phpunit/phpunit": "^5.7.14|^6.0",
36-
"cakephp/cakephp-codesniffer": "^3.0"
36+
"phpunit/phpunit": "^8.5 || ^9.3",
37+
"cakephp/cakephp-codesniffer": "^4.0",
38+
"phpstan/phpstan": "^0.12",
39+
"codacy/coverage": "^1.4"
3740
},
3841
"autoload": {
3942
"psr-4": {
@@ -53,7 +56,9 @@
5356
],
5457
"cs-check": "phpcs --colors -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
5558
"cs-fix": "phpcbf --colors --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
56-
"phpstan": "phpstan analyze -l 1 src/",
59+
"phpstan": "phpstan analyze --level 1 src/",
5760
"test": "phpunit --colors=always"
58-
}
61+
},
62+
"prefer-stable": true,
63+
"minimum-stability": "dev"
5964
}

phpunit.xml.dist

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
3-
colors="true"
4-
processIsolation="false"
5-
stopOnFailure="false"
6-
syntaxCheck="false"
7-
bootstrap="tests/bootstrap.php"
8-
>
9-
<php>
10-
<ini name="memory_limit" value="-1"/>
11-
<ini name="apc.enable_cli" value="1"/>
12-
</php>
13-
14-
<!-- Add any additional test suites you want to run here -->
15-
<testsuites>
16-
<testsuite name="SendGrid">
17-
<directory>tests/TestCase/</directory>
18-
</testsuite>
19-
</testsuites>
20-
21-
<!-- Setup a listener for fixtures -->
22-
<listeners>
23-
<listener class="\Cake\TestSuite\Fixture\FixtureInjector">
24-
<arguments>
25-
<object class="\Cake\TestSuite\Fixture\FixtureManager"/>
26-
</arguments>
27-
</listener>
28-
</listeners>
29-
30-
<filter>
31-
<whitelist>
32-
<directory suffix=".php">src/</directory>
33-
</whitelist>
34-
</filter>
35-
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">src/</directory>
6+
</include>
7+
</coverage>
8+
<php>
9+
<ini name="memory_limit" value="-1"/>
10+
<ini name="apc.enable_cli" value="1"/>
11+
</php>
12+
<!-- Add any additional test suites you want to run here -->
13+
<testsuites>
14+
<testsuite name="CakePHP SendGrid">
15+
<directory>tests/TestCase/</directory>
16+
</testsuite>
17+
</testsuites>
3618
</phpunit>

src/Mailer/Exception/SendGridApiException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
3-
* SendGrid Plugin for CakePHP 3
5+
* SendGrid Plugin for CakePHP
46
* Copyright (c) SprintCube (https://www.sprintcube.com)
57
*
68
* Licensed under The MIT License

src/Mailer/SendGridMailer.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* SendGrid Plugin for CakePHP
6+
* Copyright (c) SprintCube (https://www.sprintcube.com)
7+
*
8+
* Licensed under The MIT License
9+
* For full copyright and license information, please see the LICENSE.md
10+
* Redistributions of files must retain the above copyright notice.
11+
*
12+
* @copyright Copyright (c) SprintCube (https://www.sprintcube.com)
13+
* @license https://opensource.org/licenses/mit-license.php MIT License
14+
* @link https://github.com/sprintcube/cakephp-sendgrid
15+
* @since 4.0.0
16+
*/
17+
18+
namespace SendGrid\Mailer;
19+
20+
use Cake\Mailer\Mailer;
21+
22+
/**
23+
* Mailer base class for SendGrid
24+
*
25+
* This allows to send the email using the SendGrid.
26+
*/
27+
class SendGridMailer extends Mailer
28+
{
29+
use SendGridTrait;
30+
31+
/**
32+
* Constructor
33+
*
34+
* @param array<string, mixed>|string|null $config Array of configs, or string to load configs from app.php
35+
*/
36+
public function __construct($config = [])
37+
{
38+
parent::__construct($config);
39+
$this->setTransport('sendgrid');
40+
}
41+
}

0 commit comments

Comments
 (0)