[MonologBundle] Refactored the way to configure the email prototype for swiftmailer
This commit is contained in:
parent
874fb9540a
commit
f8b5f350dc
16
UPDATE.md
16
UPDATE.md
@ -18,6 +18,22 @@ RC4 to RC5
|
||||
* `channel`: to register it only for one logging channel (exclusive with `handler`)
|
||||
* `method`: The method used to process the record (`__invoke` is used if not set)
|
||||
|
||||
* The email_prototype for the `SwiftMailerHandler` only accept a service id now.
|
||||
|
||||
* Before:
|
||||
|
||||
email_prototype: @acme_demo.monolog.email_prototype
|
||||
|
||||
* After:
|
||||
|
||||
email_prototype: acme_demo.monolog.email_prototype
|
||||
|
||||
or if you want to use a factory for the prototype:
|
||||
|
||||
email_prototype:
|
||||
id: acme_demo.monolog.email_prototype
|
||||
method: getPrototype
|
||||
|
||||
* To avoid security issues, HTTP headers coming from proxies are not trusted
|
||||
anymore by default (like `HTTP_X_FORWARDED_FOR`, `X_FORWARDED_PROTO`, and
|
||||
`X_FORWARDED_HOST`). If your application is behind a reverse proxy, add the
|
||||
|
@ -73,7 +73,17 @@ class Configuration implements ConfigurationInterface
|
||||
->scalarNode('from_email')->end() // swift_mailer and native_mailer
|
||||
->scalarNode('to_email')->end() // swift_mailer and native_mailer
|
||||
->scalarNode('subject')->end() // swift_mailer and native_mailer
|
||||
->scalarNode('email_prototype')->end() // swift_mailer
|
||||
->arrayNode('email_prototype') // swift_mailer
|
||||
->canBeUnset()
|
||||
->beforeNormalization()
|
||||
->ifString()
|
||||
->then(function($v) { return array('id' => $v); })
|
||||
->end()
|
||||
->children()
|
||||
->scalarNode('id')->isRequired()->end()
|
||||
->scalarNode('factory-method')->defaultNull()->end()
|
||||
->end()
|
||||
->end()
|
||||
->scalarNode('formatter')->end()
|
||||
->end()
|
||||
->validate()
|
||||
|
@ -186,7 +186,11 @@ class MonologExtension extends Extension
|
||||
|
||||
case 'swift_mailer':
|
||||
if (isset($handler['email_prototype'])) {
|
||||
$prototype = $this->parseDefinition($handler['email_prototype']);
|
||||
if (!empty($handler['email_prototype']['method'])) {
|
||||
$prototype = array(new Reference($handler['email_prototype']['id']), $handler['email_prototype']['method']);
|
||||
} else {
|
||||
$prototype = new Reference($handler['email_prototype']['id']);
|
||||
}
|
||||
} else {
|
||||
$message = new Definition('Swift_Message');
|
||||
$message->setFactoryService('mailer');
|
||||
@ -243,18 +247,4 @@ class MonologExtension extends Extension
|
||||
{
|
||||
return sprintf('monolog.handler.%s', $name);
|
||||
}
|
||||
|
||||
private function parseDefinition($definition, ContainerBuilder $container = null)
|
||||
{
|
||||
if (0 === strpos($definition, '@')) {
|
||||
$definition = substr($definition, 1);
|
||||
if ($container && $container->hasDefinition($definition)) {
|
||||
$container->getDefinition($definition)->setPublic(true);
|
||||
}
|
||||
|
||||
return new Reference($definition);
|
||||
}
|
||||
|
||||
return $definition;
|
||||
}
|
||||
}
|
||||
|
@ -10,16 +10,15 @@
|
||||
<xsd:complexType name="config">
|
||||
<xsd:choice minOccurs="0" maxOccurs="unbounded">
|
||||
<xsd:element name="handler" type="handler" />
|
||||
<xsd:element name="processor" type="xsd:string" />
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="handler">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="processor" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="email-prototype" type="email-prototype" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="member" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="type" type="xsd:string" use="required" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="priority" type="xsd:integer" />
|
||||
<xsd:attribute name="level" type="level" />
|
||||
<xsd:attribute name="bubble" type="xsd:boolean" />
|
||||
@ -35,7 +34,6 @@
|
||||
<xsd:attribute name="from-email" type="xsd:string" />
|
||||
<xsd:attribute name="to-email" type="xsd:string" />
|
||||
<xsd:attribute name="subject" type="xsd:string" />
|
||||
<xsd:attribute name="email-prototype" type="xsd:string" />
|
||||
<xsd:attribute name="formatter" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
|
||||
@ -56,4 +54,9 @@
|
||||
<xsd:enumeration value="550" />
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
|
||||
<xsd:complexType name="email-prototype">
|
||||
<xsd:attribute name="id" type="xsd:string" />
|
||||
<xsd:attribute name="method" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:schema>
|
||||
|
Reference in New Issue
Block a user