You work with Symfony, but the concept of dependency injection is a little blurry for you? Find out how to take advantage of the component reading this article.
Symfony 4 has been released more than 6 months ago (30 november 2017). The main change is the way of creating applications and how to append features during the project lifetime.
⚠️ Keep in mind that Symfony 4 now requires PHP 7.1.3 at least!
Flex is the new tool used by Symfony for projects management. It's a composer plugin aiming to help the developer creating a Symfony application.
recipe is a
manifest.json file. It contains some actions to take during the installation process.
It allows you to create a folder, copy config files, add some environment variables (.env) etc...
Full action list in the documentation.
recipes are stored in two repositories:
- main recipes repository high quality
recipes. Flex default repository.
- contrib recipes repository community
recipes, Flex always asks your permission before installing it.
ℹ️ You can go to the new website symfony.sh to find
Ok, we gonna to show how create Symfony 4 project with Flex.
$ composer create-project symfony/website-skeleton my-project
recipeto create lightweight project. It only requires:
Flex will create the following folder trees.
assets static ressources (image, js, css, ...) bin runnable (console, phpunit, ...) config application config files public public files (front controller index.php) src application source code templates templating files (twig, html, ...) tests tests files translations translation files var some temporary files (cache, logs, upload, ...) vendor third party library
In order to have your first page:
- create the template file
- create controller file
Caution, the controller name is not suffixed by
Where is the bundle?
You don't have to create the bundle in src (AppBundle).
You can now register your bundle in the
We had several choices before Symfony 4 :
- Use the symfony distribution (standard, cmf-standard, rest ...) or microkernel.
Ready to use (ORM, swiftmailer, twig, ...). It can bring useless features (forced to disable/delete).
- Use the Symfony component as third party or use Silex
Lightweight solution. Need a strong knowledge in order to initialise all the components with configuration and cache.
Symfony 4 was reworked to ease the initialisation process and not to bring unwanted components. It helps to manage features along the project lifetime.
There is the top 3 Symfony 4.0 changes :
- New folder structure.
- ClassLoader replaced by composer autoload.
PS : I advise you to visit again Symfony component list,
because now you need to use
recipe or compose your need with a third party library.