From 493ee03b43f4a784f94932469533eaaeba7dcbf9 Mon Sep 17 00:00:00 2001 From: pedro Date: Fri, 8 Dec 2017 09:51:44 +0100 Subject: [PATCH] Prepare v2.0 --- .php_cs | 22 -------- .php_cs.dist | 24 ++++++++ .php_cs.rules.json | 56 +++++++++++++++++++ composer.json | 22 ++++---- phpspec.yml | 2 - .../LocalAttachmentFactorySpec.php | 8 +-- .../RemoteAttachmentFactorySpec.php | 8 +-- .../ConfigurationAwareFactorySpec.php | 29 +++++----- .../Mailer/EventDispatcherMailerSpec.php | 38 ++++++------- .../ChainAttachmentFactory.php | 4 ++ .../RemoteAttachmentFactory.php | 2 +- src/Knp/UniMail/Cid/Resolver.php | 2 +- src/Knp/UniMail/Cid/Resolver/RemoteFile.php | 2 +- .../DependencyInjection/Configuration.php | 3 +- .../DependencyInjection/UniMailExtension.php | 2 +- .../EventListener/AttachmentResolver.php | 2 +- .../EventListener/CidAttachmentMerger.php | 2 +- .../UniMail/EventListener/TwigRenderer.php | 2 +- src/Knp/UniMail/Mail/AbstractMail.php | 8 +-- src/Knp/UniMail/Mail/SwiftMail.php | 6 +- src/Knp/UniMail/Mail/TwigMail.php | 4 +- src/Knp/UniMail/MailFactory.php | 2 +- src/Knp/UniMail/Mailer.php | 4 +- .../UniMail/Mailer/EventDispatcherMailer.php | 24 ++++---- src/Knp/UniMail/Mailer/SwiftMailer.php | 6 +- src/Knp/UniMail/Mailer/TwigMailer.php | 20 ++++--- src/Knp/UniMail/Resources/config/services.yml | 36 ++++++------ 27 files changed, 191 insertions(+), 149 deletions(-) delete mode 100644 .php_cs create mode 100644 .php_cs.dist create mode 100644 .php_cs.rules.json delete mode 100644 phpspec.yml diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 8605612..0000000 --- a/.php_cs +++ /dev/null @@ -1,22 +0,0 @@ -in(__DIR__) - ->exclude('spec') - ->exclude('vendor') -; - -return Symfony\CS\Config\Config::create() - ->setUsingCache(true) - ->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL) - ->fixers([ - 'align_double_arrow', - 'align_equals', - 'concat_with_spaces', - 'logical_not_operators_with_spaces', - 'newline_after_open_tag', - 'ordered_use', - 'phpdoc_order', - ]) - ->finder($finder) -; diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..eeb96b7 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,24 @@ +setRiskyAllowed(true) + ->setRules($rules) + ->setUsingCache(false) + ->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()) + ->setFinder(PhpCsFixer\Finder::create()->in(__DIR__)) +; + +return $config; diff --git a/.php_cs.rules.json b/.php_cs.rules.json new file mode 100644 index 0000000..69b0d59 --- /dev/null +++ b/.php_cs.rules.json @@ -0,0 +1,56 @@ +{ + "@Symfony": true, + "@Symfony:risky": true, + "PedroTroller/forbidden_functions": { + "comment": "@TODO remove it", + "functions": [ + "dump", + "var_dump" + ] + }, + "PedroTroller/line_break_between_method_arguments": { + "max-args": 4, + "max-length": 80 + }, + "PedroTroller/line_break_between_statements": true, + "PedroTroller/phpspec": true, + "PedroTroller/single_line_comment": { + "action": "expanded" + }, + "align_multiline_comment": true, + "array_syntax": { + "syntax": "short" + }, + "binary_operator_spaces": { + "operators": { + "=": "align_single_space_minimal", + "=>": "align_single_space_minimal" + } + }, + "blank_line_before_statement": true, + "combine_consecutive_issets": true, + "combine_consecutive_unsets": true, + "compact_nullable_typehint": true, + "general_phpdoc_annotation_remove": true, + "heredoc_to_nowdoc": true, + "linebreak_after_opening_tag": true, + "list_syntax": { + "syntax": "long" + }, + "mb_str_functions": true, + "no_multiline_whitespace_before_semicolons": true, + "no_null_property_initialization": true, + "no_superfluous_elseif": true, + "no_useless_else": true, + "no_useless_return": true, + "ordered_class_elements": true, + "ordered_imports": true, + "phpdoc_add_missing_param_annotation": { + "only_untyped": true + }, + "phpdoc_order": true, + "phpdoc_types_order": true, + "self_accessor": false, + "semicolon_after_instruction": true, + "single_line_comment_style": true +} \ No newline at end of file diff --git a/composer.json b/composer.json index 67533fc..dd7ee1d 100644 --- a/composer.json +++ b/composer.json @@ -9,17 +9,17 @@ ], "require": { "doctrine/collections": "~1.0", - "swiftmailer/swiftmailer": "~5.0", - "symfony/config": "~2.4", - "symfony/dependency-injection": "~2.4", - "symfony/framework-bundle": "~2.4", - "symfony/http-kernel": "~2.4", - "symfony/security-bundle": "~2.0", - "symfony/twig-bundle": "~2.4" + "swiftmailer/swiftmailer": "~5.0 | ~6.0", + "symfony/config": "~3.0 | ~4.0", + "symfony/dependency-injection": "~3.0 | ~4.0", + "symfony/framework-bundle": "~3.0 | ~4.0", + "symfony/http-kernel": "~3.0 | ~4.0", + "symfony/security-bundle": "~3.0 | ~4.0", + "symfony/twig-bundle": "~3.0 | ~4.0" }, "require-dev": { - "knplabs/phpspec-welldone-extension": "~1.0", - "phpspec/phpspec": "^2.3" + "pedrotroller/php-cs-custom-fixer": "^2.2", + "phpspec/phpspec": "^4.2" }, "autoload": { "psr-0": { @@ -27,11 +27,11 @@ } }, "config": { - "bin-dir": "bin" + "sort-packages": "true" }, "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0.x-dev" } } } diff --git a/phpspec.yml b/phpspec.yml deleted file mode 100644 index 9e2e3ab..0000000 --- a/phpspec.yml +++ /dev/null @@ -1,2 +0,0 @@ -extensions: - - Knp\PhpSpec\WellDone\Extension diff --git a/spec/Knp/UniMail/AttachmentFactory/LocalAttachmentFactorySpec.php b/spec/Knp/UniMail/AttachmentFactory/LocalAttachmentFactorySpec.php index a2f79bc..1ed71f3 100644 --- a/spec/Knp/UniMail/AttachmentFactory/LocalAttachmentFactorySpec.php +++ b/spec/Knp/UniMail/AttachmentFactory/LocalAttachmentFactorySpec.php @@ -1,15 +1,14 @@ shouldHaveType('Knp\Rad\Mailer\AttachmentFactory\LocalAttachmentFactory'); + $this->shouldHaveType('Knp\UniMail\AttachmentFactory\LocalAttachmentFactory'); } function it_supports_existing_files() @@ -22,7 +21,6 @@ function it_creates_attachment_from_file() { $this ->createAttachment('foo', __FILE__) - ->shouldHaveType('Swift_Mime_MimeEntity') - ; + ->shouldHaveType('Swift_Mime_MimeEntity'); } } diff --git a/spec/Knp/UniMail/AttachmentFactory/RemoteAttachmentFactorySpec.php b/spec/Knp/UniMail/AttachmentFactory/RemoteAttachmentFactorySpec.php index 8981497..0f893c0 100644 --- a/spec/Knp/UniMail/AttachmentFactory/RemoteAttachmentFactorySpec.php +++ b/spec/Knp/UniMail/AttachmentFactory/RemoteAttachmentFactorySpec.php @@ -1,15 +1,14 @@ shouldHaveType('Knp\Rad\Mailer\AttachmentFactory\RemoteAttachmentFactory'); + $this->shouldHaveType('Knp\UniMail\AttachmentFactory\RemoteAttachmentFactory'); } function it_supports_existing_urls() @@ -22,7 +21,6 @@ function it_creates_attachment_from_file() { $this ->createAttachment('foo', 'http://symfony.com/pdf/Symfony_book_2.7.pdf?v=4') - ->shouldHaveType('Swift_Mime_MimeEntity') - ; + ->shouldHaveType('Swift_Mime_MimeEntity'); } } diff --git a/spec/Knp/UniMail/MailFactory/ConfigurationAwareFactorySpec.php b/spec/Knp/UniMail/MailFactory/ConfigurationAwareFactorySpec.php index f4a1798..4c5f854 100644 --- a/spec/Knp/UniMail/MailFactory/ConfigurationAwareFactorySpec.php +++ b/spec/Knp/UniMail/MailFactory/ConfigurationAwareFactorySpec.php @@ -1,11 +1,10 @@ [ 'from' => 'mail@mail.com', 'to' => 'to@mail.com', - ] + ], ]; $this->beConstructedWith($configuration, $factory); @@ -23,32 +22,30 @@ function let(MailFactory $factory) function it_is_initializable() { - $this->shouldHaveType('Knp\Rad\Mailer\MailFactory\ConfigurationAwareFactory'); + $this->shouldHaveType('Knp\UniMail\MailFactory\ConfigurationAwareFactory'); } function it_instantiate_a_new_mail_with_configuration($factory, Mail $mail) { $factory ->createMail('the_mail', ['from' => 'from@mail.com', 'to' => 'to@mail.com']) - ->willReturn($mail) - ; + ->willReturn($mail); $this ->createMail('the_mail', ['from' => 'from@mail.com']) - ->shouldReturn($mail) - ; + ->shouldReturn($mail); } - function it_instantiate_a_new_mail_without_configuration($factory, Mail $mail) - { + function it_instantiate_a_new_mail_without_configuration( + $factory, + Mail $mail + ) { $factory ->createMail('the_other_mail', ['from' => 'from@mail.com']) - ->willReturn($mail) - ; + ->willReturn($mail); $this ->createMail('the_other_mail', ['from' => 'from@mail.com']) - ->shouldReturn($mail) - ; + ->shouldReturn($mail); } } diff --git a/spec/Knp/UniMail/Mailer/EventDispatcherMailerSpec.php b/spec/Knp/UniMail/Mailer/EventDispatcherMailerSpec.php index 70ac418..f02af70 100644 --- a/spec/Knp/UniMail/Mailer/EventDispatcherMailerSpec.php +++ b/spec/Knp/UniMail/Mailer/EventDispatcherMailerSpec.php @@ -1,11 +1,11 @@ shouldHaveType('Knp\Rad\Mailer\Mailer\EventDispatcherMailer'); + $this->shouldHaveType('Knp\UniMail\Mailer\EventDispatcherMailer'); } function it_ask_to_wrapped_mailer_to_create_a_mail($wrapped, Mail $mail) @@ -27,13 +27,11 @@ function it_ask_to_wrapped_mailer_to_create_a_mail($wrapped, Mail $mail) $wrapped ->createMail('name', ['template' => 'the template']) ->shouldBeCalled() - ->willReturn($mail) - ; + ->willReturn($mail); $this ->createMail('name', ['template' => 'the template']) - ->shouldReturn($mail) - ; + ->shouldReturn($mail); } function it_dispatchs_events_when_a_mail_is_sent($wrapped, $dispatcher) @@ -43,42 +41,38 @@ function it_dispatchs_events_when_a_mail_is_sent($wrapped, $dispatcher) $dispatcher ->dispatch( MailerEvents::PRE_SEND, - Argument::that(function($e) use ($mail) { + Argument::that(function ($e) use ($mail) { return $mail === $e->getMail(); }) ) - ->shouldBeCalled() - ; + ->shouldBeCalled(); $dispatcher ->dispatch( MailerEvents::preSend($mail), - Argument::that(function($e) use ($mail) { + Argument::that(function ($e) use ($mail) { return $mail === $e->getMail(); }) ) - ->shouldBeCalled() - ; + ->shouldBeCalled(); $dispatcher ->dispatch( MailerEvents::POST_SEND, - Argument::that(function($e) use ($mail) { + Argument::that(function ($e) use ($mail) { return $mail === $e->getMail(); }) ) - ->shouldBeCalled() - ; + ->shouldBeCalled(); $dispatcher ->dispatch( MailerEvents::postSend($mail), - Argument::that(function($e) use ($mail) { + Argument::that(function ($e) use ($mail) { return $mail === $e->getMail(); }) ) - ->shouldBeCalled() - ; + ->shouldBeCalled(); $wrapped->sendMail($mail)->shouldBeCalled(); diff --git a/src/Knp/UniMail/AttachmentFactory/ChainAttachmentFactory.php b/src/Knp/UniMail/AttachmentFactory/ChainAttachmentFactory.php index f0c0e6d..659f6b8 100644 --- a/src/Knp/UniMail/AttachmentFactory/ChainAttachmentFactory.php +++ b/src/Knp/UniMail/AttachmentFactory/ChainAttachmentFactory.php @@ -18,6 +18,7 @@ public function __construct(array $factories) { $this->factories = $factories; } + /** * {@inheritdoc} */ @@ -48,12 +49,15 @@ public function createAttachment($name, $content) switch (true) { case is_array($content): $message = sprintf($message, 'an', 'array'); + break; case is_object($content): $message = sprintf($message, 'object', get_class($content)); + break; default: $message = sprintf($message, gettype($content), $content); + break; } diff --git a/src/Knp/UniMail/AttachmentFactory/RemoteAttachmentFactory.php b/src/Knp/UniMail/AttachmentFactory/RemoteAttachmentFactory.php index f9b95c1..204a4c8 100644 --- a/src/Knp/UniMail/AttachmentFactory/RemoteAttachmentFactory.php +++ b/src/Knp/UniMail/AttachmentFactory/RemoteAttachmentFactory.php @@ -22,7 +22,7 @@ public function supports($content) return false; } - return false === strpos($headers[0], '404'); + return false === mb_strpos($headers[0], '404'); } /** diff --git a/src/Knp/UniMail/Cid/Resolver.php b/src/Knp/UniMail/Cid/Resolver.php index ce3a604..de52eb2 100644 --- a/src/Knp/UniMail/Cid/Resolver.php +++ b/src/Knp/UniMail/Cid/Resolver.php @@ -7,7 +7,7 @@ interface Resolver /** * @param string $string * - * @return Swift_EmbeddedFile|null + * @return null|Swift_EmbeddedFile */ public function createFromString($string); } diff --git a/src/Knp/UniMail/Cid/Resolver/RemoteFile.php b/src/Knp/UniMail/Cid/Resolver/RemoteFile.php index d1325d3..c2bda02 100644 --- a/src/Knp/UniMail/Cid/Resolver/RemoteFile.php +++ b/src/Knp/UniMail/Cid/Resolver/RemoteFile.php @@ -18,7 +18,7 @@ public function createFromString($string) return; } - if (false !== strpos($headers[0], '404')) { + if (false !== mb_strpos($headers[0], '404')) { return; } diff --git a/src/Knp/UniMail/DependencyInjection/Configuration.php b/src/Knp/UniMail/DependencyInjection/Configuration.php index 18d9ac4..7ce1186 100644 --- a/src/Knp/UniMail/DependencyInjection/Configuration.php +++ b/src/Knp/UniMail/DependencyInjection/Configuration.php @@ -53,8 +53,7 @@ public function getConfigTreeBuilder() ->end() ->end() ->end() - ->end() - ; + ->end(); return $builder; } diff --git a/src/Knp/UniMail/DependencyInjection/UniMailExtension.php b/src/Knp/UniMail/DependencyInjection/UniMailExtension.php index 5eddaa0..543c9ad 100644 --- a/src/Knp/UniMail/DependencyInjection/UniMailExtension.php +++ b/src/Knp/UniMail/DependencyInjection/UniMailExtension.php @@ -14,7 +14,7 @@ class UniMailExtension extends Extension */ public function load(array $config, ContainerBuilder $container) { - $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); $configuration = $this->getConfiguration($config, $container); diff --git a/src/Knp/UniMail/EventListener/AttachmentResolver.php b/src/Knp/UniMail/EventListener/AttachmentResolver.php index d47b5fb..44df0a0 100644 --- a/src/Knp/UniMail/EventListener/AttachmentResolver.php +++ b/src/Knp/UniMail/EventListener/AttachmentResolver.php @@ -18,7 +18,7 @@ public function __construct(AttachmentFactory $factory) public static function getSubscribedEvents() { return [ - MailerEvents::PRE_SEND => array('beforeSend', -2), + MailerEvents::PRE_SEND => ['beforeSend', -2], ]; } diff --git a/src/Knp/UniMail/EventListener/CidAttachmentMerger.php b/src/Knp/UniMail/EventListener/CidAttachmentMerger.php index 2c0af1a..9e91f36 100644 --- a/src/Knp/UniMail/EventListener/CidAttachmentMerger.php +++ b/src/Knp/UniMail/EventListener/CidAttachmentMerger.php @@ -19,7 +19,7 @@ public function __construct(Collection $cids) public static function getSubscribedEvents() { return [ - MailerEvents::PRE_SEND => array('beforeSend', -3), + MailerEvents::PRE_SEND => ['beforeSend', -3], ]; } diff --git a/src/Knp/UniMail/EventListener/TwigRenderer.php b/src/Knp/UniMail/EventListener/TwigRenderer.php index a2ed790..9de6d76 100644 --- a/src/Knp/UniMail/EventListener/TwigRenderer.php +++ b/src/Knp/UniMail/EventListener/TwigRenderer.php @@ -21,7 +21,7 @@ public function __construct(Twig_Environment $twig) public static function getSubscribedEvents() { return [ - MailerEvents::PRE_SEND => array('beforeSend', -2), + MailerEvents::PRE_SEND => ['beforeSend', -2], ]; } diff --git a/src/Knp/UniMail/Mail/AbstractMail.php b/src/Knp/UniMail/Mail/AbstractMail.php index edd69cd..7667efb 100644 --- a/src/Knp/UniMail/Mail/AbstractMail.php +++ b/src/Knp/UniMail/Mail/AbstractMail.php @@ -17,22 +17,22 @@ abstract class AbstractMail implements Mail private $from; /** - * @var string|array + * @var array|string */ private $to; /** - * @var string|array + * @var array|string */ private $cc; /** - * @var string|array + * @var array|string */ private $bcc; /** - * @var string|array + * @var array|string */ private $replyTo; diff --git a/src/Knp/UniMail/Mail/SwiftMail.php b/src/Knp/UniMail/Mail/SwiftMail.php index 3bcfefb..d9ceeb2 100644 --- a/src/Knp/UniMail/Mail/SwiftMail.php +++ b/src/Knp/UniMail/Mail/SwiftMail.php @@ -26,8 +26,10 @@ public static function createFromMail(Mail $mail) return (new self($mail->getName())) ->setFrom($mail->getFrom()) ->setTo($mail->getTo()) - ->setAttachments($mail->getAttachments()) - ; + ->setCc($mail->getCc()) + ->setBcc($mail->getBcc()) + ->setReplyTo($mail->getReplyTo()) + ->setAttachments($mail->getAttachments()); } /** diff --git a/src/Knp/UniMail/Mail/TwigMail.php b/src/Knp/UniMail/Mail/TwigMail.php index b47e9c2..369668d 100644 --- a/src/Knp/UniMail/Mail/TwigMail.php +++ b/src/Knp/UniMail/Mail/TwigMail.php @@ -21,8 +21,7 @@ public static function createFromMail(Mail $mail) return (new self($mail->getName())) ->setFrom($mail->getFrom()) ->setTo($mail->getTo()) - ->setAttachments($mail->getAttachments()) - ; + ->setAttachments($mail->getAttachments()); } /** @@ -35,6 +34,7 @@ public function getTemplate() /** * @param string $string + * @param mixed $template * * @return TwigMail */ diff --git a/src/Knp/UniMail/MailFactory.php b/src/Knp/UniMail/MailFactory.php index dc9a2f0..6aea19e 100644 --- a/src/Knp/UniMail/MailFactory.php +++ b/src/Knp/UniMail/MailFactory.php @@ -6,7 +6,7 @@ interface MailFactory { /** * @param string $name - * @param array|null $options + * @param null|array $options * * @return Mail */ diff --git a/src/Knp/UniMail/Mailer.php b/src/Knp/UniMail/Mailer.php index 640a9bc..a1296f1 100644 --- a/src/Knp/UniMail/Mailer.php +++ b/src/Knp/UniMail/Mailer.php @@ -6,9 +6,9 @@ interface Mailer { /** * @param string $name - * @param array|null $options + * @param null|array $options * - * @return Mail|null + * @return null|Mail */ public function createMail($name, array $options = []); diff --git a/src/Knp/UniMail/Mailer/EventDispatcherMailer.php b/src/Knp/UniMail/Mailer/EventDispatcherMailer.php index 47eb5f9..0795ccc 100644 --- a/src/Knp/UniMail/Mailer/EventDispatcherMailer.php +++ b/src/Knp/UniMail/Mailer/EventDispatcherMailer.php @@ -24,8 +24,10 @@ class EventDispatcherMailer implements Mailer * @param Mailer $wrapped * @param EventDispatcherInterface $dispatcher */ - public function __construct(Mailer $wrapped, EventDispatcherInterface $dispatcher) - { + public function __construct( + Mailer $wrapped, + EventDispatcherInterface $dispatcher + ) { $this->wrapped = $wrapped; $this->dispatcher = $dispatcher; } @@ -37,8 +39,7 @@ public function createMail($name, array $options = []) { return $this ->wrapped - ->createMail($name, $options) - ; + ->createMail($name, $options); } /** @@ -50,28 +51,23 @@ public function sendMail(Mail $mail) $this ->dispatcher - ->dispatch(MailerEvents::PRE_SEND, $event) - ; + ->dispatch(MailerEvents::PRE_SEND, $event); $this ->dispatcher - ->dispatch(MailerEvents::preSend($event->getMail()), $event) - ; + ->dispatch(MailerEvents::preSend($event->getMail()), $event); $this ->wrapped - ->sendMail($event->getMail()) - ; + ->sendMail($event->getMail()); $this ->dispatcher - ->dispatch(MailerEvents::postSend($event->getMail()), $event) - ; + ->dispatch(MailerEvents::postSend($event->getMail()), $event); $this ->dispatcher - ->dispatch(MailerEvents::POST_SEND, $event) - ; + ->dispatch(MailerEvents::POST_SEND, $event); } /** diff --git a/src/Knp/UniMail/Mailer/SwiftMailer.php b/src/Knp/UniMail/Mailer/SwiftMailer.php index 9132958..d552133 100644 --- a/src/Knp/UniMail/Mailer/SwiftMailer.php +++ b/src/Knp/UniMail/Mailer/SwiftMailer.php @@ -37,8 +37,7 @@ public function createMail($name, array $options = []) { return $this ->factory - ->createMail($name, $options) - ; + ->createMail($name, $options); } /** @@ -61,8 +60,7 @@ public function sendMail(Mail $mail) ->setCc($mail->getCc()) ->setReplyTo($mail->getReplyTo()) ->setBody($mail->getHtmlBody(), 'text/html') - ->addPart($mail->getTextBody()) - ; + ->addPart($mail->getTextBody()); foreach ($mail->getAttachments() as $attachment) { $message->attach($attachment); diff --git a/src/Knp/UniMail/Mailer/TwigMailer.php b/src/Knp/UniMail/Mailer/TwigMailer.php index 1e5f0a6..ecf56c5 100644 --- a/src/Knp/UniMail/Mailer/TwigMailer.php +++ b/src/Knp/UniMail/Mailer/TwigMailer.php @@ -4,13 +4,13 @@ use Doctrine\Common\Collections\ArrayCollection; use Knp\UniMail\Mail; -use Knp\UniMail\Mailer as MailerInterface; +use Knp\UniMail\Mailer; use Knp\UniMail\MailFactory; use Swift_Mailer; use Swift_Message; use Twig_Environment; -class TwigMailer implements MailerInterface +class TwigMailer implements Mailer { /** * @var Twig_Environment @@ -35,8 +35,12 @@ class TwigMailer implements MailerInterface /** * @param MailFactory $factory */ - public function __construct(Twig_Environment $twig, Swift_Mailer $mailer, MailFactory $factory, ArrayCollection $cids) - { + public function __construct( + Twig_Environment $twig, + Swift_Mailer $mailer, + MailFactory $factory, + ArrayCollection $cids + ) { $this->twig = $twig; $this->mailer = $mailer; $this->factory = $factory; @@ -50,8 +54,7 @@ public function createMail($name, array $options = []) { return $this ->factory - ->createMail($name, $options) - ; + ->createMail($name, $options); } /** @@ -61,7 +64,7 @@ public function sendMail(Mail $mail) { $message = Swift_Message::newInstance(); $template = $this->twig->loadTemplate($mail->getTemplate()); - $subject = $template->renderBlock('subject', $mail->getParameters()); + $subject = $template->renderBlock('subject', $mail->getParameters()); $html = $template->renderBlock('html_body', $mail->getParameters()); $text = $template->renderBlock('text_body', $mail->getParameters()); @@ -70,8 +73,7 @@ public function sendMail(Mail $mail) ->setFrom($mail->getFrom()) ->setTo($mail->getTo()) ->setBody($html, 'text/html') - ->addPart($text) - ; + ->addPart($text); foreach ($this->cids as $name => $attachment) { $message->attach($attachment); diff --git a/src/Knp/UniMail/Resources/config/services.yml b/src/Knp/UniMail/Resources/config/services.yml index 5e4e872..3861646 100644 --- a/src/Knp/UniMail/Resources/config/services.yml +++ b/src/Knp/UniMail/Resources/config/services.yml @@ -5,9 +5,7 @@ services: knp_unimail.attachment_factory.chain_attachment_factory: class: Knp\UniMail\AttachmentFactory\ChainAttachmentFactory arguments: - factories: - - @knp_unimail.attachment_factory.local_attachment_factory - - @knp_unimail.attachment_factory.remote_attachment_factory + - [ "@knp_unimail.attachment_factory.local_attachment_factory", "@knp_unimail.attachment_factory.remote_attachment_factory" ] knp_unimail.attachment_factory.local_attachment_factory: class: Knp\UniMail\AttachmentFactory\LocalAttachmentFactory @@ -24,21 +22,21 @@ services: knp_unimail.event_listener.attachment_resolver: class: Knp\UniMail\EventListener\AttachmentResolver arguments: - - @knp_unimail.attachment_factory + - "@knp_unimail.attachment_factory" tags: - { name: kernel.event_subscriber } knp_unimail.event_listener.cid_attachment_merger: class: Knp\UniMail\EventListener\CidAttachmentMerger arguments: - - @knp_unimail.cid.collection + - "@knp_unimail.cid.collection" tags: - { name: kernel.event_subscriber } knp_unimail.event_listener.twig_renderer: class: Knp\UniMail\EventListener\TwigRenderer arguments: - - @twig + - "@twig" tags: - { name: kernel.event_subscriber } @@ -46,15 +44,15 @@ services: class: Knp\UniMail\MailFactory\ConfigurationAwareFactory public: false arguments: - - %knp_unimail.mails% - - @knp_unimail.mail_factory.registry_factory + - "%knp_unimail.mails%" + - "@knp_unimail.mail_factory.registry_factory" knp_unimail.mail_factory.registry_factory: class: Knp\UniMail\MailFactory\RegistryFactory arguments: strategies: - - @knp_unimail.mail_factory.strategy_factory.swift_mail_factory - - @knp_unimail.mail_factory.strategy_factory.twig_mail_factory + - "@knp_unimail.mail_factory.strategy_factory.swift_mail_factory" + - "@knp_unimail.mail_factory.strategy_factory.twig_mail_factory" knp_unimail.mail_factory.strategy_factory.swift_mail_factory: class: Knp\UniMail\MailFactory\StrategyMailer\SwiftMailFactory @@ -68,14 +66,14 @@ services: knp_unimail.mailer.event_dispatcher_mailer: class: Knp\UniMail\Mailer\EventDispatcherMailer arguments: - - @knp_unimail.mailer.swift_mailer - - @event_dispatcher + - "@knp_unimail.mailer.swift_mailer" + - "@event_dispatcher" knp_unimail.mailer.swift_mailer: class: Knp\UniMail\Mailer\SwiftMailer arguments: - - @mailer - - @knp_unimail.mail_factory + - "@mailer" + - "@knp_unimail.mail_factory" knp_unimail.mailer: alias: knp_unimail.mailer.event_dispatcher_mailer @@ -83,17 +81,17 @@ services: knp_unimail.twig.cid_extension: class: Knp\UniMail\Twig\CidExtension arguments: - - @knp_unimail.cid.collection - - [@knp_unimail.cid.resolver.local_file, @knp_unimail.cid.resolver.remove_file] + - "@knp_unimail.cid.collection" + - ["@knp_unimail.cid.resolver.local_file", "@knp_unimail.cid.resolver.remote_file"] tags: - { name: twig.extension } knp_unimail.cid.resolver.local_file: class: Knp\UniMail\Cid\Resolver\LocalFile arguments: - - %knp_unimail.attachments_directory% + - "%knp_unimail.attachments_directory%" - knp_unimail.cid.resolver.remove_file: + knp_unimail.cid.resolver.remote_file: class: Knp\UniMail\Cid\Resolver\RemoteFile arguments: - - %knp_unimail.attachments_directory% + - "%knp_unimail.attachments_directory%"