Skip to content

Commit

Permalink
Deprecate the TwigSwiftMailer implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
stof committed Jun 25, 2024
1 parent 4ef57b3 commit 1bd8db5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 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

0 comments on commit 1bd8db5

Please sign in to comment.