15 Dec 2019

feedSymfony Blog

A Week of Symfony #676 (9-15 December 2019)

This week, the upcoming Symfony 5.1 version added MongoDB support for the Lock component, exception pages enabled the "dark theme" and the MicroKernelTrait was improved to make it easier to use and configure.

Symfony development highlights

This week, 74 pull requests were merged (38 in code and 36 in docs) and 54 issues were closed (34 in code and 20 in docs). Excluding merges, 31 authors made 1,421 additions and 752 deletions. See details for code and docs.

3.4 changelog:

4.3 changelog:

4.4 changelog:

Master changelog:

Symfony Local Server

Symfony Local Server, the best way to run Symfony applications on your local machine, released its new 4.11.3 version with the following changes:

Newest issues and pull requests

They talked about us

Upcoming Symfony Events

Call to Action


Be trained by Symfony experts - 2019-12-16 Lyon - 2019-12-16 Lille - 2020-01-13 Clichy

15 Dec 2019 9:27am GMT

12 Dec 2019

feedSymfony Blog

Symfony Type Declarations, Return Types and PHPUnit Compatibility

If you follow the Living on the Edge category of this blog, you'll find all the latest and greatest new features of each Symfony version. Big and small features that help you create your projects while having the best possible developer experience.

However, this is only part of the development activity needed to create and maintain Symfony. In this blog post we'll mention some changes that required hundreds of hours of work but remained invisible because they are not part of a shiny new feature.

Added PHP Type Declarations

PHP type declarations (or "type hints") add information about the data types of the function and method arguments. Symfony code didn't have type declarations yet because, according to the Symfony Release Process, we cannot add the latest PHP features right away and we need to wait until certain Symfony versions are released to make those changes.

Symfony 5.0 was the perfect moment to add these type declarations to our entire code base. This was a painstaking process because, even if some work could be automated, each change had to be reviewed manually.

The reason is that it's not only about removing PHPdoc comments and adding the types to the method arguments. You also need to check the rest of the code to look for data type castings. For example:

1
2
3
4
5
6
7
8
-/**
- * @param bool|null $enabled
- */
-public function setStrictRequirements($enabled)
+public function setStrictRequirements(?bool $enabled)
{
-    $this->strictRequirements = null === $enabled ? null : (bool) $enabled;
+    $this->strictRequirements = $enabled;

Check out the Pull Request #32179 to get an idea of the size of this change. Tens of thousands of lines were changed in thousands of files and tens of hours were spent reviewing and merging everything.

Thanks to @jschaedl, @Simperfit, @Tobion, @Matts, @smoench, @vudaltsov, @julien57, @azjezz, @tigitz, @andreia, @thomasbisignani, @lyrixx, @xabbuh for contributing these changes. Special thanks to @derrabus for coordinating the work and to @nicolas-grekas for doing the actual merge and conflict solving.

Added PHP Return Types

PHP return types allow functions and methods to specify the data type of their returned values. We considered adding these return types in Symfony 5.0 but we finally didn't do it because of two reasons:

  • The burden this would put on the community is immense, because third-party libraries and bundles should also be updated to be compatible with this new Symfony code that includes return types. In other words, Symfony should be the last to add these return types, not the first one.
  • Given the complexity and flexibility of Symfony's code base, we'd need return type covariance, which is only available in PHP 7.4 (Symfony 5.x requires PHP 7.2).

In any case, we have a plan to add these return types in Symfony 6.0. Check out the Pull Request #33236 to see the clever trick used to add these return types automatically thanks to the DebugClassLoader. Special thanks to @fancyweb for fixing all current return types defined in PHPdoc comments (see Pull Request #30323).

Added Compatibility with All PHP and PHPUnit Versions

The last recent feature that required an insane amount of work but developers take it for granted is the PHPUnit Bridge compatibility with all PHP versions from 5.5 to 7.4 and all PHPUnit versions from 4.8 to 8.0.

As mentioned in the New in Symfony 4.4: PHPUnit Polyfills blog post, we added lots of polyfills to make most of PHPUnit features available regardless of the PHPUnit version used in your application. This is needed for Symfony's own testing but will also help those applications that must keep a broad compatibility with legacy PHP and PHPUnit versions.

Check out the Pull Request #32844 to see the tens of related pull requests that were needed to achieve this. Special thanks to @jderusse who did most of the work related to this feature.


Be trained by Symfony experts - 2019-12-16 Lyon - 2019-12-16 Lille - 2020-01-13 Clichy

12 Dec 2019 7:32am GMT

11 Dec 2019

feedSymfony Blog

New in Symfony 4.4: WebProfiler Improvements

Mailer Integration

Fabien Potencier

Contributed by
Fabien Potencier
in #32912.

The new Symfony Mailer was introduced in Symfony 4.3. In Symfony 4.4 we improved and polished it, including the integration with the profiler. The debug toolbar now displays the number of messages sent. If you click on it, you'll see the full message details in the new profiler panel:

The new Mailer web profiler panel in Symfony 4.4

Clear Ajax Requests

Matts

Contributed by
Matts
in #31876.

When making too many Ajax requests or keeping a page open for too long, the debug toolbar gets crowded with a long list of Ajax requests. In Symfony 4.4, you can click on the new Clear link to delete all the existing Ajax requests so you can see the new requests more clearly:

The new Clear link in the list of Ajax requests in the Symfony 4.4 web debug toolbar

Auto-Select the Best Panel for Ajax Requests

Thomas Calvet

Contributed by
Thomas Calvet
in #33783.

When you click on any element of the debug toolbar, you are redirected to its related panel (request, forms, logs, database, etc.) However, for Ajax requests we only display a link to its profile, so you cannot select the first panel displayed.

In Symfony 4.4, we made this link smarter to redirect to the most important panel for each request. For example, if the Ajax request resulted in an exception, you are redirected to the exception panel; if you dumped some information in the Ajax request, you are redirected to the dump panel; etc.

It's a small change, but it will save you some clicks and will improve your developer experience.

Compress Profiler Files

Nicolas Grekas

Contributed by
Nicolas Grekas
in #33698.

The data collected for each request is stored in an array structure before serializing and storing it the var/cache/ directory of your project. This data is not deleted automatically, so it can grow up pretty quickly.

In Symfony 4.4, if your system allows it, we compress the data automatically before saving it to disk. For a typical profile, the disk space usage decreases from 150 KB to 15 KB (for each profile).

HttpClient Integration

Timothée Barray Jérémy Romey

Contributed by Timothée Barray and Jérémy Romey in #33015.

The HttpClient component was also introduced in Symfony 4.3. In Symfony 4.4, besides several tweaks and improvements, we've added profiler integration for it. The debug toolbar now displays the number of HTTP requests and if you click on that, you'll see the full details of all requests:

The new HttpClient web profiler panel in Symfony 4.4

Be trained by Symfony experts - 2019-12-16 Lyon - 2019-12-16 Lille - 2020-01-13 Clichy

11 Dec 2019 12:25pm GMT