January 28, 2019 Javier Eguiluz

Deprecations are the key of our backward compatibility promise, which ensures smooth upgrades of your projects between minor versions (e.g. from 4.0 to 4.x). In order to provide a great developer experience, your own Symfony apps can also deprecate services, deprecate config options and even deprecate Twig templates, blocks and macros.

In Symfony 4.3, you'll also be able to deprecate service aliases. When an alias should no longer be used in your application, define it as deprecated with the deprecated configuration option:

YAML 1 2 3 4 5 6 7 # config/services.yaml services : # ... app.mailer : alias : App\Mail\PhpMailer deprecated : ~

XML 1 2 3 4 5 6 7 8 9 10 <?xml version="1.0" encoding="utf-8"?> <container xmlns= "http://symfony.com/schema/dic/services" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" > <services> <!-- ... --> <service id= "app.mailer" alias= "App\Mail\PhpMailer" > <deprecated /> </service> </services> </container>

PHP 1 2 3 4 5 // ... $container -> setAlias ( 'app.mailer' , 'App\Mail\PhpMailer' ) -> setDeprecated ( true );

If this alias is used anywhere in your app, you'll see a generic error message. If you prefer to customize that message, define it using the deprecated option (the only requirement is that the message must include the %alias_id% placeholder):