Skip to content
This repository has been archived by the owner on Jan 7, 2021. It is now read-only.

Commit

Permalink
feat(mailer): Added the bridge.
Browse files Browse the repository at this point in the history
  • Loading branch information
drixs6o9 committed Aug 26, 2019
0 parents commit 95027cf
Show file tree
Hide file tree
Showing 13 changed files with 375 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: 2 # use CircleCI 2.0

jobs: # a collection of steps
build: # runs not using Workflows must have a `build` job as entry point
working_directory: ~/sendinblue-mailer # directory where steps will run
docker: # run the steps with Docker
- image: circleci/php:fpm-stretch # ...with this image as the primary container; this is where all `steps` will run environment:
environment:
APP_ENV: test
steps:
- run:
name: Install system packages
command: sudo apt-get update && sudo apt-get -y install git
- checkout
- run:
name: Install Composer
command: |
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === trim(file_get_contents('https://composer.github.io/installer.sig'))) { echo 'Installer verified'; } else { echo 'Installer invalid'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
- run:
name: Display PHP information
command: |
php -v
php composer.phar --version
- run:
name: Install project dependencies
command: php composer.phar install
- run:
name: Run tests
command: ./vendor/bin/simple-phpunit --coverage-html build/coverage-report
- store_artifacts:
path: build/coverage-report
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build
vendor
.phpunit.*
composer.lock
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CHANGELOG
=========

1.0.0
-----

* Added the bridge
25 changes: 25 additions & 0 deletions DependencyInjection/SendinblueMailerExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Drixs6o9\SendinblueMailerBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;

/**
* Class SendinblueMailerExtension.
*
* @author Yann LUCAS
*/
class SendinblueMailerExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources'));
$loader->load('mailer_transport.xml');
}
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Yann LUCAS

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Sendinblue Mailer
=================

Provides Sendinblue integration for Symfony Mailer.

