Skip to content

Commit 19eaa0f

Browse files
committed
Fix 'Add support for headers in native mailer'
1 parent 7ecbc9e commit 19eaa0f

File tree

6 files changed

+43
-6
lines changed

6 files changed

+43
-6
lines changed

DependencyInjection/Configuration.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
* - subject: string
176176
* - [level]: level name or int value, defaults to DEBUG
177177
* - [bubble]: bool, defaults to true
178-
* - [headers]: optional array containing additional headers
178+
* - [headers]: optional array containing additional headers: ['Foo: Bar', '...']
179179
*
180180
* - socket:
181181
* - connection_string: string
@@ -348,6 +348,7 @@ public function getConfigTreeBuilder()
348348
->fixXmlConfig('excluded_http_code')
349349
->fixXmlConfig('tag')
350350
->fixXmlConfig('accepted_level')
351+
->fixXmlConfig('header')
351352
->canBeUnset()
352353
->children()
353354
->scalarNode('type')

DependencyInjection/MonologExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
541541
$handler['bubble'],
542542
));
543543
if (!empty($handler['headers'])) {
544-
$definition->addMethodCall('addHeader', $handler['headers']);
544+
$definition->addMethodCall('addHeader', [$handler['headers']]);
545545
}
546546
break;
547547

Resources/config/schema/monolog-1.0.xsd

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<xsd:element name="tag" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
2929
<xsd:element name="accepted-level" type="level" minOccurs="0" maxOccurs="unbounded" />
3030
<xsd:element name="to-email" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
31+
<xsd:element name="header" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
3132
</xsd:sequence>
3233
<xsd:attribute name="type" type="xsd:string" />
3334
<xsd:attribute name="priority" type="xsd:integer" />
@@ -88,7 +89,6 @@
8889
<xsd:attribute name="content-type" type="xsd:string" />
8990
<xsd:attribute name="webhook-url" type="xsd:string" />
9091
<xsd:attribute name="slack-team" type="xsd:string" />
91-
<xsd:attribute name="headers" type="headers" />
9292
</xsd:complexType>
9393

9494
<xsd:simpleType name="level">
@@ -189,8 +189,8 @@
189189
</xsd:complexType>
190190

191191
<xsd:complexType name="headers">
192-
<xsd:choice minOccurs="0" maxOccurs="unbounded">
193-
<xsd:element name="header" type="xsd:string" />
194-
</xsd:choice>
192+
<xsd:sequence>
193+
<xsd:any minOccurs="0" processContents="lax"/>
194+
</xsd:sequence>
195195
</xsd:complexType>
196196
</xsd:schema>

Tests/DependencyInjection/FixtureMonologExtensionTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,17 @@ public function testPsr3MessageProcessingDisabled()
216216
$this->assertNotContains(array('pushProcessor', array(new Reference('monolog.processor.psr_log_message'))), $methodCalls, 'The PSR-3 processor should not be enabled', false, false);
217217
}
218218

219+
public function testNativeMailer()
220+
{
221+
$container = $this->getContainer('native_mailer');
222+
223+
$logger = $container->getDefinition('monolog.handler.mailer');
224+
$methodCalls = $logger->getMethodCalls();
225+
226+
$this->assertCount(2, $methodCalls);
227+
$this->assertSame(['addHeader', [['Foo: bar', 'Baz: inga']]], $methodCalls[1]);
228+
}
229+
219230
protected function getContainer($fixture)
220231
{
221232
$container = new ContainerBuilder();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" ?>
2+
3+
<srv:container xmlns="http://symfony.com/schema/dic/monolog"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:srv="http://symfony.com/schema/dic/services"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/monolog http://symfony.com/schema/dic/monolog/monolog-1.0.xsd">
8+
9+
<config>
10+
<handler name="mailer" type="native_mailer" to-email="[email protected]" from-email="[email protected]" subject="a subject">
11+
<header>Foo: bar</header>
12+
<header>Baz: inga</header>
13+
</handler>
14+
</config>
15+
</srv:container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
monolog:
2+
handlers:
3+
mailer:
4+
type: native_mailer
5+
from_email: [email protected]
6+
7+
subject: a subject
8+
headers:
9+
- "Foo: bar"
10+
- "Baz: inga"

0 commit comments

Comments
 (0)