Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for additional parameters in native mailer #470

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
* - [level]: level name or int value, defaults to DEBUG
* - [bubble]: bool, defaults to true
* - [headers]: optional array containing additional headers: ['Foo: Bar', '...']
* - [parameters]: optional array containing additional parameters: ['--for bar', '...']
*
* - symfony_mailer:
* - from_email: optional if email_prototype is given
Expand Down Expand Up @@ -429,6 +430,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->fixXmlConfig('tag')
->fixXmlConfig('accepted_level')
->fixXmlConfig('header')
->fixXmlConfig('parameter')
->canBeUnset();

$handlerNode
Expand Down Expand Up @@ -976,6 +978,10 @@ private function addMailerSection(ArrayNodeDefinition $handerNode)
->canBeUnset()
->scalarPrototype()->end()
->end()
->arrayNode('parameters') // native_mailer
->canBeUnset()
->scalarPrototype()->end()
->end()
->scalarNode('mailer')->defaultNull()->end() // swift_mailer and symfony_mailer
->arrayNode('email_prototype') // swift_mailer and symfony_mailer
->canBeUnset()
Expand Down
3 changes: 3 additions & 0 deletions DependencyInjection/MonologExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,9 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
if (!empty($handler['headers'])) {
$definition->addMethodCall('addHeader', [$handler['headers']]);
}
if (!empty($handler['parameters'])) {
$definition->addMethodCall('addParameter', [$handler['parameters']]);
}
break;

case 'symfony_mailer':
Expand Down
1 change: 1 addition & 0 deletions Resources/config/schema/monolog-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<xsd:element name="accepted-level" type="level" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="to-email" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="header" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="parameter" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="process-psr-3-messages" type="process-psr-3-messages" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="type" type="xsd:string" />
Expand Down
3 changes: 2 additions & 1 deletion Tests/DependencyInjection/FixtureMonologExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,9 @@ public function testNativeMailer()
$logger = $container->getDefinition('monolog.handler.mailer');
$methodCalls = $logger->getMethodCalls();

$this->assertCount(2, $methodCalls);
$this->assertCount(3, $methodCalls);
$this->assertSame(['addHeader', [['Foo: bar', 'Baz: inga']]], $methodCalls[1]);
$this->assertSame(['addParameter', [['--foo bar', '--baz inga']]], $methodCalls[2]);
}

protected function getContainer($fixture)
Expand Down
2 changes: 2 additions & 0 deletions Tests/DependencyInjection/Fixtures/xml/native_mailer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<handler name="mailer" type="native_mailer" to-email="[email protected]" from-email="[email protected]" subject="a subject">
<header>Foo: bar</header>
<header>Baz: inga</header>
<parameter>--foo bar</parameter>
<parameter>--baz inga</parameter>
</handler>
</config>
</srv:container>
3 changes: 3 additions & 0 deletions Tests/DependencyInjection/Fixtures/yml/native_mailer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ monolog:
headers:
- "Foo: bar"
- "Baz: inga"
parameters:
- "--foo bar"
- "--baz inga"
Loading