bug #32553 [Mailer] Allow register mailer configuration in xml format (Koc)

This PR was submitted for the 4.4 branch but it was merged into the 4.3 branch instead (closes #32553).

Discussion
----------

[Mailer] Allow register mailer configuration in xml format

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This looks like bugfix but also similar to new feature. I can switch branch to 4.3 if needed.

Commits
-------

2f3b47a9e4 [Mailer] Allow register mailer configuration in xml format
This commit is contained in:
Fabien Potencier 2019-07-16 08:05:24 +02:00
commit b2dd93a231
5 changed files with 35 additions and 1 deletions

View File

@ -33,6 +33,7 @@
<xsd:element name="lock" type="lock" minOccurs="0" maxOccurs="1" />
<xsd:element name="messenger" type="messenger" minOccurs="0" maxOccurs="1" />
<xsd:element name="http-client" type="http_client" minOccurs="0" maxOccurs="1" />
<xsd:element name="mailer" type="mailer" minOccurs="0" maxOccurs="1" />
</xsd:choice>
<xsd:attribute name="http-method-override" type="xsd:boolean" />
@ -543,4 +544,8 @@
<xsd:complexType name="http_header" mixed="true">
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
<xsd:complexType name="mailer">
<xsd:attribute name="dsn" type="xsd:string" />
</xsd:complexType>
</xsd:schema>

View File

@ -0,0 +1,7 @@
<?php
$container->loadFromExtension('framework', [
'mailer' => [
'dsn' => 'smtp://example.com',
],
]);

View File

@ -0,0 +1,12 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
<framework:config>
<framework:mailer dsn="smtp://example.com" />
</framework:config>
</container>

View File

@ -0,0 +1,3 @@
framework:
mailer:
dsn: 'smtp://example.com'

View File

@ -55,7 +55,6 @@ use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
use Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader;
use Symfony\Component\Validator\Util\LegacyTranslatorProxy;
use Symfony\Component\Validator\Validation;
use Symfony\Component\Workflow;
abstract class FrameworkExtensionTest extends TestCase
@ -1552,6 +1551,14 @@ abstract class FrameworkExtensionTest extends TestCase
], $defaultOptions['peer_fingerprint']);
}
public function testMailer(): void
{
$container = $this->createContainerFromFile('mailer');
$this->assertTrue($container->hasAlias('mailer'));
$this->assertTrue($container->hasDefinition('mailer.default_transport'));
}
protected function createContainer(array $data = [])
{
return new ContainerBuilder(new ParameterBag(array_merge([