Skip to content

Commit 7b7a97e

Browse files
committed
bug #91 make it possible to use multiple to_email in XML (xabbuh)
This PR was merged into the 2.1.x-dev branch. Discussion ---------- make it possible to use multiple to_email in XML The Configuration class allows to configure more than one recipient (see symfony/symfony-docs#4135). Since the ``to_email`` field was configured as an attribute in XML configurations, it couldn't be specified multiple times. Commits ------- 44505b6 make it possible to use multiple to_email in XML
2 parents 227bbee + 44505b6 commit 7b7a97e

File tree

6 files changed

+76
-0
lines changed

6 files changed

+76
-0
lines changed

Resources/config/schema/monolog-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<xsd:element name="excluded-404" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
2626
<xsd:element name="tag" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
2727
<xsd:element name="accepted-level" type="level" minOccurs="0" maxOccurs="unbounded" />
28+
<xsd:element name="to-email" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
2829
</xsd:sequence>
2930
<xsd:attribute name="type" type="xsd:string" />
3031
<xsd:attribute name="priority" type="xsd:integer" />

Tests/DependencyInjection/FixtureMonologExtensionTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,28 @@ public function testHandlersWithChannels()
136136
);
137137
}
138138

139+
public function testSingleEmailRecipient()
140+
{
141+
$container = $this->getContainer('single_email_recipient');
142+
143+
$this->assertSame(array(
144+
array('setFrom', array('error@example.com')),
145+
array('setTo', array(array('error@example.com'))),
146+
array('setSubject', array('An Error Occurred!')),
147+
), $container->getDefinition('monolog.handler.swift.mail_prototype')->getMethodCalls());
148+
}
149+
150+
public function testMultipleEmailRecipients()
151+
{
152+
$container = $this->getContainer('multiple_email_recipients');
153+
154+
$this->assertSame(array(
155+
array('setFrom', array('error@example.com')),
156+
array('setTo', array(array('dev1@example.com', 'dev2@example.com'))),
157+
array('setSubject', array('An Error Occurred!')),
158+
), $container->getDefinition('monolog.handler.swift.mail_prototype')->getMethodCalls());
159+
}
160+
139161
protected function getContainer($fixture)
140162
{
141163
$container = new ContainerBuilder();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:monolog="http://symfony.com/schema/dic/monolog"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/monolog http://symfony.com/schema/dic/monolog/monolog-1.0.xsd">
7+
8+
<monolog:config>
9+
<monolog:handler
10+
name="swift"
11+
type="swift_mailer"
12+
from-email="error@example.com"
13+
subject="An Error Occurred!"
14+
level="debug">
15+
16+
<monolog:to-email>dev1@example.com</monolog:to-email>
17+
<monolog:to-email>dev2@example.com</monolog:to-email>
18+
</monolog:handler>
19+
</monolog:config>
20+
</container>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:monolog="http://symfony.com/schema/dic/monolog"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/monolog http://symfony.com/schema/dic/monolog/monolog-1.0.xsd">
7+
8+
<monolog:config>
9+
<monolog:handler
10+
name="swift"
11+
type="swift_mailer"
12+
from-email="error@example.com"
13+
to-email="error@example.com"
14+
subject="An Error Occurred!"
15+
level="debug" />
16+
</monolog:config>
17+
</container>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
monolog:
2+
handlers:
3+
swift:
4+
type: swift_mailer
5+
from_email: error@example.com
6+
to_email: [dev1@example.com, dev2@example.com]
7+
subject: An Error Occurred!
8+
level: debug
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
monolog:
2+
handlers:
3+
swift:
4+
type: swift_mailer
5+
from_email: error@example.com
6+
to_email: error@example.com
7+
subject: An Error Occurred!
8+
level: debug

0 commit comments

Comments
 (0)