Today I want to write some words about new Symfony 4.0.
It’s nothing new, all information are available on Symfony project page. We are waiting for new but we already knew what will be implemented. So this is kind of summary information about it.
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.
Where we use Symfony?
REST API, web service, huge application with many satellites, or other micro style applications ran directly on console? 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 that’s not the only way to use Symfony.
New idea is to start with a small application framework and turn on any elements we want to use. The new version is based on micro-kernel and contains 70% less code and files than Symfony 3 apps.
Symfony Flex
Composition over Inheritance. If you think about it, distributions use inheritance. Most distributions are forks of the Symfony Standard Edition with additional bundles. What about using composition instead?
Symfony Flex is a modern replacement for the Symfony Installer, and not the name of the next Symfony version. This is a tool that replaces and improves the Symfony Installer and the Symfony Standard Edition.
Installing a Bundle / Removing a Bundle – today.
It starts very simply but you always must go to readme file and check what to do with, it’s probably, something like these:
- Register the bundle in the
AppKernel
class; - Register some routes
- Configure the bundle as you see fit
What’s about removing a Bundle? This is harder than instaling
Let’s us check, what’s next.
Creating a Recipe for a Bundle
Another way to contribute is to add a Flex recipe for a bundle (or library). Of course, not all bundles need a recipe: if the bundle has no configuration and installing it is as simple as enabling the bundle in the kernel, then skip it! Flex will auto-generate a recipe.
For details on creating a recipe, see github.com/symfony/recipes.
Making a Bundle Compatible with Symfony 4
If you want to make a bundle compatible with Symfony 4, here are the basic steps:
- Update the
composer.json
file: anysymfony/*
libraries need to have|4.0
added to it. For example, you would change from"symfony/form": "~3.0"
to"symfony/form": "~3.0|^4.0"
.
"require": { "symfony/form": "~2.7|~3.0|~4.0", "symfony/asset": "~2.7|~3.0|~4.0", "symfony/dependency-injection": "~2.7|~3.0|~4.0", "symfony/routing": "~2.7|~3.0|~4.0", "symfony/security-bundle": "~2.7|~3.0|~4.0", "symfony/yaml": "~2.7|~3.0|~4.0", "symfony/form": "~2.7|~3.0|~4.0", "symfony/validator": "~2.7|~3.0|~4.0", "symfony/twig-bundle": "~2.7|~3.0|~4.0", "symfony/twig-bridge": "^2.7|~3.0|~4.0", "twig/twig": "~1.28|~2.0", "phpoption/phpoption": "~1.1", "doctrine/annotations": "~1.0" },
- Update the bundle’s
.travis.yml
file so that it is tested against Symfony 4.
More information on A new way to deploy applications
Symfony Applications go minimal
Now, imagine an application where symfony/symfony
is not a dependency. An application can start with just symfony/framework-bundle
. Automatically enabling form support is now trivial: enable it when symfony/form
is installed, disable it otherwise. Simple, no magic, no configuration, great developer experience. We love Symfony 4.
Bundle-less applications is just one of the best practices changes for Symfony
So Symfony 4 will recommend and generate bundle-less applications. No more bundle for your code, just use App\
as a namespace for any class under src/
.
Backward Compatibility Promise
This is probabbly the hardest thing to do, but as we read in Backward Compatibility Promise – upgrading ours application will be smooth experience.
This promise was introduced with Symfony 2.3 and does not apply to previous versions of Symfony.
We are still waiting.
I hope you found this information useful