Hands-on Symfony Flex

Composition over inheritance

CBTW
L’Actualité Tech — Blog CBTW
4 min readMay 23, 2017

--

Symfony Flex
Symfony Flex

What is Symfony Flex

Sensiolabs recently made public Symfony Flex which reveals the future of the Symfony framework. In a few words, it’s a Composer plugin that hooks on your composer commands. Whenever you require a dependency that has an associated recipe on the Flex server (administered by Sensiolabs at flex.symfony.com), Symfony Flex will run some tasks to nicely integrate this dependency to your current Symfony project. Tasks like registering the bundle, the routes, the env vars, the make tasks and the git ignored files are completely automated.

The end of the Symfony standard distribution

Distributions are a wrong abstraction. We rarely need all the dependencies and files that come with them. So, what we do most of the time, is to remove everything we don’t need. What we should do instead is to compose our application’s infrastructure with the exact dependencies we need over time. This is where Flex comes into play. It’s oriented around micro-first ideal, but you can still build giant monoliths if you want to :). Symfony Flex is going to be the default way to manage Symfony 4 applications.

New best practices for Symfony 4 & Symfony Flex

  • First of all, Symfony 4 will require PHP 7.1 and will drop support for HHVM.
  • The default structure of the src/ directory will be bundle-less. A step forward for having framework agnostic application code. No more AppBundle.
  • No more parameters.yml, use env variables instead, .env file with the symfony/dotenv component in dev and system env vars in prod.
  • One single front controller for all environments called web/index.php. APP_ENV and APP_DEBUG env vars can be used for both the web front controller and the console in replacement of the — env and — no-debug flags.
  • Use of Makefile is also a great choice as `make` is a standard tool pre-installed almost everywhere and working flawlessly as a task runner. `make serve` and you just set up a web server listening on localhost:8000. `make cache-clear` also works for clearing the cache.
  • New directory structure. Tests move to a top-level tests/ directory, templates under templates/ and configuration to etc/.

The structure is still under debate though.

Compose your application with symfony/flex

You can see that symfony/flex runs automatically some tasks every time it installs a dependency. Once it’s done, it offers us a ready to use project structure.

You can also bootstrap a symfony skeleton as a composer project by running composer create-project symfony/skeleton:3.3.x-dev flex-demo

Here is a demo video showing symfony flex in action

To conclude

Symfony Flex is a great surprise and a step forward for the whole Symfony community. It forces to start small and it easily adapts to different kind of projects. It combines the strength of both Silex (micro) and Symfony (bundles). Some changes such as the new directory structure and bundle-less source directory are amazing additions.

Even if there can only be one “admin” or “api” official flex alias, you’re still free to contribute your own recipes on this separate community repository (https://github.com/symfony/recipes-contrib). Symfony flex, as well as Symfony 4 will be stable by the end of the year (november 2017).

Nous publions régulièrement des articles sur des sujets de développement produit web et mobile, data science, cybersécurité, cloud, hyperautomatisation et organisation du travail. N’hésitez donc pas à suivre notre compte Medium pour être notifié de nos prochaines publications et réaliser votre veille professionnelle.

Vous pouvez également suivre nos publications et notre actualité professionnelle, via nos différents réseaux sociaux : LinkedIn, Twitter, Instagram, Youtube et Twitch.

Pour en savoir sur notre entreprise et nos expertises, vous pouvez aussi consulter notre site Positive Thinking Company et nos offres d’emploi.

L’auteur

Lucas
Software Craftsman, Web addict et passionné d’architecture logicielle

--

--

CBTW
L’Actualité Tech — Blog CBTW

Nos experts partagent leur vision et leur veille en développement web et mobile, data et analytics, sécurité, cloud, hyperautomation et digital workplace.