From 7c344c730c0b32461259564263e56832db1d7800 Mon Sep 17 00:00:00 2001 From: Anthony Bocci Date: Sat, 18 May 2019 20:39:12 +0200 Subject: [PATCH] Add support for headers in native mailer The native mailer is able to have additional headers, but it wasn't possible to give it any headers in the configuration. Swift mailer may have a content_type key but not native mailer. A new "headers" key is now allowed in the handler configuration, so a list of headers may be given to the handler. Only native mailer supports it. Related to #272 --- DependencyInjection/Configuration.php | 5 +++++ DependencyInjection/MonologExtension.php | 3 +++ Resources/config/schema/monolog-1.0.xsd | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index ff023175..8e8f31ab 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -160,6 +160,7 @@ * - subject: string * - [level]: level name or int value, defaults to DEBUG * - [bubble]: bool, defaults to true + * - [headers]: optional array containing additional headers * * - socket: * - connection_string: string @@ -541,6 +542,10 @@ public function getConfigTreeBuilder() ->end() ->scalarNode('subject')->end() // swift_mailer and native_mailer ->scalarNode('content_type')->defaultNull()->end() // swift_mailer + ->arrayNode('headers') // native_mailer + ->canBeUnset() + ->scalarPrototype()->end() + ->end() ->scalarNode('mailer')->defaultValue('mailer')->end() // swift_mailer ->arrayNode('email_prototype') // swift_mailer ->canBeUnset() diff --git a/DependencyInjection/MonologExtension.php b/DependencyInjection/MonologExtension.php index 14b00662..d149ce2b 100644 --- a/DependencyInjection/MonologExtension.php +++ b/DependencyInjection/MonologExtension.php @@ -508,6 +508,9 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler $handler['level'], $handler['bubble'], )); + if (!empty($handler['headers'])) { + $definition->addMethodCall('addHeader', $handler['headers']); + } break; case 'socket': diff --git a/Resources/config/schema/monolog-1.0.xsd b/Resources/config/schema/monolog-1.0.xsd index 137df65e..14cc51c5 100644 --- a/Resources/config/schema/monolog-1.0.xsd +++ b/Resources/config/schema/monolog-1.0.xsd @@ -88,6 +88,7 @@ + @@ -172,4 +173,10 @@ + + + + + +