phparchitect-2019-08

(Rick Simeone) #1
4 \ August 2019 \ http://www.phparch.com

Symfony 4: A New Way to Develop Applications

Symfony 3 was boring, a cleanup version of Symfony2.8.
In Symfony 3, nothing special happened. It was a transition
period from Symfony 2 to Symfony 4, so we locked features;
there was a lot of deprecated code, which was later removed in
Symfony 4. Just for note, Symfony 3.4 was the slowest release^4
of Symfony ever (deprecated features are probably one cause)
Figure 1 outlines the evolution in composing Symfony^5 appli-
cations.

Symfony 4—A New King in PHP World
Symfony 4 was released on November 30th, 2017 and it is
by far the best Symfony version ever. Symfony 4^6 represents
a rethinking of its ideas and features from the ground up to
match the industry practices. First, application bundles are
gone, and config parameters are now environment variables.
The application directory structure is easier to navigate, and
there are hundreds of other small improvements to make you
love Symfony. The result is less Symfony concepts and more
standard practices. It’s easier to learn, easier to configure,
easier to install and deploy, and easier to master.
Symfony 4 is following the trend of modern web appli-
cations. It can be a fullstack framework, but it can also be a
tiny application. For example, it can be a simple command
(terminal) application that does only one thing. New appli-
cations created with Symfony 4 are based on a micro-kernel
and contain 70% less code and files than new Symfony 3 apps.
It removed a lot of non-essential dependencies were removed,
and the result is the smallest footprint across all PHP frame-
works. And, Symfony 4 is faster than ever.


Framework Composition and Better
Developer Experience
Getting started with Symfony 2 was easy, but installing
bundles and extending the framework was too cumbersome.
Removing a bundle was even more cumbersome. The flow
was always the same; require it via Composer and then follow

4 slowest release: https://phpa.me/symfony4-performance
5 composing Symfony: https://phpa.me/symfony-compose-app


6 Symfony 4: https://symfony.com/


n-steps to set up the plugin. Once you test it and see it isn’t
right, you have to backtrack. Did you ever try to remove
Forms or Twig from Symfony 2? It was painful! So, this
system was broken and was not even close to being a plug-
and-play system.

Fun Fact: Composer started as a conversation about
how to generically install bundles, plugins, and extensions
for Symfony and phpBB.
WTF Fact: Neither Symfony nor phpBB uses Composer
as a way to install its bundles, plugins, or extensions.

The distribution system was a good idea but didn’t work.
The only popular and useful distribution was Symfony Stan-
dard edition. Most projects, if not all of them, were started by
using this distribution, and then developers used inheritance
to build their apps. The result was a standard distribution
with some third-party bundles added. In the beginning, the
standard edition included a demo app as a showcase on
how to work with Symfony. Removing it every time a new
project was started was time-consuming and not something
that you wanted to do. After a while, it was removed, but new
developers didn’t have any example to follow. Also, there was
always a feeling it included a lot of code which was not used
and that the app was slow and not optimized. It was not an
ideal or even a good developers experience (DX).

"As a developer, I want to start small, without too many
dependencies. But I also want to be able to grow my appli-
cation as I see fit. From a micro-framework style app to a
gigantic monolith. Your choice. The framework should not
get in the way.
Starting a new project with Symfony or evolving a
project is currently too complex for beginners and too
cumbersome for advanced Symfony developers. We can
do better."

This quote describes the ideal experience stated by Fabien
Potencier. Not every application needs a templating system
or database. Because of that, 70% of the classes included in
Symfony Standard edition were mostly never used.
Symfony 4 brings us a fantastic developers experience, and
it allows us to start small, to start as a micro framework. It
begins with almost zero dependencies, and the only things
included are Symfony Flex and basic framework dependen-
cies. In Symfony 4, we’re composing our application, and we
are defining our stack by ourselves. We are more in control of
our code base and framework. So my first Symfony 4 project
was a simple console application: a website scraper. After a
while, I added Doctrine and databases, then, later on, I added
the Symfony Messenger component and many other things.

Figure 1
Free download pdf