mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-15 09:30:58 +00:00
Extract Mailer component & bundle
This commit is contained in:
parent
883e2431d4
commit
1f7ac825d5
48 changed files with 2 additions and 2235 deletions
|
|
@ -54,6 +54,8 @@
|
|||
"swiftmailer/swiftmailer": "^6.0",
|
||||
"sylius-labs/association-hydrator": "^1.0",
|
||||
"sylius/fixtures-bundle": "~1.1.15",
|
||||
"sylius/mailer": "~1.1.15",
|
||||
"sylius/mailer-bundle": "~1.1.15",
|
||||
"sylius/registry": "~1.1.15",
|
||||
"sylius/theme-bundle": "~1.1.15",
|
||||
"symfony/monolog-bundle": "^3.0",
|
||||
|
|
@ -122,8 +124,6 @@
|
|||
"sylius/inventory-bundle": "self.version",
|
||||
"sylius/locale": "self.version",
|
||||
"sylius/locale-bundle": "self.version",
|
||||
"sylius/mailer": "self.version",
|
||||
"sylius/mailer-bundle": "self.version",
|
||||
"sylius/money-bundle": "self.version",
|
||||
"sylius/order": "self.version",
|
||||
"sylius/order-bundle": "self.version",
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ suites:
|
|||
Grid: { namespace: Sylius\Component\Grid, psr4_prefix: Sylius\Component\Grid, spec_path: src/Sylius/Component/Grid, src_path: src/Sylius/Component/Grid }
|
||||
Inventory: { namespace: Sylius\Component\Inventory, psr4_prefix: Sylius\Component\Inventory, spec_path: src/Sylius/Component/Inventory, src_path: src/Sylius/Component/Inventory }
|
||||
Locale: { namespace: Sylius\Component\Locale, psr4_prefix: Sylius\Component\Locale, spec_path: src/Sylius/Component/Locale, src_path: src/Sylius/Component/Locale }
|
||||
Mailer: { namespace: Sylius\Component\Mailer, psr4_prefix: Sylius\Component\Mailer, spec_path: src/Sylius/Component/Mailer, src_path: src/Sylius/Component/Mailer }
|
||||
Order: { namespace: Sylius\Component\Order, psr4_prefix: Sylius\Component\Order, spec_path: src/Sylius/Component/Order, src_path: src/Sylius/Component/Order }
|
||||
Payment: { namespace: Sylius\Component\Payment, psr4_prefix: Sylius\Component\Payment, spec_path: src/Sylius/Component/Payment, src_path: src/Sylius/Component/Payment }
|
||||
Product: { namespace: Sylius\Component\Product, psr4_prefix: Sylius\Component\Product, spec_path: src/Sylius/Component/Product, src_path: src/Sylius/Component/Product }
|
||||
|
|
@ -31,7 +30,6 @@ suites:
|
|||
GridBundle: { namespace: Sylius\Bundle\GridBundle, psr4_prefix: Sylius\Bundle\GridBundle, spec_path: src/Sylius/Bundle/GridBundle, src_path: src/Sylius/Bundle/GridBundle }
|
||||
InventoryBundle: { namespace: Sylius\Bundle\InventoryBundle, psr4_prefix: Sylius\Bundle\InventoryBundle, spec_path: src/Sylius/Bundle/InventoryBundle, src_path: src/Sylius/Bundle/InventoryBundle }
|
||||
LocaleBundle: { namespace: Sylius\Bundle\LocaleBundle, psr4_prefix: Sylius\Bundle\LocaleBundle, spec_path: src/Sylius/Bundle/LocaleBundle, src_path: src/Sylius/Bundle/LocaleBundle }
|
||||
MailerBundle: { namespace: Sylius\Bundle\MailerBundle, psr4_prefix: Sylius\Bundle\MailerBundle, spec_path: src/Sylius/Bundle/MailerBundle, src_path: src/Sylius/Bundle/MailerBundle }
|
||||
MoneyBundle: { namespace: Sylius\Bundle\MoneyBundle, psr4_prefix: Sylius\Bundle\MoneyBundle, spec_path: src/Sylius/Bundle/MoneyBundle, src_path: src/Sylius/Bundle/MoneyBundle }
|
||||
OrderBundle: { namespace: Sylius\Bundle\OrderBundle, psr4_prefix: Sylius\Bundle\OrderBundle, spec_path: src/Sylius/Bundle/OrderBundle, src_path: src/Sylius/Bundle/OrderBundle }
|
||||
PaymentBundle: { namespace: Sylius\Bundle\PaymentBundle, psr4_prefix: Sylius\Bundle\PaymentBundle, spec_path: src/Sylius/Bundle/PaymentBundle, src_path: src/Sylius/Bundle/PaymentBundle }
|
||||
|
|
|
|||
8
src/Sylius/Bundle/MailerBundle/.gitignore
vendored
8
src/Sylius/Bundle/MailerBundle/.gitignore
vendored
|
|
@ -1,8 +0,0 @@
|
|||
vendor/
|
||||
bin/
|
||||
|
||||
composer.phar
|
||||
composer.lock
|
||||
|
||||
test/app/cache
|
||||
test/app/logs
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\MailerBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
||||
final class Configuration implements ConfigurationInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfigTreeBuilder(): TreeBuilder
|
||||
{
|
||||
$treeBuilder = new TreeBuilder();
|
||||
$rootNode = $treeBuilder->root('sylius_mailer');
|
||||
|
||||
$rootNode
|
||||
->children()
|
||||
->scalarNode('sender_adapter')->defaultValue('sylius.email_sender.adapter.swiftmailer')->end()
|
||||
->scalarNode('renderer_adapter')->defaultValue('sylius.email_renderer.adapter.twig')->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
$this->addEmailsSection($rootNode);
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayNodeDefinition $node
|
||||
*/
|
||||
private function addEmailsSection(ArrayNodeDefinition $node): void
|
||||
{
|
||||
$node
|
||||
->children()
|
||||
->arrayNode('sender')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('name')->defaultValue('Example.com Store')->end()
|
||||
->scalarNode('address')->defaultValue('no-reply@example.com')->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('emails')
|
||||
->useAttributeAsKey('code')
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('subject')->cannotBeEmpty()->end()
|
||||
->scalarNode('template')->cannotBeEmpty()->end()
|
||||
->booleanNode('enabled')->defaultTrue()->end()
|
||||
->arrayNode('sender')
|
||||
->children()
|
||||
->scalarNode('name')->end()
|
||||
->scalarNode('address')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('templates')
|
||||
->useAttributeAsKey('name')
|
||||
->scalarPrototype()->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\MailerBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
final class SyliusMailerExtension extends Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $config, ContainerBuilder $container): void
|
||||
{
|
||||
$config = $this->processConfiguration($this->getConfiguration([], $container), $config);
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
|
||||
|
||||
$configFiles = [
|
||||
'services.xml',
|
||||
];
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
}
|
||||
|
||||
$container->setAlias('sylius.email_sender.adapter', $config['sender_adapter']);
|
||||
$container->setAlias('sylius.email_renderer.adapter', $config['renderer_adapter']);
|
||||
|
||||
$container->setParameter('sylius.mailer.sender_name', $config['sender']['name']);
|
||||
$container->setParameter('sylius.mailer.sender_address', $config['sender']['address']);
|
||||
|
||||
$templates = $config['templates'] ?? ['Default' => 'SyliusMailerBundle::default.html.twig'];
|
||||
|
||||
$container->setParameter('sylius.mailer.emails', $config['emails']);
|
||||
$container->setParameter('sylius.mailer.templates', $templates);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
Copyright (c) 2011-2018 Paweł Jędrzejewski
|
||||
|
||||
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.
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
SyliusMailerBundle [](http://travis-ci.org/Sylius/SyliusMailerBundle)
|
||||
==================
|
||||
|
||||
[**Symfony2**](http://symfony.com) integration of Sylius Mailer component.
|
||||
|
||||
Sylius
|
||||
------
|
||||
|
||||
**Sylius** - Modern ecommerce for Symfony2. Visit [Sylius.org](http://sylius.com).
|
||||
|
||||
Sylius
|
||||
------
|
||||
|
||||

|
||||
|
||||
Sylius is an Open Source eCommerce solution built from decoupled components with powerful API and the highest quality code. [Read more on sylius.com](http://sylius.com).
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
Documentation is available on [**docs.sylius.com**](http://docs.sylius.com/en/latest/components_and_bundles/bundles/SyliusMailerBundle/index.html).
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
[This page](http://docs.sylius.com/en/latest/contributing/index.html) contains all the information about contributing to Sylius.
|
||||
|
||||
Follow Sylius' Development
|
||||
--------------------------
|
||||
|
||||
If you want to keep up with the updates and latest features, follow us on the following channels:
|
||||
|
||||
* [Official Blog](https://sylius.com/blog)
|
||||
* [Sylius on Twitter](https://twitter.com/Sylius)
|
||||
* [Sylius on Facebook](https://facebook.com/SyliusEcommerce)
|
||||
|
||||
Bug tracking
|
||||
------------
|
||||
|
||||
Sylius uses [GitHub issues](https://github.com/Sylius/Sylius/issues).
|
||||
If you have found bug, please create an issue.
|
||||
|
||||
MIT License
|
||||
-----------
|
||||
|
||||
License can be found [here](https://github.com/Sylius/Sylius/blob/master/LICENSE).
|
||||
|
||||
Authors
|
||||
-------
|
||||
|
||||
The bundle was originally created by [Paweł Jędrzejewski](http://pjedrzejewski.com).
|
||||
See the list of [contributors](https://github.com/Sylius/Sylius/contributors).
|
||||
|
|
@ -1,105 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\MailerBundle\Renderer\Adapter;
|
||||
|
||||
use Sylius\Component\Mailer\Event\EmailRenderEvent;
|
||||
use Sylius\Component\Mailer\Model\EmailInterface;
|
||||
use Sylius\Component\Mailer\Renderer\Adapter\AbstractAdapter;
|
||||
use Sylius\Component\Mailer\Renderer\RenderedEmail;
|
||||
use Sylius\Component\Mailer\SyliusMailerEvents;
|
||||
|
||||
class EmailTwigAdapter extends AbstractAdapter
|
||||
{
|
||||
/**
|
||||
* @var \Twig_Environment
|
||||
*/
|
||||
protected $twig;
|
||||
|
||||
/**
|
||||
* @param \Twig_Environment $twig
|
||||
*/
|
||||
public function __construct(\Twig_Environment $twig)
|
||||
{
|
||||
$this->twig = $twig;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render(EmailInterface $email, array $data = []): RenderedEmail
|
||||
{
|
||||
$renderedEmail = $this->getRenderedEmail($email, $data);
|
||||
|
||||
/** @var EmailRenderEvent $event */
|
||||
$event = $this->dispatcher->dispatch(
|
||||
SyliusMailerEvents::EMAIL_PRE_RENDER,
|
||||
new EmailRenderEvent($renderedEmail)
|
||||
);
|
||||
|
||||
return $event->getRenderedEmail();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EmailInterface $email
|
||||
* @param array $data
|
||||
*
|
||||
* @return RenderedEmail
|
||||
*/
|
||||
private function getRenderedEmail(EmailInterface $email, array $data): RenderedEmail
|
||||
{
|
||||
if (null !== $email->getTemplate()) {
|
||||
return $this->provideEmailWithTemplate($email, $data);
|
||||
}
|
||||
|
||||
return $this->provideEmailWithoutTemplate($email, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EmailInterface $email
|
||||
* @param array $data
|
||||
*
|
||||
* @return RenderedEmail
|
||||
*/
|
||||
private function provideEmailWithTemplate(EmailInterface $email, array $data): RenderedEmail
|
||||
{
|
||||
$data = $this->twig->mergeGlobals($data);
|
||||
|
||||
/** @var \Twig_Template $template */
|
||||
$template = $this->twig->loadTemplate($email->getTemplate());
|
||||
|
||||
$subject = $template->renderBlock('subject', $data);
|
||||
$body = $template->renderBlock('body', $data);
|
||||
|
||||
return new RenderedEmail($subject, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EmailInterface $email
|
||||
* @param array $data
|
||||
*
|
||||
* @return RenderedEmail
|
||||
*/
|
||||
private function provideEmailWithoutTemplate(EmailInterface $email, array $data): RenderedEmail
|
||||
{
|
||||
$twig = new \Twig_Environment(new \Twig_Loader_Array([]));
|
||||
|
||||
$subjectTemplate = $twig->createTemplate($email->getSubject());
|
||||
$bodyTemplate = $twig->createTemplate($email->getContent());
|
||||
|
||||
$subject = $subjectTemplate->render($data);
|
||||
$body = $bodyTemplate->render($data);
|
||||
|
||||
return new RenderedEmail($subject, $body);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
|
||||
This file is part of the Sylius package.
|
||||
|
||||
(c) Paweł Jędrzejewski
|
||||
|
||||
For the full copyright and license information, please view the LICENSE
|
||||
file that was distributed with this source code.
|
||||
|
||||
-->
|
||||
|
||||
<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="sylius.factory.email" class="Sylius\Component\Mailer\Factory\EmailFactory" />
|
||||
|
||||
<service id="sylius.email_provider" class="Sylius\Component\Mailer\Provider\EmailProvider">
|
||||
<argument type="service" id="sylius.factory.email" />
|
||||
<argument>%sylius.mailer.emails%</argument>
|
||||
</service>
|
||||
<service id="sylius.email_sender" class="Sylius\Component\Mailer\Sender\Sender">
|
||||
<argument type="service" id="sylius.email_renderer.adapter" />
|
||||
<argument type="service" id="sylius.email_sender.adapter" />
|
||||
<argument type="service" id="sylius.email_provider" />
|
||||
<argument type="service" id="sylius.mailer.default_settings_provider" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.mailer.default_settings_provider" class="Sylius\Component\Mailer\Provider\DefaultSettingsProvider">
|
||||
<argument>%sylius.mailer.sender_name%</argument>
|
||||
<argument>%sylius.mailer.sender_address%</argument>
|
||||
</service>
|
||||
|
||||
<service id="sylius.email_renderer.adapter.abstract" class="Sylius\Component\Mailer\Renderer\Adapter\AbstractAdapter" abstract="true">
|
||||
<call method="setEventDispatcher">
|
||||
<argument type="service" id="event_dispatcher" />
|
||||
</call>
|
||||
</service>
|
||||
<service id="sylius.email_renderer.adapter.twig" class="Sylius\Bundle\MailerBundle\Renderer\Adapter\EmailTwigAdapter" parent="sylius.email_renderer.adapter.abstract">
|
||||
<argument type="service" id="twig" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.email_sender.adapter.abstract" class="Sylius\Component\Mailer\Sender\Adapter\AbstractAdapter" abstract="true">
|
||||
<call method="setEventDispatcher">
|
||||
<argument type="service" id="event_dispatcher" />
|
||||
</call>
|
||||
</service>
|
||||
<service id="sylius.email_sender.adapter.swiftmailer" class="Sylius\Bundle\MailerBundle\Sender\Adapter\SwiftMailerAdapter" parent="sylius.email_sender.adapter.abstract">
|
||||
<argument type="service" id="mailer" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\MailerBundle\Sender\Adapter;
|
||||
|
||||
use Sylius\Component\Mailer\Event\EmailSendEvent;
|
||||
use Sylius\Component\Mailer\Model\EmailInterface;
|
||||
use Sylius\Component\Mailer\Renderer\RenderedEmail;
|
||||
use Sylius\Component\Mailer\Sender\Adapter\AbstractAdapter;
|
||||
use Sylius\Component\Mailer\SyliusMailerEvents;
|
||||
|
||||
class SwiftMailerAdapter extends AbstractAdapter
|
||||
{
|
||||
/**
|
||||
* @var \Swift_Mailer
|
||||
*/
|
||||
protected $mailer;
|
||||
|
||||
/**
|
||||
* @param \Swift_Mailer $mailer
|
||||
*/
|
||||
public function __construct(\Swift_Mailer $mailer)
|
||||
{
|
||||
$this->mailer = $mailer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function send(
|
||||
array $recipients,
|
||||
string $senderAddress,
|
||||
string $senderName,
|
||||
RenderedEmail $renderedEmail,
|
||||
EmailInterface $email,
|
||||
array $data,
|
||||
array $attachments = [],
|
||||
array $replyTo = []
|
||||
): void {
|
||||
$message = (new \Swift_Message())
|
||||
->setSubject($renderedEmail->getSubject())
|
||||
->setFrom([$senderAddress => $senderName])
|
||||
->setTo($recipients)
|
||||
->setReplyTo($replyTo);
|
||||
|
||||
$message->setBody($renderedEmail->getBody(), 'text/html');
|
||||
|
||||
foreach ($attachments as $attachment) {
|
||||
$file = \Swift_Attachment::fromPath($attachment);
|
||||
|
||||
$message->attach($file);
|
||||
}
|
||||
|
||||
$emailSendEvent = new EmailSendEvent($message, $email, $data, $recipients, $replyTo);
|
||||
|
||||
$this->dispatcher->dispatch(SyliusMailerEvents::EMAIL_PRE_SEND, $emailSendEvent);
|
||||
|
||||
$this->mailer->send($message);
|
||||
|
||||
$this->dispatcher->dispatch(SyliusMailerEvents::EMAIL_POST_SEND, $emailSendEvent);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\MailerBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
final class SyliusMailerBundle extends Bundle
|
||||
{
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
{
|
||||
"name": "sylius/mailer-bundle",
|
||||
"type": "symfony-bundle",
|
||||
"description": "Mailers and e-mail template management for Symfony projects.",
|
||||
"keywords": ["mailer", "email", "swiftmailer"],
|
||||
"homepage": "http://sylius.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Paweł Jędrzejewski",
|
||||
"homepage": "http://pjedrzejewski.com"
|
||||
},
|
||||
{
|
||||
"name": "Sylius project",
|
||||
"homepage": "http://sylius.com"
|
||||
},
|
||||
{
|
||||
"name": "Community contributions",
|
||||
"homepage": "http://github.com/Sylius/Sylius/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.1",
|
||||
|
||||
"sylius/mailer": "^1.1",
|
||||
"symfony/framework-bundle": "^3.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpspec/phpspec": "^4.0",
|
||||
"phpunit/phpunit": "^6.5",
|
||||
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
|
||||
"symfony/browser-kit": "^3.4",
|
||||
"symfony/dependency-injection": "^3.4",
|
||||
"symfony/swiftmailer-bundle": "^3.1",
|
||||
"symfony/templating": "^3.4",
|
||||
"symfony/twig-bundle": "^3.4"
|
||||
},
|
||||
"config": {
|
||||
"bin-dir": "bin"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Sylius\\Bundle\\MailerBundle\\": "" }
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Sylius\\Bundle\\MailerBundle\\spec\\": "spec/",
|
||||
"AppBundle\\": "test/src/AppBundle/"
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"repositories": [
|
||||
{
|
||||
"type": "path",
|
||||
"url": "../../*/*"
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.1-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
suites:
|
||||
main:
|
||||
namespace: Sylius\Bundle\MailerBundle
|
||||
psr4_prefix: Sylius\Bundle\MailerBundle
|
||||
src_path: .
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
|
||||
backupGlobals="false"
|
||||
colors="true"
|
||||
bootstrap="vendor/autoload.php"
|
||||
>
|
||||
<php>
|
||||
<server name="KERNEL_DIR" value="test/app/" />
|
||||
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true" />
|
||||
</php>
|
||||
<testsuites>
|
||||
<testsuite name="SyliusMailerBundle Test Suite">
|
||||
<directory>./test/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace spec\Sylius\Bundle\MailerBundle\Renderer\Adapter;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Sylius\Component\Mailer\Event\EmailRenderEvent;
|
||||
use Sylius\Component\Mailer\Model\EmailInterface;
|
||||
use Sylius\Component\Mailer\Renderer\Adapter\AbstractAdapter;
|
||||
use Sylius\Component\Mailer\Renderer\RenderedEmail;
|
||||
use Sylius\Component\Mailer\SyliusMailerEvents;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
final class EmailTwigAdapterSpec extends ObjectBehavior
|
||||
{
|
||||
function let(\Twig_Environment $twig): void
|
||||
{
|
||||
$this->beConstructedWith($twig);
|
||||
}
|
||||
|
||||
function it_is_an_adapter(): void
|
||||
{
|
||||
$this->shouldHaveType(AbstractAdapter::class);
|
||||
}
|
||||
|
||||
function it_renders_an_email(
|
||||
\Twig_Environment $twig,
|
||||
\Twig_Template $template,
|
||||
EmailInterface $email,
|
||||
EmailRenderEvent $event,
|
||||
EventDispatcherInterface $dispatcher,
|
||||
RenderedEmail $renderedEmail
|
||||
): void {
|
||||
$this->setEventDispatcher($dispatcher);
|
||||
|
||||
$twig->mergeGlobals([])->shouldBeCalled()->willReturn([]);
|
||||
|
||||
$email->getTemplate()->shouldBeCalled()->willReturn('MyTemplate');
|
||||
$twig->loadTemplate('MyTemplate')->shouldBeCalled()->willReturn($template);
|
||||
|
||||
$template->renderBlock('subject', [])->willReturn('template');
|
||||
$template->renderBlock('body', [])->willReturn('body');
|
||||
|
||||
$dispatcher->dispatch(
|
||||
SyliusMailerEvents::EMAIL_PRE_RENDER,
|
||||
Argument::type(EmailRenderEvent::class)
|
||||
)->shouldBeCalled()->willReturn($event);
|
||||
|
||||
$event->getRenderedEmail()->shouldBeCalled()->willReturn($renderedEmail);
|
||||
|
||||
$this->render($email, [])->shouldReturn($renderedEmail);
|
||||
}
|
||||
|
||||
function it_creates_and_renders_an_email(
|
||||
EmailInterface $email,
|
||||
EmailRenderEvent $event,
|
||||
EventDispatcherInterface $dispatcher,
|
||||
RenderedEmail $renderedEmail
|
||||
): void {
|
||||
$this->setEventDispatcher($dispatcher);
|
||||
|
||||
$email->getTemplate()->shouldBeCalled()->willReturn(null);
|
||||
$email->getSubject()->shouldBeCalled()->willReturn('subject');
|
||||
$email->getContent()->shouldBeCalled()->willReturn('content');
|
||||
|
||||
$dispatcher->dispatch(
|
||||
SyliusMailerEvents::EMAIL_PRE_RENDER,
|
||||
Argument::type(EmailRenderEvent::class)
|
||||
)->shouldBeCalled()->willReturn($event);
|
||||
|
||||
$event->getRenderedEmail()->shouldBeCalled()->willReturn($renderedEmail);
|
||||
|
||||
$this->render($email, [])->shouldReturn($renderedEmail);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace spec\Sylius\Bundle\MailerBundle\Sender\Adapter;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Sylius\Component\Mailer\Event\EmailSendEvent;
|
||||
use Sylius\Component\Mailer\Model\EmailInterface;
|
||||
use Sylius\Component\Mailer\Renderer\RenderedEmail;
|
||||
use Sylius\Component\Mailer\Sender\Adapter\AbstractAdapter;
|
||||
use Sylius\Component\Mailer\SyliusMailerEvents;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
final class SwiftMailerAdapterSpec extends ObjectBehavior
|
||||
{
|
||||
function let(\Swift_Mailer $mailer): void
|
||||
{
|
||||
$this->beConstructedWith($mailer);
|
||||
}
|
||||
|
||||
function it_is_an_adapter(): void
|
||||
{
|
||||
$this->shouldHaveType(AbstractAdapter::class);
|
||||
}
|
||||
|
||||
function it_sends_an_email(
|
||||
\Swift_Mailer $mailer,
|
||||
EmailInterface $email,
|
||||
EventDispatcherInterface $dispatcher,
|
||||
RenderedEmail $renderedEmail
|
||||
): void {
|
||||
$this->setEventDispatcher($dispatcher);
|
||||
|
||||
$renderedEmail->getSubject()->shouldBeCalled()->willReturn('subject');
|
||||
$renderedEmail->getBody()->shouldBeCalled()->willReturn('body');
|
||||
|
||||
$dispatcher->dispatch(
|
||||
SyliusMailerEvents::EMAIL_PRE_SEND,
|
||||
Argument::type(EmailSendEvent::class)
|
||||
)->shouldBeCalled();
|
||||
|
||||
$mailer->send(Argument::type('\Swift_Message'))->shouldBeCalled();
|
||||
|
||||
$dispatcher->dispatch(
|
||||
SyliusMailerEvents::EMAIL_POST_SEND,
|
||||
Argument::type(EmailSendEvent::class)
|
||||
)->shouldBeCalled();
|
||||
|
||||
$this->send(
|
||||
['pawel@sylius.com'],
|
||||
'arnaud@sylius.com',
|
||||
'arnaud',
|
||||
$renderedEmail,
|
||||
$email,
|
||||
[]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
|
||||
class AppKernel extends Kernel
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function registerBundles(): array
|
||||
{
|
||||
return [
|
||||
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
|
||||
new Sylius\Bundle\MailerBundle\SyliusMailerBundle(),
|
||||
new Symfony\Bundle\TwigBundle\TwigBundle(),
|
||||
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function registerContainerConfiguration(LoaderInterface $loader): void
|
||||
{
|
||||
$loader->load(__DIR__ . '/config/config.yml');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getContainerBaseClass(): string
|
||||
{
|
||||
if ('test' === $this->environment) {
|
||||
return MockerContainer::class;
|
||||
}
|
||||
|
||||
return parent::getContainerBaseClass();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
imports:
|
||||
- { resource: "@SyliusMailerBundle/test/app/config/parameters.yml" }
|
||||
|
||||
framework:
|
||||
assets: false
|
||||
secret: "%secret%"
|
||||
templating:
|
||||
engines: ['twig']
|
||||
default_locale: "%locale%"
|
||||
http_method_override: true
|
||||
test: ~
|
||||
|
||||
twig:
|
||||
debug: "%kernel.debug%"
|
||||
strict_variables: "%kernel.debug%"
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
parameters:
|
||||
locale: en_US
|
||||
secret: "Three can keep a secret, if two of them are dead."
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
require_once __DIR__ . "/../../vendor/autoload.php";
|
||||
require_once __DIR__.'/AppKernel.php';
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
|
||||
$input = new ArgvInput();
|
||||
|
||||
$application = new Application(new AppKernel('test', true));
|
||||
$application->run($input);
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\MailerBundle\Tests;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
final class SyliusMailerBundleTest extends WebTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function its_services_are_initializable(): void
|
||||
{
|
||||
/** @var ContainerInterface $container */
|
||||
$container = self::createClient()->getContainer();
|
||||
|
||||
$services = $container->getServiceIds();
|
||||
|
||||
$services = array_filter($services, function ($serviceId) {
|
||||
return 0 === strpos($serviceId, 'sylius.');
|
||||
});
|
||||
|
||||
foreach ($services as $id) {
|
||||
$container->get($id);
|
||||
}
|
||||
}
|
||||
}
|
||||
5
src/Sylius/Component/Mailer/.gitignore
vendored
5
src/Sylius/Component/Mailer/.gitignore
vendored
|
|
@ -1,5 +0,0 @@
|
|||
vendor/
|
||||
bin/
|
||||
|
||||
composer.phar
|
||||
composer.lock
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Mailer\Event;
|
||||
|
||||
use Sylius\Component\Mailer\Renderer\RenderedEmail;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
class EmailRenderEvent extends Event
|
||||
{
|
||||
/**
|
||||
* @var RenderedEmail
|
||||
*/
|
||||
protected $renderedEmail;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $recipients;
|
||||
|
||||
/**
|
||||
* @param RenderedEmail $renderedEmail
|
||||
* @param array $recipients
|
||||
*/
|
||||
public function __construct(RenderedEmail $renderedEmail, array $recipients = [])
|
||||
{
|
||||
$this->renderedEmail = $renderedEmail;
|
||||
$this->recipients = $recipients;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RenderedEmail
|
||||
*/
|
||||
public function getRenderedEmail(): RenderedEmail
|
||||
{
|
||||
return $this->renderedEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RenderedEmail $renderedEmail
|
||||
*/
|
||||
public function setRenderedEmail(RenderedEmail $renderedEmail): void
|
||||
{
|
||||
$this->renderedEmail = $renderedEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getRecipients(): array
|
||||
{
|
||||
return $this->recipients;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $recipients
|
||||
*/
|
||||
public function setRecipients(array $recipients): void
|
||||
{
|
||||
$this->recipients = $recipients;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Mailer\Event;
|
||||
|
||||
use Sylius\Component\Mailer\Model\EmailInterface;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
final class EmailSendEvent extends Event
|
||||
{
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $message;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $recipients;
|
||||
|
||||
/**
|
||||
* @var EmailInterface
|
||||
*/
|
||||
protected $email;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $replyTo;
|
||||
|
||||
/**
|
||||
* @param mixed $message
|
||||
* @param array $recipients
|
||||
* @param EmailInterface $email
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct($message, EmailInterface $email, array $data, array $recipients = [], array $replyTo = [])
|
||||
{
|
||||
$this->message = $message;
|
||||
$this->email = $email;
|
||||
$this->data = $data;
|
||||
$this->recipients = $recipients;
|
||||
$this->replyTo = $replyTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getRecipients(): array
|
||||
{
|
||||
return $this->recipients;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EmailInterface
|
||||
*/
|
||||
public function getEmail(): EmailInterface
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMessage()
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getData(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getReplyTo(): array
|
||||
{
|
||||
return $this->replyTo;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Mailer\Factory;
|
||||
|
||||
use Sylius\Component\Mailer\Model\Email;
|
||||
use Sylius\Component\Mailer\Model\EmailInterface;
|
||||
|
||||
class EmailFactory implements EmailFactoryInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createNew(): EmailInterface
|
||||
{
|
||||
return new Email();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Mailer\Factory;
|
||||
|
||||
use Sylius\Component\Mailer\Model\EmailInterface;
|
||||
|
||||
interface EmailFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @return EmailInterface
|
||||
*/
|
||||
public function createNew(): EmailInterface;
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
Copyright (c) 2011-2018 Paweł Jędrzejewski
|
||||
|
||||
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.
|
||||
|
|
@ -1,187 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Mailer\Model;
|
||||
|
||||
final class Email implements EmailInterface
|
||||
{
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $code;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $enabled = true;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $subject;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $content;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $template;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $senderName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $senderAddress;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCode(): ?string
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setCode(string $code): void
|
||||
{
|
||||
$this->code = $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $enabled
|
||||
*/
|
||||
public function setEnabled(bool $enabled): void
|
||||
{
|
||||
$this->enabled = $enabled;
|
||||
}
|
||||
|
||||
public function enable(): void
|
||||
{
|
||||
$this->enabled = true;
|
||||
}
|
||||
|
||||
public function disable(): void
|
||||
{
|
||||
$this->enabled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSubject(): ?string
|
||||
{
|
||||
return $this->subject;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setSubject(string $subject): void
|
||||
{
|
||||
$this->subject = $subject;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getContent(): ?string
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setContent(string $content): void
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTemplate(): ?string
|
||||
{
|
||||
return $this->template;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setTemplate(string $template): void
|
||||
{
|
||||
$this->template = $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSenderName(): ?string
|
||||
{
|
||||
return $this->senderName;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setSenderName(string $senderName): void
|
||||
{
|
||||
$this->senderName = $senderName;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSenderAddress(): ?string
|
||||
{
|
||||
return $this->senderAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setSenderAddress(string $senderAddress): void
|
||||
{
|
||||
$this->senderAddress = $senderAddress;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Mailer\Model;
|
||||
|
||||
interface EmailInterface
|
||||
{
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCode(): ?string;
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*/
|
||||
public function setCode(string $code): void;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled(): bool;
|
||||
|
||||
/**
|
||||
* @param bool $enabled
|
||||
*/
|
||||
public function setEnabled(bool $enabled): void;
|
||||
|
||||
public function enable(): void;
|
||||
|
||||
public function disable(): void;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSubject(): ?string;
|
||||
|
||||
/**
|
||||
* @param string $subject
|
||||
*/
|
||||
public function setSubject(string $subject): void;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getContent(): ?string;
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
*/
|
||||
public function setContent(string $content);
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTemplate(): ?string;
|
||||
|
||||
/**
|
||||
* @param string $template
|
||||
*/
|
||||
public function setTemplate(string $template): void;
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSenderName(): ?string;
|
||||
|
||||
/**
|
||||
* @param string $senderName
|
||||
*/
|
||||
public function setSenderName(string $senderName): void;
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSenderAddress(): ?string;
|
||||
|
||||
/**
|
||||
* @param string $senderAddress
|
||||
*/
|
||||
public function setSenderAddress(string $senderAddress): void;
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Mailer\Provider;
|
||||
|
||||
final class DefaultSettingsProvider implements DefaultSettingsProviderInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $senderName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $senderAddress;
|
||||
|
||||
/**
|
||||
* @param string $senderName
|
||||
* @param string $senderAddress
|
||||
*/
|
||||
public function __construct(string $senderName, string $senderAddress)
|
||||
{
|
||||
$this->senderName = $senderName;
|
||||
$this->senderAddress = $senderAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSenderName(): string
|
||||
{
|
||||
return $this->senderName;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSenderAddress(): string
|
||||
{
|
||||
return $this->senderAddress;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Mailer\Provider;
|
||||
|
||||
interface DefaultSettingsProviderInterface
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSenderName(): string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSenderAddress(): string;
|
||||
}
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Mailer\Provider;
|
||||
|
||||
use Sylius\Component\Mailer\Factory\EmailFactoryInterface;
|
||||
use Sylius\Component\Mailer\Model\EmailInterface;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final class EmailProvider implements EmailProviderInterface
|
||||
{
|
||||
/**
|
||||
* @var EmailFactoryInterface
|
||||
*/
|
||||
private $emailFactory;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $configuration;
|
||||
|
||||
/**
|
||||
* @param EmailFactoryInterface $emailFactory
|
||||
* @param array $configuration
|
||||
*/
|
||||
public function __construct(
|
||||
EmailFactoryInterface $emailFactory,
|
||||
array $configuration
|
||||
) {
|
||||
$this->emailFactory = $emailFactory;
|
||||
$this->configuration = $configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmail(string $code): EmailInterface
|
||||
{
|
||||
return $this->getEmailFromConfiguration($code);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return EmailInterface
|
||||
*/
|
||||
private function getEmailFromConfiguration(string $code): EmailInterface
|
||||
{
|
||||
Assert::keyExists($this->configuration, $code, sprintf('Email with code "%s" does not exist!', $code));
|
||||
|
||||
/** @var EmailInterface $email */
|
||||
$email = $this->emailFactory->createNew();
|
||||
$configuration = $this->configuration[$code];
|
||||
|
||||
$email->setCode($code);
|
||||
$email->setSubject($configuration['subject']);
|
||||
$email->setTemplate($configuration['template']);
|
||||
|
||||
if (isset($configuration['enabled']) && false === $configuration['enabled']) {
|
||||
$email->setEnabled(false);
|
||||
}
|
||||
if (isset($configuration['sender']['name'])) {
|
||||
$email->setSenderName($configuration['sender']['name']);
|
||||
}
|
||||
if (isset($configuration['sender']['address'])) {
|
||||
$email->setSenderAddress($configuration['sender']['address']);
|
||||
}
|
||||
|
||||
return $email;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Mailer\Provider;
|
||||
|
||||
use Sylius\Component\Mailer\Model\EmailInterface;
|
||||
|
||||
interface EmailProviderInterface
|
||||
{
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return EmailInterface
|
||||
*/
|
||||
public function getEmail(string $code): EmailInterface;
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
Mailer Component [](http://travis-ci.org/Sylius/Mailer)
|
||||
================
|
||||
|
||||
Abstraction layer for sending and management of e-mail templates.
|
||||
|
||||
Sylius
|
||||
------
|
||||
|
||||

|
||||
|
||||
Sylius is an Open Source eCommerce solution built from decoupled components with powerful API and the highest quality code. [Read more on sylius.com](http://sylius.com).
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
Documentation is available on [**docs.sylius.com**](http://docs.sylius.com/en/latest/components_and_bundles/components/Mailer/index.html).
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
[This page](http://docs.sylius.com/en/latest/contributing/index.html) contains all the information about contributing to Sylius.
|
||||
|
||||
Follow Sylius' Development
|
||||
--------------------------
|
||||
|
||||
If you want to keep up with the updates and latest features, follow us on the following channels:
|
||||
|
||||
* [Official Blog](https://sylius.com/blog)
|
||||
* [Sylius on Twitter](https://twitter.com/Sylius)
|
||||
* [Sylius on Facebook](https://facebook.com/SyliusEcommerce)
|
||||
|
||||
Bug tracking
|
||||
------------
|
||||
|
||||
Sylius uses [GitHub issues](https://github.com/Sylius/Sylius/issues).
|
||||
If you have found bug, please create an issue.
|
||||
|
||||
MIT License
|
||||
-----------
|
||||
|
||||
License can be found [here](https://github.com/Sylius/Sylius/blob/master/LICENSE).
|
||||
|
||||
Authors
|
||||
-------
|
||||
|
||||
The component was originally created by [Paweł Jędrzejewski](http://pjedrzejewski.com).
|
||||
See the list of [contributors](https://github.com/Sylius/Mailer/contributors).
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Mailer\Renderer\Adapter;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
abstract class AbstractAdapter implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
/**
|
||||
* @param EventDispatcherInterface $dispatcher
|
||||
*/
|
||||
public function setEventDispatcher(EventDispatcherInterface $dispatcher): void
|
||||
{
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Mailer\Renderer\Adapter;
|
||||
|
||||
use Sylius\Component\Mailer\Model\EmailInterface;
|
||||
use Sylius\Component\Mailer\Renderer\RenderedEmail;
|
||||
|
||||
interface AdapterInterface
|
||||
{
|
||||
/**
|
||||
* @param EmailInterface $email
|
||||
* @param array $data
|
||||
*
|
||||
* @return RenderedEmail
|
||||
*/
|
||||
public function render(EmailInterface $email, array $data = []): RenderedEmail;
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Mailer\Renderer;
|
||||
|
||||
class RenderedEmail
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $subject;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $body;
|
||||
|
||||
/**
|
||||
* @param string $subject
|
||||
* @param string $body
|
||||
*/
|
||||
public function __construct(string $subject, string $body)
|
||||
{
|
||||
$this->subject = $subject;
|
||||
$this->body = $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSubject(): string
|
||||
{
|
||||
return $this->subject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $subject
|
||||
*/
|
||||
public function setSubject(string $subject): void
|
||||
{
|
||||
$this->subject = $subject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getBody(): string
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $body
|
||||
*/
|
||||
public function setBody(string $body): void
|
||||
{
|
||||
$this->body = $body;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Mailer\Sender\Adapter;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
abstract class AbstractAdapter implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
/**
|
||||
* @param EventDispatcherInterface $dispatcher
|
||||
*/
|
||||
public function setEventDispatcher(EventDispatcherInterface $dispatcher): void
|
||||
{
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Mailer\Sender\Adapter;
|
||||
|
||||
use Sylius\Component\Mailer\Model\EmailInterface;
|
||||
use Sylius\Component\Mailer\Renderer\RenderedEmail;
|
||||
|
||||
interface AdapterInterface
|
||||
{
|
||||
/**
|
||||
* @param array $recipients
|
||||
* @param string $senderAddress
|
||||
* @param string $senderName
|
||||
* @param RenderedEmail $renderedEmail
|
||||
* @param EmailInterface $email
|
||||
* @param array $data
|
||||
* @param array $attachments
|
||||
* @param array $replyTo
|
||||
*/
|
||||
public function send(
|
||||
array $recipients,
|
||||
string $senderAddress,
|
||||
string $senderName,
|
||||
RenderedEmail $renderedEmail,
|
||||
EmailInterface $email,
|
||||
array $data,
|
||||
array $attachments = [],
|
||||
array $replyTo = []
|
||||
): void;
|
||||
}
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Mailer\Sender;
|
||||
|
||||
use Sylius\Component\Mailer\Provider\DefaultSettingsProviderInterface;
|
||||
use Sylius\Component\Mailer\Provider\EmailProviderInterface;
|
||||
use Sylius\Component\Mailer\Renderer\Adapter\AdapterInterface as RendererAdapterInterface;
|
||||
use Sylius\Component\Mailer\Sender\Adapter\AdapterInterface as SenderAdapterInterface;
|
||||
|
||||
final class Sender implements SenderInterface
|
||||
{
|
||||
/**
|
||||
* @var RendererAdapterInterface
|
||||
*/
|
||||
private $rendererAdapter;
|
||||
|
||||
/**
|
||||
* @var SenderAdapterInterface
|
||||
*/
|
||||
private $senderAdapter;
|
||||
|
||||
/**
|
||||
* @var EmailProviderInterface
|
||||
*/
|
||||
private $provider;
|
||||
|
||||
/**
|
||||
* @var DefaultSettingsProviderInterface
|
||||
*/
|
||||
private $defaultSettingsProvider;
|
||||
|
||||
/**
|
||||
* @param RendererAdapterInterface $rendererAdapter
|
||||
* @param SenderAdapterInterface $senderAdapter
|
||||
* @param EmailProviderInterface $provider
|
||||
* @param DefaultSettingsProviderInterface $defaultSettingsProvider
|
||||
*/
|
||||
public function __construct(
|
||||
RendererAdapterInterface $rendererAdapter,
|
||||
SenderAdapterInterface $senderAdapter,
|
||||
EmailProviderInterface $provider,
|
||||
DefaultSettingsProviderInterface $defaultSettingsProvider
|
||||
) {
|
||||
$this->senderAdapter = $senderAdapter;
|
||||
$this->rendererAdapter = $rendererAdapter;
|
||||
$this->provider = $provider;
|
||||
$this->defaultSettingsProvider = $defaultSettingsProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function send(string $code, array $recipients, array $data = [], array $attachments = [], array $replyTo = []): void
|
||||
{
|
||||
$email = $this->provider->getEmail($code);
|
||||
|
||||
if (!$email->isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$senderAddress = $email->getSenderAddress() ?: $this->defaultSettingsProvider->getSenderAddress();
|
||||
$senderName = $email->getSenderName() ?: $this->defaultSettingsProvider->getSenderName();
|
||||
|
||||
$renderedEmail = $this->rendererAdapter->render($email, $data);
|
||||
|
||||
$this->senderAdapter->send(
|
||||
$recipients,
|
||||
$senderAddress,
|
||||
$senderName,
|
||||
$renderedEmail,
|
||||
$email,
|
||||
$data,
|
||||
$attachments,
|
||||
$replyTo
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Mailer\Sender;
|
||||
|
||||
interface SenderInterface
|
||||
{
|
||||
/**
|
||||
* @param string $code
|
||||
* @param array $recipients
|
||||
* @param array $data
|
||||
* @param array $attachments
|
||||
* @param array $replyTo
|
||||
*/
|
||||
public function send(string $code, array $recipients, array $data = [], array $attachments = [], array $replyTo = []): void;
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Mailer;
|
||||
|
||||
class SyliusMailerEvents
|
||||
{
|
||||
public const EMAIL_PRE_RENDER = 'sylius.email_rendered';
|
||||
public const EMAIL_PRE_SEND = 'sylius.email_send.pre_send';
|
||||
public const EMAIL_POST_SEND = 'sylius.email_send.post_send';
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
{
|
||||
"name": "sylius/mailer",
|
||||
"type": "library",
|
||||
"description": "Mails management and sending abstraction.",
|
||||
"keywords": ["email", "mails", "notifications"],
|
||||
"homepage": "http://sylius.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Paweł Jędrzejewski",
|
||||
"homepage": "http://pjedrzejewski.com"
|
||||
},
|
||||
{
|
||||
"name": "Sylius project",
|
||||
"homepage": "http://sylius.com"
|
||||
},
|
||||
{
|
||||
"name": "Community contributions",
|
||||
"homepage": "http://github.com/Sylius/Sylius/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.1",
|
||||
|
||||
"webmozart/assert": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpspec/phpspec": "^4.0"
|
||||
},
|
||||
"config": {
|
||||
"bin-dir": "bin"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Sylius\\Component\\Mailer\\": "" }
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": { "Sylius\\Component\\Mailer\\spec\\": "spec/" }
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"repositories": [
|
||||
{
|
||||
"type": "path",
|
||||
"url": "../../*/*"
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.1-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
suites:
|
||||
main:
|
||||
namespace: Sylius\Component\Mailer
|
||||
psr4_prefix: Sylius\Component\Mailer
|
||||
src_path: .
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace spec\Sylius\Component\Mailer\Factory;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Component\Mailer\Factory\EmailFactoryInterface;
|
||||
use Sylius\Component\Mailer\Model\Email;
|
||||
|
||||
final class EmailFactorySpec extends ObjectBehavior
|
||||
{
|
||||
function it_implements_email_factory_interface(): void
|
||||
{
|
||||
$this->shouldImplement(EmailFactoryInterface::class);
|
||||
}
|
||||
|
||||
function it_creates_new_email(): void
|
||||
{
|
||||
$this->createNew()->shouldHaveType(Email::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace spec\Sylius\Component\Mailer\Model;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Component\Mailer\Model\EmailInterface;
|
||||
|
||||
final class EmailSpec extends ObjectBehavior
|
||||
{
|
||||
function it_implements_email_interface(): void
|
||||
{
|
||||
$this->shouldImplement(EmailInterface::class);
|
||||
}
|
||||
|
||||
function it_has_no_code_by_default(): void
|
||||
{
|
||||
$this->getCode()->shouldReturn(null);
|
||||
}
|
||||
|
||||
function its_code_is_mutable(): void
|
||||
{
|
||||
$this->setCode('bar');
|
||||
$this->getCode()->shouldReturn('bar');
|
||||
}
|
||||
|
||||
function its_subject_is_mutable(): void
|
||||
{
|
||||
$this->setSubject('foo');
|
||||
$this->getSubject()->shouldReturn('foo');
|
||||
}
|
||||
|
||||
function its_content_is_mutable(): void
|
||||
{
|
||||
$this->setContent('foo content');
|
||||
$this->getContent()->shouldReturn('foo content');
|
||||
}
|
||||
|
||||
function its_template_is_mutable(): void
|
||||
{
|
||||
$this->setContent('template.html.twig');
|
||||
$this->getContent()->shouldReturn('template.html.twig');
|
||||
}
|
||||
|
||||
function its_sender_name_is_mutable(): void
|
||||
{
|
||||
$this->setSenderName('Example');
|
||||
$this->getSenderName()->shouldReturn('Example');
|
||||
}
|
||||
|
||||
function its_sender_address_is_mutable(): void
|
||||
{
|
||||
$this->setSenderAddress('no-reply@example.com');
|
||||
$this->getSenderAddress()->shouldReturn('no-reply@example.com');
|
||||
}
|
||||
|
||||
function it_is_enabled_by_default(): void
|
||||
{
|
||||
$this->shouldBeEnabled();
|
||||
}
|
||||
|
||||
function it_can_be_disabled(): void
|
||||
{
|
||||
$this->setEnabled(false);
|
||||
$this->shouldNotBeEnabled();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace spec\Sylius\Component\Mailer\Provider;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Component\Mailer\Factory\EmailFactoryInterface;
|
||||
use Sylius\Component\Mailer\Model\EmailInterface;
|
||||
use Sylius\Component\Mailer\Provider\EmailProviderInterface;
|
||||
|
||||
final class EmailProviderSpec extends ObjectBehavior
|
||||
{
|
||||
function let(EmailFactoryInterface $emailFactory): void
|
||||
{
|
||||
$emails = [
|
||||
'user_confirmation' => [
|
||||
'enabled' => false,
|
||||
'subject' => 'Hello test!',
|
||||
'template' => 'SyliusMailerBundle::default.html.twig',
|
||||
'sender' => [
|
||||
'name' => 'John Doe',
|
||||
'address' => 'john@doe.com',
|
||||
],
|
||||
],
|
||||
'order_cancelled' => [
|
||||
'enabled' => false,
|
||||
'subject' => 'Hi test!',
|
||||
'template' => 'SyliusMailerBundle::default.html.twig',
|
||||
'sender' => [
|
||||
'name' => 'Rick Doe',
|
||||
'address' => 'john@doe.com',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->beConstructedWith($emailFactory, $emails);
|
||||
}
|
||||
|
||||
function it_implements_email_provider_interface(): void
|
||||
{
|
||||
$this->shouldImplement(EmailProviderInterface::class);
|
||||
}
|
||||
|
||||
function it_looks_for_an_email_in_configuration_when_it_cannot_be_found_via_repository(
|
||||
EmailInterface $email,
|
||||
EmailFactoryInterface $emailFactory
|
||||
): void {
|
||||
$emailFactory->createNew()->willReturn($email);
|
||||
|
||||
$email->setCode('user_confirmation')->shouldBeCalled();
|
||||
$email->setSubject('Hello test!')->shouldBeCalled();
|
||||
$email->setTemplate('SyliusMailerBundle::default.html.twig')->shouldBeCalled();
|
||||
$email->setSenderName('John Doe')->shouldBeCalled();
|
||||
$email->setSenderAddress('john@doe.com')->shouldBeCalled();
|
||||
$email->setEnabled(false)->shouldBeCalled();
|
||||
|
||||
$this->getEmail('user_confirmation')->shouldReturn($email);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace spec\Sylius\Component\Mailer\Sender;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Component\Mailer\Model\EmailInterface;
|
||||
use Sylius\Component\Mailer\Provider\DefaultSettingsProviderInterface;
|
||||
use Sylius\Component\Mailer\Provider\EmailProviderInterface;
|
||||
use Sylius\Component\Mailer\Renderer\Adapter\AdapterInterface as RendererAdapterInterface;
|
||||
use Sylius\Component\Mailer\Renderer\RenderedEmail;
|
||||
use Sylius\Component\Mailer\Sender\Adapter\AdapterInterface as SenderAdapterInterface;
|
||||
|
||||
final class SenderSpec extends ObjectBehavior
|
||||
{
|
||||
function let(
|
||||
RendererAdapterInterface $rendererAdapter,
|
||||
SenderAdapterInterface $senderAdapter,
|
||||
EmailProviderInterface $provider,
|
||||
DefaultSettingsProviderInterface $defaultSettingsProvider
|
||||
): void {
|
||||
$this->beConstructedWith($rendererAdapter, $senderAdapter, $provider, $defaultSettingsProvider);
|
||||
}
|
||||
|
||||
function it_sends_an_email_through_the_adapter(
|
||||
EmailInterface $email,
|
||||
EmailProviderInterface $provider,
|
||||
RenderedEmail $renderedEmail,
|
||||
RendererAdapterInterface $rendererAdapter,
|
||||
SenderAdapterInterface $senderAdapter
|
||||
): void {
|
||||
$provider->getEmail('bar')->willReturn($email);
|
||||
$email->isEnabled()->willReturn(true);
|
||||
$email->getSenderAddress()->willReturn('sender@example.com');
|
||||
$email->getSenderName()->willReturn('Sender');
|
||||
|
||||
$data = ['foo' => 2];
|
||||
|
||||
$rendererAdapter->render($email, ['foo' => 2])->willReturn($renderedEmail);
|
||||
$senderAdapter->send(['john@example.com'], 'sender@example.com', 'Sender', $renderedEmail, $email, $data, [], [])->shouldBeCalled();
|
||||
|
||||
$this->send('bar', ['john@example.com'], $data, []);
|
||||
}
|
||||
|
||||
function it_does_not_send_disabled_emails(
|
||||
EmailInterface $email,
|
||||
EmailProviderInterface $provider,
|
||||
RendererAdapterInterface $rendererAdapter,
|
||||
SenderAdapterInterface $senderAdapter
|
||||
): void {
|
||||
$provider->getEmail('bar')->willReturn($email);
|
||||
$email->isEnabled()->willReturn(false);
|
||||
|
||||
$rendererAdapter->render($email, ['foo' => 2])->shouldNotBeCalled();
|
||||
$senderAdapter->send(['john@example.com'], 'mail@sylius.com', 'Sylius Mailer', null, $email, [], [], [])->shouldNotBeCalled();
|
||||
|
||||
$this->send('bar', ['john@example.com'], ['foo' => 2], []);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue