Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 64 additions & 64 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,85 +11,85 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['7.2', '7.4', '8.0']
php-version: ['8.0']
prefer-lowest: ['']
include:
- php-version: '7.2'
prefer-lowest: 'prefer-lowest'

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
coverage: pcov

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Get date part for cache key
id: key-date
run: echo "::set-output name=date::$(date +'%Y-%m')"

- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}

- name: Composer install
run: |
if [[ ${{ matrix.php-version }} == '8.0' ]]; then
composer install --ignore-platform-reqs
elif ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
composer update --prefer-lowest --prefer-stable
else
composer install
fi

- name: Run PHPUnit
run: |
if [[ ${{ matrix.php-version }} == '7.4' ]]; then
vendor/bin/phpunit --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi

- name: Code Coverage Report
if: success() && matrix.php-version == '7.4'
uses: codecov/codecov-action@v1
- uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
coverage: pcov

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Get date part for cache key
id: key-date
run: echo "::set-output name=date::$(date +'%Y-%m')"

- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}

- name: Composer install
run: |
if [[ ${{ matrix.php-version }} == '8.0' ]]; then
composer install --ignore-platform-reqs
elif ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
composer update --prefer-lowest --prefer-stable
else
composer install
fi

- name: Run PHPUnit
run: |
if [[ ${{ matrix.php-version }} == '7.4' ]]; then
vendor/bin/phpunit --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi

- name: Code Coverage Report
if: success() && matrix.php-version == '7.4'
uses: codecov/codecov-action@v1

validation:
name: Coding Standard & Static Analysis
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1
- uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
extensions: mbstring, intl
coverage: none
tools: psalm:~4.1.0
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
extensions: mbstring, intl
coverage: none
tools: psalm:~4.1.0

- name: Composer Install
run: composer stan-setup
- name: Composer Install
run: composer stan-setup

- name: Run phpstan
run: composer phpstan
- name: Run phpstan
run: composer phpstan

- name: Run phpcs
run: composer cs-check
- name: Run phpcs
run: composer cs-check

# - name: Run psalm
# run: psalm --output-format=github
# run: psalm --output-format=github
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@

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

This branch is for use with CakePHP 5.0+. For CakePHP 4, please use cake-4.x branch.
This branch is for use with **CakePHP 5.0+**. For other versions of CakePHP, please use the following version map.


| SendGrid Plugin | Branch | CakePHP Core|
| --- | --- | --- |
| 1.x **[EOL]** | [cake-3.x](https://github.com/sprintcube/cakephp-sendgrid/tree/cake-3.x) | 3.4+ |
| 4.x | [cake-4.x](https://github.com/sprintcube/cakephp-sendgrid/tree/cake-4.x) | 4.0+ |
| 5.x (in progress) | [master](https://github.com/sprintcube/cakephp-sendgrid/tree/master) | 5.0+ |

## Requirements

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

The return url needs to be set to
* https://YOUR DOMAIN/send-grid/webhook
* https://YOURDOMAIN/send-grid/webhook


The CSRF protection middleware needs to allow posts to the webhooks controller in Application.php
Expand Down
19 changes: 16 additions & 3 deletions src/Controller/AppController.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
<?php

declare(strict_types=1);

/**
* SendGrid Plugin for CakePHP
* Copyright (c) SprintCube (https://www.sprintcube.com)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.md
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) SprintCube (https://www.sprintcube.com)
* @license https://opensource.org/licenses/mit-license.php MIT License
* @link https://github.com/sprintcube/cakephp-sendgrid
* @since 5.0.0
*/

namespace SendGrid\Controller;

use App\Controller\AppController as BaseController;

class AppController extends BaseController
{
}
class AppController extends BaseController {}
18 changes: 15 additions & 3 deletions src/Controller/WebhooksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
*
*/

/**
* SendGrid Plugin for CakePHP
* Copyright (c) SprintCube (https://www.sprintcube.com)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.md
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) SprintCube (https://www.sprintcube.com)
* @license https://opensource.org/licenses/mit-license.php MIT License
* @link https://github.com/sprintcube/cakephp-sendgrid
* @since 5.0.0
*/

namespace SendGrid\Controller;

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

if (!isset($config['verification_key'])) {
if (isset($config['debug']) && $config['debug'] == 'true') {
Expand All @@ -85,7 +98,7 @@ public function index()
$this->viewBuilder()->setOption('serialize', "error");
return;
}

$publicKey = PublicKey::fromString($config['verification_key']);

$timestampedPayload = $this->request->getHeaderLine($this::TIMESTAMP) . $payload;
Expand Down Expand Up @@ -126,5 +139,4 @@ public function index()
$this->set('OK', "OK");
$this->viewBuilder()->setOption('serialize', "OK");
}

}
1 change: 1 addition & 0 deletions src/Mailer/SendGridMailer.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Mailer/Transport/SendGridTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,9 @@ protected function _prepareEmailAddresses(Message $message)
if (!empty($replyTo)) {
if (key($replyTo) != $replyTo[key($replyTo)]) {
$this->_reqParams['reply_to'] = (object)['email' => key($replyTo), 'name' => $replyTo[key($replyTo)]];

} else {
$this->_reqParams['reply_to'] = (object)['email' => key($replyTo)];
}
}
}

$emails = [];
Expand All @@ -207,6 +206,10 @@ protected function _prepareEmailAddresses(Message $message)
];
}

if (empty($emails['to'])) {
throw new SendGridApiException('Missing to email address.');
}

foreach ($message->getCc() as $ccEmail => $ccName) {
$emails['cc'][] = [
'email' => $ccEmail,
Expand Down
Loading