Symfony 4: Compose your Applications - Fabien Potencier

  • Автор темы Planet PHP
  • Дата начала

Planet PHP

Guest
Note: If you are a Medium user, my new articles are now cross-posted there as well.

Note: Symfony 4.0 will be released at the end of November 2017. During the next few weeks, I will publish articles about my ideas and the main changes I want to implement for Symfony 4.

Symfony 3.0 was boring, a cleaned-up version of the Symfony 2.8 version:


Symfony 3.0 = Symfony 2.8 - deprecated features

Symfony 4.0 will be different:


Symfony 4.0 = Symfony 3.4 - deprecated features + a new way to develop applications

There is another way to think about a new major version though:


Symfony 4.0 = Symfony 3.0 + all features added in 3.x - deprecated features + a new way to develop applications

Symfony 4.0 will also require PHP 7.

While thinking about what needs to be changed for Symfony 4, I thought about the day-to-day experience of managing an application.

Installing a Bundle is too cumbersome#


The current best way to add more dependencies to a Symfony application is to install bundles and libraries via Composer packages.

Fun fact: Composer started as a conversation about how to generically install bundles/plugins/extensions for Symfony and phpBB.

WTF fact: Neither Symfony nor phpBB uses Composer as a way to install its bundles/plugins/extensions.

When installing a Symfony bundle, using Composer is not enough; you also need to enable and configure the bundle correctly before using its features. Here are the typical steps you need to perform:


  • Execute composer require symfony/bundle; it must be manual as developers are in charge of selecting the packages they want to install; however, we will see that we can make it better when installing dependencies in the context of a Symfony application (hint: wouldn't it be cool to run composer req cli, composer req admin, or composer req mailer?);


  • Register the bundle in the AppKernel class;


  • Register some routes (optional);

  • Configure the bundle as you see fit.

The first step cannot be automated, but it feels like the other ones could be. Configuration cannot be automated but we can probably generate good defaults like done in the Symfony Standard Edition for some bundles.

Have a look at the documentation of popular bundles. Their READMEs all start with the same boring dance.

Removing a Bundle is even more cumbersome#


From time to time you might want to remove a bundle. How can you do that? Simple enough: composer remove symfony/bundle.

Well, that's not enough.

Remember how we needed to register the bundle, add routes wiring, and configuration? We need to undo that now, too. This means visiting several files to remove the bundle. This makes removing a bundle a boring and error-prone process.

The Symfony Standard Edition is not good enough#


Symfony Distributions was an attempt to fix some of these issues by providing a good starting point.

The most popular one, the Symfony Standard Edition, is "optimized" for "traditional" frontend applications for which you need a database, a templating system, and a way to send emails. But is it still relevant? What if you want to start a micro-framework style application? Or an API/web service one?

The Symfony Standard Edition makes choices for the developer, but either too few or too many. Symfony Distributions do not scale well; it is not easy to remove dependencies, and it is not that easy to add new ones.



Another issue with distributions is that they come with files that you don't want for your project. Like the LICENSE and the README files. Most projects are not MIT-licensed and the authors are probably different from the ones who worked on the distribution. In the same vein, you have to change almost all entries of the composer.json file.

Removing a few files is no problem, but it adds up quickly.

A few years back, the Symfony Standard Edition came with a small demo to get you started faster. But we removed i

Truncated by Planet PHP, read more at the original (another 3353 bytes)

Читать дальше...
 
Сверху