Skip to content

Commit eb43d9a

Browse files
Merge pull request #9 from narendravaghela/master
Updates for Cake5
2 parents 07af49c + 648355b commit eb43d9a

File tree

6 files changed

+110
-74
lines changed

6 files changed

+110
-74
lines changed

.github/workflows/ci.yml

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -11,85 +11,85 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
php-version: ['7.2', '7.4', '8.0']
14+
php-version: ['8.0']
1515
prefer-lowest: ['']
1616
include:
1717
- php-version: '7.2'
1818
prefer-lowest: 'prefer-lowest'
1919

2020
steps:
21-
- uses: actions/checkout@v2
22-
with:
23-
fetch-depth: 1
24-
25-
- name: Setup PHP
26-
uses: shivammathur/setup-php@v2
27-
with:
28-
php-version: ${{ matrix.php-version }}
29-
extensions: mbstring, intl
30-
coverage: pcov
31-
32-
- name: Get composer cache directory
33-
id: composer-cache
34-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
35-
36-
- name: Get date part for cache key
37-
id: key-date
38-
run: echo "::set-output name=date::$(date +'%Y-%m')"
39-
40-
- name: Cache composer dependencies
41-
uses: actions/cache@v2
42-
with:
43-
path: ${{ steps.composer-cache.outputs.dir }}
44-
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
45-
46-
- name: Composer install
47-
run: |
48-
if [[ ${{ matrix.php-version }} == '8.0' ]]; then
49-
composer install --ignore-platform-reqs
50-
elif ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
51-
composer update --prefer-lowest --prefer-stable
52-
else
53-
composer install
54-
fi
55-
56-
- name: Run PHPUnit
57-
run: |
58-
if [[ ${{ matrix.php-version }} == '7.4' ]]; then
59-
vendor/bin/phpunit --coverage-clover=coverage.xml
60-
else
61-
vendor/bin/phpunit
62-
fi
63-
64-
- name: Code Coverage Report
65-
if: success() && matrix.php-version == '7.4'
66-
uses: codecov/codecov-action@v1
21+
- uses: actions/checkout@v2
22+
with:
23+
fetch-depth: 1
24+
25+
- name: Setup PHP
26+
uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: ${{ matrix.php-version }}
29+
extensions: mbstring, intl
30+
coverage: pcov
31+
32+
- name: Get composer cache directory
33+
id: composer-cache
34+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
35+
36+
- name: Get date part for cache key
37+
id: key-date
38+
run: echo "::set-output name=date::$(date +'%Y-%m')"
39+
40+
- name: Cache composer dependencies
41+
uses: actions/cache@v2
42+
with:
43+
path: ${{ steps.composer-cache.outputs.dir }}
44+
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
45+
46+
- name: Composer install
47+
run: |
48+
if [[ ${{ matrix.php-version }} == '8.0' ]]; then
49+
composer install --ignore-platform-reqs
50+
elif ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
51+
composer update --prefer-lowest --prefer-stable
52+
else
53+
composer install
54+
fi
55+
56+
- name: Run PHPUnit
57+
run: |
58+
if [[ ${{ matrix.php-version }} == '7.4' ]]; then
59+
vendor/bin/phpunit --coverage-clover=coverage.xml
60+
else
61+
vendor/bin/phpunit
62+
fi
63+
64+
- name: Code Coverage Report
65+
if: success() && matrix.php-version == '7.4'
66+
uses: codecov/codecov-action@v1
6767

6868
validation:
6969
name: Coding Standard & Static Analysis
7070
runs-on: ubuntu-18.04
7171

7272
steps:
73-
- uses: actions/checkout@v2
74-
with:
75-
fetch-depth: 1
73+
- uses: actions/checkout@v2
74+
with:
75+
fetch-depth: 1
7676

77-
- name: Setup PHP
78-
uses: shivammathur/setup-php@v2
79-
with:
80-
php-version: '7.4'
81-
extensions: mbstring, intl
82-
coverage: none
83-
tools: psalm:~4.1.0
77+
- name: Setup PHP
78+
uses: shivammathur/setup-php@v2
79+
with:
80+
php-version: '7.4'
81+
extensions: mbstring, intl
82+
coverage: none
83+
tools: psalm:~4.1.0
8484

85-
- name: Composer Install
86-
run: composer stan-setup
85+
- name: Composer Install
86+
run: composer stan-setup
8787

88-
- name: Run phpstan
89-
run: composer phpstan
88+
- name: Run phpstan
89+
run: composer phpstan
9090

91-
- name: Run phpcs
92-
run: composer cs-check
91+
- name: Run phpcs
92+
run: composer cs-check
9393

9494
# - name: Run psalm
95-
# run: psalm --output-format=github
95+
# run: psalm --output-format=github

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@
88

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

