Cover of the book Symfony 5: The Fast Track

Symfony 5: The Fast Track is the best book to learn modern Symfony development, from zero to production. +300 pages in full color showing how to combine Symfony with Docker, APIs, queues & async tasks, Webpack, Single-Page Applications, etc.

Buy printed version

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

This article showcases some minor but useful new features added to Symfony 5.1 that will make your development work easier. This is also the last article in the New in Symfony 5.1 series, which contains 47 articles in total.

Allow to include the severity in ConstraintViolationList

Contributed by
Kévin Dunglas
in #35545.

Symfony Validator component allows to include a payload in constraint violations with the error severity and other data. In Symfony 5.1 we've improved the Serializer component to also allow adding a payload with data in the ConstraintViolationList:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
use Symfony\Component\Serializer\Normalizer\ConstraintViolationListNormalizer;
use Symfony\Component\Validator\Constraints\NotNull;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;

$constraint = new NotNull();
$constraint->payload = ['severity' => 'warning', 'someOtherField' => 'someValue'];
$list = new ConstraintViolationList([
    new ConstraintViolation(/* ... */, $constraint),
]);

$result = $this->normalizer->normalize($list, null, [
    // pass an array of field names to add only those to the payload
    // pass NULL or TRUE to pass all fields
    ConstraintViolationListNormalizer::PAYLOAD_FIELDS => ['severity']]
);
$payload = $result['violations'][0]['payload'];
// $payload = ['severity' => 'warning'];

Mailer Log Handler

Contributed by
Alexander Borisov
in #33456.

In your Symfony applications, logging should be managed using dedicated tools or services. However, in some circumstances (e.g. while prototyping, when developing tiny apps, etc.) sending logs via email when an error happens may be a valid solution, all things considered.

That's why in Symfony 5.1 we added a new Monolog log handler which uses the Mailer component to send the logs via email.

New Deprecation Contract

Contributed by
Nicolas Grekas
in #35526 and #35648.

Symfony Contracts are a set of abstractions extracted out of the Symfony components. In Symfony 5.1 we've started using a new contract related to deprecations. The only method provided by the contract is:

1
trigger_deprecation(string $package, string $version, string $message, ...$args): void;

This will provide more meaningful and standardized deprecation messages in your applications, so we've updated Symfony's own code to use the new method:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// Before
@trigger_error(
    'Not setting the "framework.router.utf8" configuration option is deprecated
    since Symfony 5.1, it will default to "true" in Symfony 6.0.',
    E_USER_DEPRECATED
);

// After
trigger_deprecation(
    'symfony/framework-bundle', '5.1',
    'Not setting the "framework.router.utf8" configuration option is deprecated,
    it will default to "true" in version 6.0.'
);

Dark Mode in Exception Pages

Contributed by
Javier Eguiluz
in #34924.

Adding support for "dark mode" or "dark themes" is increasingly popular in developer tools. We already implement that feature in symfony.com and the Symfony Profiler, but in Symfony 5.1 we also added support for dark mode in exception pages.

Check out the Pull Request #34924 to see some screenshots of this new design.

Help the Symfony project!

As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.

New in Symfony 5.1: Misc. improvements (Part 3) symfony.com/blog/new-in-symfony-5-1-misc-improvements-part-3

Tweet this

Comments

Thank you for the articles Javier. :)
LOVE the dark mode exceptions :)
Dark mode exceptions 💞

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.