Skip to content

Commit

Permalink
Merge pull request #3082 from stof/deprecate_swiftmailer
Browse files Browse the repository at this point in the history
Deprecate the TwigSwiftMailer implementation
  • Loading branch information
stof authored Jun 25, 2024
2 parents 0ed476a + 1bd8db5 commit 119ed17
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 19 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

### 3.4.0 (2024-06-25)

* Deprecated the TwigSwiftMailer implementation

### 3.3.0 (2024-06-24)

* Added a mailer implementation based on symfony/mailer and Twig
Expand Down
2 changes: 1 addition & 1 deletion docs/emails.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The bundle comes with 3 mailer implementations. They are listed below
by service id:

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

.. note::
Expand Down
12 changes: 11 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,17 @@ private function addServiceSection(ArrayNodeDefinition $node): void
->arrayNode('service')
->addDefaultsIfNotSet()
->children()
->scalarNode('mailer')->defaultNull()->end()
->scalarNode('mailer')
->defaultNull()
->validate()
->ifInArray(['fos_user.mailer.twig_swift'])
->then(function ($v) {
trigger_deprecation('friendsofsymfony/user-bundle', '3.4.0', 'The twig_swift mailer is deprecated because Swiftmailer itself is unmaintained.');

return $v;
})
->end()
->end()
->scalarNode('email_canonicalizer')->defaultValue('fos_user.util.canonicalizer.default')->end()
->scalarNode('token_generator')->defaultValue('fos_user.util.token_generator.default')->end()
->scalarNode('username_canonicalizer')->defaultValue('fos_user.util.canonicalizer.default')->end()
Expand Down
9 changes: 9 additions & 0 deletions src/DependencyInjection/FOSUserExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
Expand Down Expand Up @@ -77,6 +78,14 @@ public function load(array $configs, ContainerBuilder $container): void
$loader->load(sprintf('%s.xml', $basename));
}

$twigSwiftMailerDefinition = $container->getDefinition('fos_user.mailer.twig_swift');
if (method_exists(Definition::class, 'getDeprecation')) {
$twigSwiftMailerDefinition->setDeprecated('friendsofsymfony/user-bundle', '3.4.0', 'The "%service_id%" service is deprecated. Use a different mailer implementation instead.');
} else {
// BC for Symfony <5.1
$twigSwiftMailerDefinition->setDeprecated('The "fos_user.mailer.twig_swift" service is deprecated. Use a different mailer implementation instead.');
}

if (!$config['use_authentication_listener']) {
$container->removeDefinition('fos_user.listener.authentication');
}
Expand Down
2 changes: 2 additions & 0 deletions src/Mailer/TwigSwiftMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

/**
* @author Christophe Coevoet <[email protected]>
*
* @deprecated
*/
class TwigSwiftMailer implements MailerInterface
{
Expand Down
34 changes: 17 additions & 17 deletions tests/DependencyInjection/FOSUserExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ public function testDisableRegistration()
$loader->load([$config], $this->configuration);
$this->assertNotHasDefinition('fos_user.registration.form.factory');

$mailer = $this->configuration->getDefinition('fos_user.mailer.twig_swift');
$mailer = $this->configuration->getDefinition('fos_user.mailer.twig_symfony');
$parameters = $this->configuration->getParameterBag()->resolveValue(
$mailer->getArgument(3)
);
$this->assertSame(
[
'confirmation' => ['[email protected]' => 'Acme Ltd'],
'resetting' => ['[email protected]' => 'Acme Corp'],
'confirmation' => ['address' => '[email protected]', 'sender_name' => 'Acme Ltd'],
'resetting' => ['address' => '[email protected]', 'sender_name' => 'Acme Corp'],
],
$parameters['from_email']
);
Expand All @@ -122,14 +122,14 @@ public function testDisableResetting()
$loader->load([$config], $this->configuration);
$this->assertNotHasDefinition('fos_user.resetting.form.factory');

$mailer = $this->configuration->getDefinition('fos_user.mailer.twig_swift');
$mailer = $this->configuration->getDefinition('fos_user.mailer.twig_symfony');
$parameters = $this->configuration->getParameterBag()->resolveValue(
$mailer->getArgument(3)
);
$this->assertSame(
[
'confirmation' => ['[email protected]' => 'Acme Corp'],
'resetting' => ['[email protected]' => 'Acme Ltd'],
'confirmation' => ['address' => '[email protected]', 'sender_name' => 'Acme Corp'],
'resetting' => ['address' => '[email protected]', 'sender_name' => 'Acme Ltd'],
],
$parameters['from_email']
);
Expand Down Expand Up @@ -166,8 +166,8 @@ public function testEmailsDisabledFeature($testConfig, $registration, $resetting
$config = array_merge($config, $testConfig);
$loader->load([$config], $this->configuration);

$this->assertParameter($registration, 'fos_user.registration.confirmation.from_email');
$this->assertParameter($resetting, 'fos_user.resetting.email.from_email');
$this->assertParameter($registration, 'fos_user.registration.confirmation.from_address');
$this->assertParameter($resetting, 'fos_user.resetting.email.from_address');
}

public function providerEmailsDisabledFeature()
Expand All @@ -190,13 +190,13 @@ public function providerEmailsDisabledFeature()
],
];

$default = ['[email protected]' => 'Acme Corp'];
$overriden = ['[email protected]' => 'Acme Ltd'];
$default = ['address' => '[email protected]', 'sender_name' => 'Acme Corp'];
$overriden = ['address' => '[email protected]', 'sender_name' => 'Acme Ltd'];

return [
[$configBothFeaturesDisabled, ['[email protected]' => 'Acme Ltd'], ['[email protected]' => 'Acme Ltd']],
[$configResettingDisabled, $default, ['[email protected]' => 'Acme Ltd']],
[$configRegistrationDisabled, ['[email protected]' => 'Acme Ltd'], $default],
[$configBothFeaturesDisabled, ['address' => '[email protected]', 'sender_name' => 'Acme Ltd'], ['address' => '[email protected]', 'sender_name' => 'Acme Ltd']],
[$configResettingDisabled, $default, ['address' => '[email protected]', 'sender_name' => 'Acme Ltd']],
[$configRegistrationDisabled, ['address' => '[email protected]', 'sender_name' => 'Acme Ltd'], $default],
[$configOverridenRegistrationEmail, $overriden, $default],
[$configOverridenResettingEmail, $default, $overriden],
];
Expand Down Expand Up @@ -289,10 +289,10 @@ public function testUserLoadConfirmationEmailWithDefaults()
$this->createEmptyConfiguration();

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

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

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

Expand Down

0 comments on commit 119ed17

Please sign in to comment.