[![CircleCI](https://circleci.com/gh/drixs6o9/sendinblue-mailer/tree/master.svg?style=svg)](https://circleci.com/gh/drixs6o9/sendinblue-mailer/tree/master)

Installation
------------

Open a command console inyour project directory and execute the
following command to download the latest stable version of this bundle:

```bash
$ composer require drixs6o9/sendinblue-mailer
```

Then, enable the bundle by adding the following line in the `config/bundle.php`
file of your project:

```php
<?php
// config/bundle.php

return [
// ...
Drixs6o9\SendinblueMailerBundle\SendinblueMailerBundle::class => ['all' => true],
];
```

Finally, add your Sendinblue credentials into your `.env.local` file of your project:
```env
###> drixs6o9/sendinblue-mailer ###
SENDINBLUE_USERNAME=username
SENDINBLUE_PASSWORD=password
MAILER_DSN=smtp://$SENDINBLUE_USERNAME:$SENDINBLUE_PASSWORD@sendinblue
###< drixs6o9/sendinblue-mailer ###
```

Resources
---------

* [Report issues](https://github.com/drixs6o9/sendinblue-mailer/issues)
* [Send Pull Requests](https://github.com/drixs6o9/sendinblue-mailer/pulls)
12 changes: 12 additions & 0 deletions Resources/mailer_transport.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="mailer.transport_factory.sendinblue" class="Drixs6o9\SendinblueMailerBundle\Transport\SendinblueTransportFactory" parent="mailer.transport_factory.abstract">
<tag name="mailer.transport_factory" />
</service>
</services>
</container>
14 changes: 14 additions & 0 deletions SendinblueMailerBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Drixs6o9\SendinblueMailerBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* Class SendinblueMailer.
*
* @author Yann LUCAS
*/
class SendinblueMailerBundle extends Bundle
{
}
71 changes: 71 additions & 0 deletions Tests/Transport/SeninblueTransportFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace Drixs6o9\SendinblueMailerBundle\Tests\Transport;

use Drixs6o9\SendinblueMailerBundle\Transport\SendinblueSmtpTransport;
use Drixs6o9\SendinblueMailerBundle\Transport\SendinblueTransportFactory;
use Symfony\Component\Mailer\Test\TransportFactoryTestCase;
use Symfony\Component\Mailer\Transport\Dsn;
use Symfony\Component\Mailer\Transport\TransportFactoryInterface;

/**
* Class SeninblueTransportFactoryTest.
*
* @author Yann LUCAS
*/
class SeninblueTransportFactoryTest extends TransportFactoryTestCase
{
/**
* {@inheritDoc}
*/
public function getFactory(): TransportFactoryInterface
{
return new SendinblueTransportFactory($this->getDispatcher(), $this->getClient(), $this->getLogger());
}

/**
* {@inheritDoc}
*/
public function supportsProvider(): iterable
{
yield [
new Dsn('smtp', 'sendinblue'),
true,
];

yield [
new Dsn('smtp', 'example.com'),
false,
];
}

/**
* {@inheritDoc}
*/
public function createProvider(): iterable
{
yield [
new Dsn('smtp', 'sendinblue', self::USER, self::PASSWORD),
new SendinblueSmtpTransport(self::USER, self::PASSWORD, $this->getDispatcher(), $this->getLogger()),
];
}

/**
* {@inheritDoc}
*/
public function unsupportedSchemeProvider(): iterable
{
yield [
new Dsn('foo', 'sendinblue', self::USER, self::PASSWORD),
'The "foo" scheme is not supported for mailer "sendinblue". Supported schemes are: "smtp".',
];
}

/**
* {@inheritDoc}
*/
public function incompleteDsnProvider(): iterable
{
yield [new Dsn('smtp', 'sendinblue', self::USER)];
}
}
41 changes: 41 additions & 0 deletions Transport/SendinblueSmtpTransport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Drixs6o9\SendinblueMailerBundle\Transport;

use Psr\Log\LoggerInterface;
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

/**
* Class SendinblueSmtpTransport.
*
* @author Yann LUCAS
*/
final class SendinblueSmtpTransport extends EsmtpTransport
{
const SENDINBLUE_SMTP_HOST = 'smtp-relay.sendinblue.com';
const SENDINBLUE_SMTP_PORT = 465;
const SENDINBLUE_TLS_ENABLED = true;

/**
* SendinblueSmtpTransport constructor.
*
* @param string $username
* @param string $password
* @param EventDispatcherInterface|null $dispatcher
* @param LoggerInterface|null $logger
*/
public function __construct($username, $password, $dispatcher = null, $logger = null)
{
parent::__construct(
self::SENDINBLUE_SMTP_HOST,
self::SENDINBLUE_SMTP_PORT,
self::SENDINBLUE_TLS_ENABLED,
$dispatcher,
$logger
);

$this->setUsername($username);
$this->setPassword($password);
}
}
41 changes: 41 additions & 0 deletions Transport/SendinblueTransportFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Drixs6o9\SendinblueMailerBundle\Transport;

use Symfony\Component\Mailer\Exception\UnsupportedSchemeException;
use Symfony\Component\Mailer\Transport\AbstractTransportFactory;
use Symfony\Component\Mailer\Transport\Dsn;
use Symfony\Component\Mailer\Transport\TransportInterface;

/**
* Class SendinblueTransportFactory.
*
* @author Yann LUCAS
*/
final class SendinblueTransportFactory extends AbstractTransportFactory
{
/**
* {@inheritDoc}
*/
public function create(Dsn $dsn): TransportInterface
{
if ('smtp' !== $dsn->getScheme()) {
throw new UnsupportedSchemeException($dsn, ['smtp']);
}

return new SendinblueSmtpTransport(
$this->getUser($dsn),
$this->getPassword($dsn),
$this->dispatcher,
$this->logger
);
}

/**
* {@inheritDoc}
*/
public function supports(Dsn $dsn): bool
{
return 'sendinblue' === $dsn->getHost();
}
}
29 changes: 29 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "drixs6o9/sendinblue-mailer",
"type": "symfony-bridge",
"description": "Symfony Sendinblue Mailer Bridge",
"keywords": ["symfony", "sendinblue", "mailer", "bridge"],
"homepage": "https://github.com/drixs6o9",
"license": "MIT",
"authors": [
{
"name": "Yann LUCAS",
"email": "yann.lucas@oulook.com"
}
],
"require": {
"php": "^7.2.9",
"symfony/mailer": "^4.4|^5.0"
},
"require-dev": {
"symfony/http-client": "^4.4|^5.0",
"symfony/test-pack": "*"
},
"autoload": {
"psr-4": { "Drixs6o9\\SendinblueMailerBundle\\": "" },
"exclude-from-classmap": [
"/Tests/"
]
},
"minimum-stability": "dev"
}
32 changes: 32 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
failOnRisky="true"
failOnWarning="true"
>
<php>
<ini name="error_reporting" value="-1" />
</php>

<testsuites>
<testsuite name="Symfony Sendinblue Mailer Bridge Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./DependencyInjection</directory>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>

0 comments on commit 95027cf

Please sign in to comment.