Skip to content

Commit

Permalink
Add support for headers in native mailer
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nalysius authored and lyrixx committed Jun 11, 2019
1 parent 5fe15c2 commit 7ecbc9e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions DependencyInjection/Configuration.php
Expand Up @@ -175,6 +175,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
Expand Down Expand Up @@ -594,6 +595,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()
Expand Down
3 changes: 3 additions & 0 deletions DependencyInjection/MonologExtension.php
Expand Up @@ -540,6 +540,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':
Expand Down
7 changes: 7 additions & 0 deletions Resources/config/schema/monolog-1.0.xsd
Expand Up @@ -88,6 +88,7 @@
<xsd:attribute name="content-type" type="xsd:string" />
<xsd:attribute name="webhook-url" type="xsd:string" />
<xsd:attribute name="slack-team" type="xsd:string" />
<xsd:attribute name="headers" type="headers" />
</xsd:complexType>

<xsd:simpleType name="level">
Expand Down Expand Up @@ -186,4 +187,10 @@
</xsd:choice>
<xsd:attribute name="code" type="xsd:integer" />
</xsd:complexType>

<xsd:complexType name="headers">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="header" type="xsd:string" />
</xsd:choice>
</xsd:complexType>
</xsd:schema>

0 comments on commit 7ecbc9e

Please sign in to comment.