Skip to content

Commit 119ed17

Browse files
authored
Merge pull request #3082 from stof/deprecate_swiftmailer
Deprecate the TwigSwiftMailer implementation
2 parents 0ed476a + 1bd8db5 commit 119ed17

File tree

6 files changed

+44
-19
lines changed

6 files changed

+44
-19
lines changed

Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelog
22
=========
33

4+
### 3.4.0 (2024-06-25)
5+
6+
* Deprecated the TwigSwiftMailer implementation
7+
48
### 3.3.0 (2024-06-24)
59

610
* Added a mailer implementation based on symfony/mailer and Twig

docs/emails.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The bundle comes with 3 mailer implementations. They are listed below
4242
by service id:
4343

4444
- ``fos_user.mailer.twig_symfony`` uses symfony/mailer to send emails and Twig blocks to render the message.
45-
- ``fos_user.mailer.twig_swift`` uses Swiftmailer to send emails and Twig blocks to render the message.
45+
- ``fos_user.mailer.twig_swift`` (deprecated) uses Swiftmailer to send emails and Twig blocks to render the message.
4646
- ``fos_user.mailer.noop`` is a mailer implementation which performs no operation, so no emails are sent.
4747

4848
.. note::

src/DependencyInjection/Configuration.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,17 @@ private function addServiceSection(ArrayNodeDefinition $node): void
223223
->arrayNode('service')
224224
->addDefaultsIfNotSet()
225225
->children()
226-
->scalarNode('mailer')->defaultNull()->end()
226+
->scalarNode('mailer')
227+
->defaultNull()
228+
->validate()
229+
->ifInArray(['fos_user.mailer.twig_swift'])
230+
->then(function ($v) {
231+
trigger_deprecation('friendsofsymfony/user-bundle', '3.4.0', 'The twig_swift mailer is deprecated because Swiftmailer itself is unmaintained.');
232+
233+
return $v;
234+
})
235+
->end()
236+
->end()
227237
->scalarNode('email_canonicalizer')->defaultValue('fos_user.util.canonicalizer.default')->end()
228238
->scalarNode('token_generator')->defaultValue('fos_user.util.token_generator.default')->end()
229239
->scalarNode('username_canonicalizer')->defaultValue('fos_user.util.canonicalizer.default')->end()

src/DependencyInjection/FOSUserExtension.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Config\FileLocator;
1717
use Symfony\Component\DependencyInjection\Alias;
1818
use Symfony\Component\DependencyInjection\ContainerBuilder;
19+
use Symfony\Component\DependencyInjection\Definition;
1920
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2021
use Symfony\Component\DependencyInjection\Reference;
2122
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
@@ -77,6 +78,14 @@ public function load(array $configs, ContainerBuilder $container): void
7778
$loader->load(sprintf('%s.xml', $basename));
7879
}
7980

81+
$twigSwiftMailerDefinition = $container->getDefinition('fos_user.mailer.twig_swift');
82+
if (method_exists(Definition::class, 'getDeprecation')) {
83+
$twigSwiftMailerDefinition->setDeprecated('friendsofsymfony/user-bundle', '3.4.0', 'The "%service_id%" service is deprecated. Use a different mailer implementation instead.');
84+
} else {
85+
// BC for Symfony <5.1
86+
$twigSwiftMailerDefinition->setDeprecated('The "fos_user.mailer.twig_swift" service is deprecated. Use a different mailer implementation instead.');
87+
}
88+
8089
if (!$config['use_authentication_listener']) {
8190
$container->removeDefinition('fos_user.listener.authentication');
8291
}

src/Mailer/TwigSwiftMailer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
/**
1919
* @author Christophe Coevoet <[email protected]>
20+
*
21+
* @deprecated
2022
*/
2123
class TwigSwiftMailer implements MailerInterface
2224
{

tests/DependencyInjection/FOSUserExtensionTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ public function testDisableRegistration()
100100
$loader->load([$config], $this->configuration);
101101
$this->assertNotHasDefinition('fos_user.registration.form.factory');
102102

103-
$mailer = $this->configuration->getDefinition('fos_user.mailer.twig_swift');
103+
$mailer = $this->configuration->getDefinition('fos_user.mailer.twig_symfony');
104104
$parameters = $this->configuration->getParameterBag()->resolveValue(
105105
$mailer->getArgument(3)
106106
);
107107
$this->assertSame(
108108
[
109-
'confirmation' => ['[email protected]' => 'Acme Ltd'],
110-
'resetting' => ['[email protected]' => 'Acme Corp'],
109+
'confirmation' => ['address' => '[email protected]', 'sender_name' => 'Acme Ltd'],
110+
'resetting' => ['address' => '[email protected]', 'sender_name' => 'Acme Corp'],
111111
],
112112
$parameters['from_email']
113113
);
@@ -122,14 +122,14 @@ public function testDisableResetting()
122122
$loader->load([$config], $this->configuration);
123123
$this->assertNotHasDefinition('fos_user.resetting.form.factory');
124124

125-
$mailer = $this->configuration->getDefinition('fos_user.mailer.twig_swift');
125+
$mailer = $this->configuration->getDefinition('fos_user.mailer.twig_symfony');
126126
$parameters = $this->configuration->getParameterBag()->resolveValue(
127127
$mailer->getArgument(3)
128128
);
129129
$this->assertSame(
130130
[
131-
'confirmation' => ['[email protected]' => 'Acme Corp'],
132-
'resetting' => ['[email protected]' => 'Acme Ltd'],
131+
'confirmation' => ['address' => '[email protected]', 'sender_name' => 'Acme Corp'],
132+
'resetting' => ['address' => '[email protected]', 'sender_name' => 'Acme Ltd'],
133133
],
134134
$parameters['from_email']
135135
);
@@ -166,8 +166,8 @@ public function testEmailsDisabledFeature($testConfig, $registration, $resetting
166166
$config = array_merge($config, $testConfig);
167167
$loader->load([$config], $this->configuration);
168168

169-
$this->assertParameter($registration, 'fos_user.registration.confirmation.from_email');
170-
$this->assertParameter($resetting, 'fos_user.resetting.email.from_email');
169+
$this->assertParameter($registration, 'fos_user.registration.confirmation.from_address');
170+
$this->assertParameter($resetting, 'fos_user.resetting.email.from_address');
171171
}
172172

173173
public function providerEmailsDisabledFeature()
@@ -190,13 +190,13 @@ public function providerEmailsDisabledFeature()
190190
],
191191
];
192192

