Skip to content

Commit f8b5f35

Browse files
committed
[MonologBundle] Refactored the way to configure the email prototype for swiftmailer
1 parent 874fb95 commit f8b5f35

File tree

4 files changed

+39
-20
lines changed

4 files changed

+39
-20
lines changed

UPDATE.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ RC4 to RC5
1818
* `channel`: to register it only for one logging channel (exclusive with `handler`)
1919
* `method`: The method used to process the record (`__invoke` is used if not set)
2020

21+
* The email_prototype for the `SwiftMailerHandler` only accept a service id now.
22+
23+
* Before:
24+
25+
email_prototype: @acme_demo.monolog.email_prototype
26+
27+
* After:
28+
29+
email_prototype: acme_demo.monolog.email_prototype
30+
31+
or if you want to use a factory for the prototype:
32+
33+
email_prototype:
34+
id: acme_demo.monolog.email_prototype
35+
method: getPrototype
36+
2137
* To avoid security issues, HTTP headers coming from proxies are not trusted
2238
anymore by default (like `HTTP_X_FORWARDED_FOR`, `X_FORWARDED_PROTO`, and
2339
`X_FORWARDED_HOST`). If your application is behind a reverse proxy, add the

src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,17 @@ public function getConfigTreeBuilder()
7373
->scalarNode('from_email')->end() // swift_mailer and native_mailer
7474
->scalarNode('to_email')->end() // swift_mailer and native_mailer
7575
->scalarNode('subject')->end() // swift_mailer and native_mailer
76-
->scalarNode('email_prototype')->end() // swift_mailer
76+
->arrayNode('email_prototype') // swift_mailer
77+
->canBeUnset()
78+
->beforeNormalization()
79+
->ifString()
80+
->then(function($v) { return array('id' => $v); })
81+
->end()
82+
->children()
83+
->scalarNode('id')->isRequired()->end()
84+
->scalarNode('factory-method')->defaultNull()->end()
85+
->end()
86+
->end()
7787
->scalarNode('formatter')->end()
7888
->end()
7989
->validate()

src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,11 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
186186

187187
case 'swift_mailer':
188188
if (isset($handler['email_prototype'])) {
189-
$prototype = $this->parseDefinition($handler['email_prototype']);
189+
if (!empty($handler['email_prototype']['method'])) {
190+
$prototype = array(new Reference($handler['email_prototype']['id']), $handler['email_prototype']['method']);
191+
} else {
192+
$prototype = new Reference($handler['email_prototype']['id']);
193+
}
190194
} else {
191195
$message = new Definition('Swift_Message');
192196
$message->setFactoryService('mailer');
@@ -243,18 +247,4 @@ private function getHandlerId($name)
243247
{
244248
return sprintf('monolog.handler.%s', $name);
245249
}
246-
247-
private function parseDefinition($definition, ContainerBuilder $container = null)
248-
{
249-
if (0 === strpos($definition, '@')) {
250-
$definition = substr($definition, 1);
251-
if ($container && $container->hasDefinition($definition)) {
252-
$container->getDefinition($definition)->setPublic(true);
253-
}
254-
255-
return new Reference($definition);
256-
}
257-
258-
return $definition;
259-
}
260250
}

src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@
1010
<xsd:complexType name="config">
1111
<xsd:choice minOccurs="0" maxOccurs="unbounded">
1212
<xsd:element name="handler" type="handler" />
13-
<xsd:element name="processor" type="xsd:string" />
1413
</xsd:choice>
1514
</xsd:complexType>
1615

1716
<xsd:complexType name="handler">
1817
<xsd:sequence>
19-
<xsd:element name="processor" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
18+
<xsd:element name="email-prototype" type="email-prototype" minOccurs="0" maxOccurs="1" />
2019
<xsd:element name="member" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
2120
</xsd:sequence>
22-
<xsd:attribute name="type" type="xsd:string" use="required" />
21+
<xsd:attribute name="type" type="xsd:string" />
2322
<xsd:attribute name="priority" type="xsd:integer" />
2423
<xsd:attribute name="level" type="level" />
2524
<xsd:attribute name="bubble" type="xsd:boolean" />
@@ -35,7 +34,6 @@
3534
<xsd:attribute name="from-email" type="xsd:string" />
3635
<xsd:attribute name="to-email" type="xsd:string" />
3736
<xsd:attribute name="subject" type="xsd:string" />
38-
<xsd:attribute name="email-prototype" type="xsd:string" />
3937
<xsd:attribute name="formatter" type="xsd:string" />
4038
</xsd:complexType>
4139

@@ -56,4 +54,9 @@
5654
<xsd:enumeration value="550" />
5755
</xsd:restriction>
5856
</xsd:simpleType>
57+
58+
<xsd:complexType name="email-prototype">
59+
<xsd:attribute name="id" type="xsd:string" />
60+
<xsd:attribute name="method" type="xsd:string" />
61+
</xsd:complexType>
5962
</xsd:schema>

0 commit comments

Comments
 (0)