PHPnews.io

New in Symfony 5.1: Misc. improvements (Part 2)

Written by Symfony blog / Original link on May. 28, 2020

YAML linter command

c6cd8201-8f41-4f70-a051-63d89a8fe9b6.png

Contributed by
Jan Schädlich
in #34387.

Symfony includes a linter that checks the validity of the syntax of your YAML config files. It's available under the lint:yaml command, but requires using the entire Symfony project console application.

In Symfony 5.1 we added a single-command application called yaml-lint so you can lint YAML files using only the Yaml and Console components:

1
$ php vendor/bin/yaml-lint translations/

Improved RoundRobin mailer transport

f1a2c5905e121d09feba5ad73898ffca

Contributed by
Fabien Potencier
in #35525.

If your application doesn't use the Messenger component to send emails and sends just one message, the RoundRobin transport doesn't work as expected, because its first transport is always used. In Symfony 5.1 we improved it to select the first transport randomly.

Separate log channel for deprecations

ee688cc3d1fc875cbe8675d87f40b85f

Contributed by
Laurent Voullemier
in #36621.

Deprecation messages are the key of the Symfony Backward Compatibility Promise, which ensures a smooth upgrade between minor Symfony versions. However, sometimes it's overwhelming to see lots of deprecations in your log files. In other projects, you may want to focus exclusively on deprecations, so the other log messages only complicate things.

That's why in Symfony 5.1 we've added some optional configuration in the config/packages/prod/monolog.yaml file to log the deprecations in a separate file. The new config is commented by default, so you need to enable it explicitly if you want to use it.

Added support for mailer tags/metadata

d64dd257ad0745f676d423dc03e4a37c

Contributed by
Kevin Bond in #35050.

Some mailing services allow to define tags/metadata in your messages to add any data that may be useful for your application. In Symfony 5.1 we added support for them in mailers such as Postmark and Mailgun:

1
2
3
4
5
6
use Symfony\Component\Mailer\Header\MetadataHeader;
use Symfony\Component\Mailer\Header\TagHeader;

$email->getHeaders()->add(new TagHeader('password-reset'));
$email->getHeaders()->add(new MetadataHeader('Color', 'blue'));
$email->getHeaders()->add(new MetadataHeader('Client-ID', '12345'));

In mailers that support these features, you'll see the data in the custom headers or payload of the messages. In the rest of mailers, you'll see them as custom headers:

1
2
3
X-Tag: password-reset
X-Metadata-Color: blue
X-Metadata-Client-ID: 12345
Sponsor the Symfony project.

symfony

« Surface Book 3 review: the web developer's laptop [link] - Generate a Unique Series of Values with Earmark »