193-
$default = ['[email protected]' => 'Acme Corp'];
194-
$overriden = ['[email protected]' => 'Acme Ltd'];
193+
$default = ['address' => '[email protected]', 'sender_name' => 'Acme Corp'];
194+
$overriden = ['address' => '[email protected]', 'sender_name' => 'Acme Ltd'];
195195

196196
return [
197-
[$configBothFeaturesDisabled, ['[email protected]' => 'Acme Ltd'], ['[email protected]' => 'Acme Ltd']],
198-
[$configResettingDisabled, $default, ['[email protected]' => 'Acme Ltd']],
199-
[$configRegistrationDisabled, ['[email protected]' => 'Acme Ltd'], $default],
197+
[$configBothFeaturesDisabled, ['address' => '[email protected]', 'sender_name' => 'Acme Ltd'], ['address' => '[email protected]', 'sender_name' => 'Acme Ltd']],
198+
[$configResettingDisabled, $default, ['address' => '[email protected]', 'sender_name' => 'Acme Ltd']],
199+
[$configRegistrationDisabled, ['address' => '[email protected]', 'sender_name' => 'Acme Ltd'], $default],
200200
[$configOverridenRegistrationEmail, $overriden, $default],
201201
[$configOverridenResettingEmail, $default, $overriden],
202202
];
@@ -289,10 +289,10 @@ public function testUserLoadConfirmationEmailWithDefaults()
289289
$this->createEmptyConfiguration();
290290

291291
$this->assertParameter(false, 'fos_user.registration.confirmation.enabled');
292-
$this->assertParameter(['[email protected]' => 'Acme Corp'], 'fos_user.registration.confirmation.from_email');
292+
$this->assertParameter(['address' => '[email protected]', 'sender_name' => 'Acme Corp'], 'fos_user.registration.confirmation.from_address');
293293
$this->assertParameter('@FOSUser/Registration/email.txt.twig', 'fos_user.registration.confirmation.template');
294294
$this->assertParameter('@FOSUser/Resetting/email.txt.twig', 'fos_user.resetting.email.template');
295-
$this->assertParameter(['[email protected]' => 'Acme Corp'], 'fos_user.resetting.email.from_email');
295+
$this->assertParameter(['address' => '[email protected]', 'sender_name' => 'Acme Corp'], 'fos_user.resetting.email.from_address');
296296
$this->assertParameter(86400, 'fos_user.resetting.token_ttl');
297297
}
298298

@@ -301,10 +301,10 @@ public function testUserLoadConfirmationEmail()
301301
$this->createFullConfiguration();
302302

303303
$this->assertParameter(true, 'fos_user.registration.confirmation.enabled');
304-
$this->assertParameter(['[email protected]' => 'Acme Corp'], 'fos_user.registration.confirmation.from_email');
304+
$this->assertParameter(['address' => '[email protected]', 'sender_name' => 'Acme Corp'], 'fos_user.registration.confirmation.from_address');
305305
$this->assertParameter('AcmeMyBundle:Registration:mail.txt.twig', 'fos_user.registration.confirmation.template');
306306
$this->assertParameter('AcmeMyBundle:Resetting:mail.txt.twig', 'fos_user.resetting.email.template');
307-
$this->assertParameter(['[email protected]' => 'Acme Corp'], 'fos_user.resetting.email.from_email');
307+
$this->assertParameter(['address' => '[email protected]', 'sender_name' => 'Acme Corp'], 'fos_user.resetting.email.from_address');
308308
$this->assertParameter(7200, 'fos_user.resetting.retry_ttl');
309309
}
310310

0 commit comments

Comments
 (0)