New in Symfony 5.4: Misc. features (part 3)

This is the last blog post of the blog series that shows the new features of Symfony 5.4 and 6.0. We hope you enjoyed it and now want to upgrade your Symfony applications to these new versions.

Longer RateLimiter Intervals

        Contributed by Alexandre Daubois 
        in #43060.

The RateLimiter component provides a Token Bucket implementation to rate limit input and output in your application. It's commonly used in features like login throttling (e.g. allow up to 5 failed login attempts every hour) and API constraints (e.g. allow up to 1,000 requests per hour). However, some applications need longer intervals to only allow a certain number of evens per month or even per year. That's why in Symfony 5.4 we're adding the perMonth() and perYear() methods to the RateLimiter component.

Simpler Way of Creating Constraint Errors

        Contributed by Grégoire Pineau 
        in #41154.

When using the Validator component, if some validation fails, you get a non-empty list of errors in the form of a ConstraintViolationList class. You need to do the same when creating validation errors yourself. This is cumbersome when you only have one error:

    1

2 3 4 5 $violations = new ConstraintViolationList(); $violations->add(new ConstraintViolation('A publish is already running.', '', [], null, '', null));

// e.g. when using ApiPlatform\Core\Bridge\Symfony\Validator\Exception\ValidationException throw new ValidationException($violations);

In Symfony 5.4 we've added a new createSingleConstraint() method so simplify the creation of single-error validation errors:

    1

2 3 $violations = ConstraintViolationList::createSingleConstraint('A publish is already running.');

throw new ValidationException($violations);

Lock Files When Appending To Them

        Contributed by fwolfsjaeger 
        in #43796.

The Filesystem component provides OS-independent features related to the file system. One of those utilities is the appendToFile() method, which adds some content at the end of some file. In Symfony 5.4 we've improved it with a third optional boolean argument. If set to true, Symfony will acquire an exclusive lock on the file while proceeding to the writing (it's the same as the \LOCK_EX flag in PHP).

    1

2 3 4 $filesystem->appendToFile('logs.txt', 'Email sent to user@example.com');

// the third argument tells whether the file should be locked when writing to it $filesystem->appendToFile('logs.txt', 'Email sent to user@example.com', true);

PhpStan Extractor for PropertyInfo

        Contributed by Baptiste Leduc 
        in #40457.

The PropertyInfo component extracts information about the properties of PHP classes using metadata of popular sources (Doctrine, PHP Reflection, PHPdoc, etc.) In Symfony 5.4 we're adding support to extract information based on the metadata defined for PHPStan, a popular PHP static analysis tool. This will allow you to extract information from metadata like the following:

    1

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 class SomeClass { /* @var string|int / public $property1;

/** @var (string|int)[] */
public $property2;

/** @var array */
public $property3;

/** @var array */
public $property4;

/** @var (Dummy | ParentDummy | null) */
public $property5;

}

Did you know? Your company can sponsor the Filesystem, RateLimiter, PropertyInfo or any of the other Symfony components. Show your logo, link and description next to some component both on symfony.com and GitHub. Increase the awareness of your brand, attract new developers to your company and help support the Open Source Symfony project. Interested? Contact us via the "Symfony Backers" option of the Symfony Support page.

                Sponsor the Symfony project.

https://symfony.com/blog/new-in-symfony-5-4-misc-features-part-3?utm_source=Symfony%20Blog%20Feed&utm_medium=feed

Erstellt 4y | 03.12.2021, 09:20:05


Melden Sie sich an, um einen Kommentar hinzuzufügen

Andere Beiträge in dieser Gruppe

SymfonyOnline June 2025: Speakers, Stats & Replays!

Thank you for joining us at SymfonyOnline June 2025!

What a great edition of SymfonyOnline we’ve just wrapped up! 🎉

We were thrilled to welcome 300 participants from 35 different countries—a

18.06.2025, 08:50:17 | Symfony
A Week of Symfony #963 (June 9–15, 2025)

This week, Symfony celebrated the SymfonyOnline June 2025 conference with great success. Meanwhile, development efforts focused on improving invokable commands for the upcoming Symfony 7.4 version. Th

15.06.2025, 09:10:09 | Symfony
A Week of Symfony #962 (June 2–8, 2025)

This week, development activity focused on the upcoming Symfony 7.4 and 8.0 versions, which will deprecate and remove many features. In addition, we published a case study about Yousign. Finally, we'r

08.06.2025, 07:50:05 | Symfony
Case study - Yousign: Scaling Trust with Smart, Scalable Architecture

As digital signatures become the norm in modern business, Yousign has established itself as a trusted leader across Europe. Behind its simple, intuitive interface is a powerful technical engine, handl

06.06.2025, 07:10:24 | Symfony
SymfonyOnline June 2025 starts next week!

Get ready for the exciting SymfonyOnline June 2025, kicking off in a few days only! There’s still time to register and join the international online Symfony conference—along with pre-conferenc

05.06.2025, 10:20:09 | Symfony
A Week of Symfony #961 (May 26 – June 1, 2025)

This week, Symfony released the stable version of Symfony 7.3, which includes lots of amazing new features. We also published the maintenance versions 6.4.22 and 7.2.7.

Symfony development highlights

01.06.2025, 08:50:16 | Symfony
New in Symfony 7.3: DX Improvements (part 2)

This is the second part of the blog post showcasing the main DX (developer experience) features introduced in Symfony 7.3. Read the first part of this blog post.

Verify URI Signatures… https://symfon

29.05.2025, 09:10:19 | Symfony