11-
This branch is for use with CakePHP 5.0+. For CakePHP 4, please use cake-4.x branch.
11+
This branch is for use with **CakePHP 5.0+**. For other versions of CakePHP, please use the following version map.
12+
13+
14+
| SendGrid Plugin | Branch | CakePHP Core|
15+
| --- | --- | --- |
16+
| 1.x **[EOL]** | [cake-3.x](https://github.com/sprintcube/cakephp-sendgrid/tree/cake-3.x) | 3.4+ |
17+
| 4.x | [cake-4.x](https://github.com/sprintcube/cakephp-sendgrid/tree/cake-4.x) | 4.0+ |
18+
| 5.x (in progress) | [master](https://github.com/sprintcube/cakephp-sendgrid/tree/master) | 5.0+ |
1219

1320
## Requirements
1421

@@ -171,7 +178,7 @@ You will need to login to your SendGrid Account and configure your domain and th
171178
https://app.sendgrid.com/settings/mail_settings/webhook_settings
172179

173180
The return url needs to be set to
174-
* https://YOUR DOMAIN/send-grid/webhook
181+
* https://YOURDOMAIN/send-grid/webhook
175182

176183

177184
The CSRF protection middleware needs to allow posts to the webhooks controller in Application.php

src/Controller/AppController.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
<?php
2+
23
declare(strict_types=1);
34

5+
/**
6+
* SendGrid Plugin for CakePHP
7+
* Copyright (c) SprintCube (https://www.sprintcube.com)
8+
*
9+
* Licensed under The MIT License
10+
* For full copyright and license information, please see the LICENSE.md
11+
* Redistributions of files must retain the above copyright notice.
12+
*
13+
* @copyright Copyright (c) SprintCube (https://www.sprintcube.com)
14+
* @license https://opensource.org/licenses/mit-license.php MIT License
15+
* @link https://github.com/sprintcube/cakephp-sendgrid
16+
* @since 5.0.0
17+
*/
18+
419
namespace SendGrid\Controller;
520

621
use App\Controller\AppController as BaseController;
722

8-
class AppController extends BaseController
9-
{
10-
}
23+
class AppController extends BaseController {}

src/Controller/WebhooksController.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@
1919
*
2020
*/
2121

22+
/**
23+
* SendGrid Plugin for CakePHP
24+
* Copyright (c) SprintCube (https://www.sprintcube.com)
25+
*
26+
* Licensed under The MIT License
27+
* For full copyright and license information, please see the LICENSE.md
28+
* Redistributions of files must retain the above copyright notice.
29+
*
30+
* @copyright Copyright (c) SprintCube (https://www.sprintcube.com)
31+
* @license https://opensource.org/licenses/mit-license.php MIT License
32+
* @link https://github.com/sprintcube/cakephp-sendgrid
33+
* @since 5.0.0
34+
*/
2235

2336
namespace SendGrid\Controller;
2437

@@ -75,7 +88,7 @@ public function index()
7588
if (isset($config['secure']) && $config['secure'] == 'true') {
7689
$this->request->getBody()->rewind();
7790
$payload = $this->request->getBody()->getContents();
78-
// Log::debug($payload);
91+
// Log::debug($payload);
7992

8093
if (!isset($config['verification_key'])) {
8194
if (isset($config['debug']) && $config['debug'] == 'true') {
@@ -85,7 +98,7 @@ public function index()
8598
$this->viewBuilder()->setOption('serialize', "error");
8699
return;
87100
}
88-
101+
89102
$publicKey = PublicKey::fromString($config['verification_key']);
90103

91104
$timestampedPayload = $this->request->getHeaderLine($this::TIMESTAMP) . $payload;
@@ -126,5 +139,4 @@ public function index()
126139
$this->set('OK', "OK");
127140
$this->viewBuilder()->setOption('serialize', "OK");
128141
}
129-
130142
}

src/Mailer/SendGridMailer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
/**

src/Mailer/Transport/SendGridTransport.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,9 @@ protected function _prepareEmailAddresses(Message $message)
193193
if (!empty($replyTo)) {
194194
if (key($replyTo) != $replyTo[key($replyTo)]) {
195195
$this->_reqParams['reply_to'] = (object)['email' => key($replyTo), 'name' => $replyTo[key($replyTo)]];
196-
197196
} else {
198197
$this->_reqParams['reply_to'] = (object)['email' => key($replyTo)];
199-
}
198+
}
200199
}
201200

202201
$emails = [];
@@ -207,6 +206,10 @@ protected function _prepareEmailAddresses(Message $message)
207206
];
208207
}
209208

209+
if (empty($emails['to'])) {
210+
throw new SendGridApiException('Missing to email address.');
211+
}
212+
210213
foreach ($message->getCc() as $ccEmail => $ccName) {
211214
$emails['cc'][] = [
212215
'email' => $ccEmail,

0 commit comments

Comments
 (0)