问题
After updating symfony/swiftmailer-bundle to v2.2.5 with composer.phar update I get such error:
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Removing symfony/swiftmailer-bundle (v2.2.4)
- Installing symfony/swiftmailer-bundle (v2.2.5)
Loading from cache
Writing lock file
Generating autoload files
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
The service definition "swiftmailer.mailer" does not exist.
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception
[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command.
Problem is fixed after downgrading to 2.2.4
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Removing symfony/swiftmailer-bundle (v2.2.5)
- Installing symfony/swiftmailer-bundle (v2.2.4)
Loading from cache
Writing lock file
Generating autoload files
Clearing the cache for the dev environment with debug true
Installing assets using the hard copy option
Installing assets (part of code removed)
回答1:
You should definitely use mailer
service, as it's an alias to the correct swiftmailer service, regardless how it named. For example im v2.3.3 it's swiftmailer.mailer.default
But you have to use
$container->findDefinition('mailer');
which unlike
getDefinition()
also resolves aliases so if the$serviceId
argument is an alias you will get the underlying definition.
回答2:
The line that triggerd the error was:
$definition = $container->getDefinition('swiftmailer.mailer') ;
Error was caused by change of service name. Until 2.2.4 the name was
swiftmailer.mailer
and since 2.2.5 it is:
swiftmailer.mailer.abstract
I changed the line to:
$definition = $container->hasDefinition('swiftmailer.mailer') ? $container->getDefinition('swiftmailer.mailer') : $container->getDefinition('swiftmailer.mailer.abstract');
That fixed the error.
来源:https://stackoverflow.com/questions/18182794/error-after-updating-symfony-swiftmailer-bundle-to-2-2-5