Symfony 4 & Symfony Flex - Core ideas, features and improvements

Symfony 4 & Symfony Flex - Core ideas, features and improvements

Since its release back in 2005, Symfony has been continuously evolving and improving. With every new version, the framework has pushed forward, helping us writing better code faster.
In this talk we will see the new features and improvements that Symfony 4 is going to introduce next November. We will learn the core ideas from this new version, understanding not only how to use it, but also what are the key assumptions and motivations behind.
Moreover, we will have a close look at the so-called “Symfony 4 secret weapon”: Symfony Flex. This Composer plugin has been created with the idea of cutting configuration times to the minimum. We will understand how it works and learn how to use it properly to boost our productivity.

281604c1a5357a164f2a9cd6e403b4e3?s=128

Victoria Quirante

October 24, 2017
Tweet

Transcript

  1. Symfony 4 & Symfony Flex Core ideas, features and improvements

    Victoria Quirante
  2. I work at Limenius We build tailor-made projects with Symfony

    and React We have been working with Symfony since 2008 SF4 means a significant evolution Victoria Quirante @vicqr victoria@limenius.com
  3. SYMFONY 4 MOTIVATION What are the driving forces behind this

    new version https://www.flickr.com/photos/gsfc/14411386334
  4. SYMFONY 4 MOTIVATION Or why the hell do we have

    to change things again https://www.flickr.com/photos/mindaugasdanys/3766009204
  5. «As a developer, I want to start small, without too

    many dependencies. But I also want to be able to grow my application as I see fit. From a micro-framework style app to a gigantic monolith. Your choice. The framework should not get in the way.» Fabien Potencier «Symfony Flex is all about making it simple and easy to create any Symfony applications, from the most simple micro-style project to the more complex ones with dozens of dependencies. It automates adding and removing bundles. It takes care of giving you sensible defaults. It helps discovering good bundles.» Fabien Potencier
  6. Victoria Quirante @vicqr victoria@limenius.com SF 4 seems like the result

    of a SWOT analysis Victoria Quirante @vicqr victoria@limenius.com S W O T Flexible Powerful Config time high Learning curve SF 2 Web development environment
  7. Victoria Quirante @vicqr victoria@limenius.com Recent evolution of the web development

    environment Our favourite framework Some jQuery { { Back-end Front-end
  8. Victoria Quirante @vicqr victoria@limenius.com Recent evolution of the web development

    environment Our favourite framework Some jQuery { { Back-end Front-end Backbone.js Ember.js Angular.js Gulp Grunt Vue.js Webpack React.js chats notifications immediate validations page reloads
  9. Victoria Quirante @vicqr victoria@limenius.com Our favourite framework Some jQuery Recent

    evolution of the web development environment { { Back-end Front-end Our favourite front-end framework Our favourite back-end framework API Backbone.js Ember.js Angular.js Gulp Grunt Vue.js Webpack React.js chats notifications immediate validations page reloads
  10. Victoria Quirante @vicqr victoria@limenius.com Our favourite framework Some jQuery Recent

    evolution of the web development environment { { Back-end Front-end Our favourite front-end framework Our favourite back-end framework API Our favourite front-end framework API
  11. Victoria Quirante @vicqr victoria@limenius.com Our favourite framework Some jQuery Recent

    evolution of the web development environment { { Back-end Front-end Our favourite front-end framework Our favourite back-end framework API Our favourite front-end framework API API API API API
  12. Then, what is expected from a back-end framework nowadays?

  13. Victoria Quirante @vicqr victoria@limenius.com - To be a great solution

    for APIs - To make easy to build some functionalities (admin panels, etc.) - To be efficient creating small apps and microservices - ... What is expected nowadays from a back-end framework? To take good care of the back-end
  14. Victoria Quirante @vicqr victoria@limenius.com SF 4 seems like the result

    of a SWOT analysis S W O T Flexible Powerful Config times high Learning curve APIs everywhere Microservices needed Backends needed Drupal/Laravel Frontend revolution SF 2 Web development environment
  15. In front of this, what things should we change?

  16. SYMFONY 4 PHILOSOPHY https://www.flickr.com/photos/68532869@N08/16357411958

  17. Victoria Quirante @vicqr victoria@limenius.com Symfony roadmap

  18. Victoria Quirante @vicqr victoria@limenius.com Symfony 2 was two things 1.

    A full stack framework 1. A full stack framework 2. A set of independent components
  19. Victoria Quirante @vicqr victoria@limenius.com Symfony 2 was two things 1.

    A full stack framework But “developing in Symfony 2” generally meant using the full framework
  20. Victoria Quirante @vicqr victoria@limenius.com Example: If you wanted to build

    a console app before You could start with the full FW and get many things you don’t need Or go for the components approach… and fight quite a bit
  21. Victoria Quirante @vicqr victoria@limenius.com Symfony 2 VS Symfony 4 graphically

    SF 2 web app SF 2 API SF 2 microservice
  22. Victoria Quirante @vicqr victoria@limenius.com Symfony 2 VS Symfony 4 graphically

    SF 2 web app SF 2 API SF 2 microservice SF 4 web app SF 4 API SF 4 microservice
  23. Victoria Quirante @vicqr victoria@limenius.com Working with SF 4 SF 4

    web app SF 4 API SF 4 microservice SF 4
  24. SF4 is not a new FW, it is a new

    mindset behind the same FW
  25. Victoria Quirante @vicqr victoria@limenius.com Symfony 4 - Compose your application

    Make easy to create projects with lots or few dependencies For that, they wanted automate bundle installation/configuration
  26. It is key that we can make our project grow

    or shrink very easily
  27. Victoria Quirante @vicqr victoria@limenius.com Working with SF 4 SF 4

    web app SF 4 API SF 4 microservice SF 4 We need something to smooth out this transformations
  28. SYMFONY FLEX What exactly is it

  29. SF FLEX is not a version of SF, it is

    a tool to implement SF4’s philosophy
  30. Victoria Quirante @vicqr victoria@limenius.com Symfony Flex - Automation to the

    max It is a composer plugin that comes with Symfony 4 Moving towards zero configuration time It also “promotes” a curated list of official recipes
  31. Victoria Quirante @vicqr victoria@limenius.com Internals Modifies the behaviour of the

    require and update commands Allows Symfony to perform tasks before or after the Composer commands
  32. Victoria Quirante @vicqr victoria@limenius.com How it works composer require mailer

    It installs and enables SwiftmailerBundle
  33. Victoria Quirante @vicqr victoria@limenius.com How it works composer req mailer

    It installs and enables SwiftmailerBundle
  34. Victoria Quirante @vicqr victoria@limenius.com How it works Your application with

    Symfony Flex composer require mailer
  35. Victoria Quirante @vicqr victoria@limenius.com How it works Your application with

    Symfony Flex composer require mailer Symfony Flex server Is there information about this package?
  36. Victoria Quirante @vicqr victoria@limenius.com How it works Your application with

    Symfony Flex composer require mailer Is there information about this package? Going for regular installation via Composer Nope Symfony Flex server
  37. Victoria Quirante @vicqr victoria@limenius.com How it works Your application with

    Symfony Flex composer require mailer Is there information about this package? Symfony Flex server
  38. Victoria Quirante @vicqr victoria@limenius.com How it works Your application with

    Symfony Flex composer require mailer Is there information about this package? Yes, sending recipe Cool, following recipe instructions! Symfony Flex server
  39. Victoria Quirante @vicqr victoria@limenius.com How it works Your application with

    Symfony Flex composer require mailer Is there information about this package? Yes, sending recipe Cool, following recipe instructions! Deciding which packages to install Symfony Flex server
  40. Victoria Quirante @vicqr victoria@limenius.com How it works Your application with

    Symfony Flex composer require mailer Is there information about this package? Asking Composer to install them Yes, sending recipe Cool, following recipe instructions! Deciding which packages to install Symfony Flex server
  41. Victoria Quirante @vicqr victoria@limenius.com How it works Your application with

    Symfony Flex composer require mailer Is there information about this package? Asking Composer to install them Yes, sending recipe Cool, following recipe instructions! Deciding which packages to install Running any tasks required Symfony Flex server
  42. Victoria Quirante @vicqr victoria@limenius.com Recipes Defined in a manifest.json file

    May contain other files or directories It ‘explains’ Symfony Flex what things need to be done
  43. Victoria Quirante @vicqr victoria@limenius.com Recipes { "bundles": { "Symfony\\Bundle\\SwiftmailerBundle\\SwiftmailerBundle": ["all"]

    }, "copy-from-recipe": { "config/": "%CONFIG_DIR%/" }, "env": { "MAILER_URL": "smtp://localhost:25?encryption=&auth_mode=" }, "aliases": ["mailer", "mail"] }
  44. Victoria Quirante @vicqr victoria@limenius.com Recipes { "bundles": { "Symfony\\Bundle\\SwiftmailerBundle\\SwiftmailerBundle": ["all"]

    }, "copy-from-recipe": { "config/": "%CONFIG_DIR%/" }, "env": { "MAILER_URL": "smtp://localhost:25?encryption=&auth_mode=" }, "aliases": ["mailer", "mail"] } Environments that this bundle has to enable automatically
  45. Victoria Quirante @vicqr victoria@limenius.com Recipes { "bundles": { "Symfony\\Bundle\\SwiftmailerBundle\\SwiftmailerBundle": ["all"]

    }, "copy-from-recipe": { "config/": "%CONFIG_DIR%/" }, "env": { "MAILER_URL": "smtp://localhost:25?encryption=&auth_mode=" }, "aliases": ["mailer", "mail"] } Files and directories that will be copied into your application
  46. Victoria Quirante @vicqr victoria@limenius.com Recipes { "bundles": { "Symfony\\Bundle\\SwiftmailerBundle\\SwiftmailerBundle": ["all"]

    }, "copy-from-recipe": { "config/": "%CONFIG_DIR%/" }, "env": { "MAILER_URL": "smtp://localhost:25?encryption=&auth_mode=" }, "aliases": ["mailer", "mail"] } New environment variables that will be added to your application
  47. Victoria Quirante @vicqr victoria@limenius.com Recipes List of alternative shorter names

    for the package { "bundles": { "Symfony\\Bundle\\SwiftmailerBundle\\SwiftmailerBundle": ["all"] }, "copy-from-recipe": { "config/": "%CONFIG_DIR%/" }, "env": { "MAILER_URL": "smtp://localhost:25?encryption=&auth_mode=" }, "aliases": ["mailer", "mail"] }
  48. Victoria Quirante @vicqr victoria@limenius.com Official and unofficial recipes Two repositories:

    core and contrib official repository (very) opinionated approval from SF core team Symfony Flex looks here aliases core community repository not opinionated - Symfony Flex may look here - contrib
  49. Victoria Quirante @vicqr victoria@limenius.com Creating a new Symfony app with

    Symfony Flex composer create-project symfony/skeleton my-project
  50. Victoria Quirante @vicqr victoria@limenius.com Creating a new Symfony app with

    Symfony Flex composer create-project symfony/skeleton my-project "require": { "php": "^7.0.8", "symfony/flex": "^1.0", "symfony/console": "^4.0", "symfony/framework-bundle": "^4.0", "symfony/lts": "^4@dev", "symfony/yaml": "^4.0" }, Downloads the Symfony skeleton (just one composer.json)
  51. Victoria Quirante @vicqr victoria@limenius.com Creating a new Symfony app with

    Symfony Flex composer create-project symfony/skeleton my-project "require": { "php": "^7.0.8", "symfony/flex": "^1.0", "symfony/console": "^4.0", "symfony/framework-bundle": "^4.0", "symfony/lts": "^4@dev", "symfony/yaml": "^4.0" }, Downloads the Symfony skeleton (just one composer.json) composer install symfony/flex is the first package installed And runs
  52. Victoria Quirante @vicqr victoria@limenius.com May I avoid using Symfony Flex?

    Yes, you can install/configure things as you used to But Symfony Flex is the default way of doing things in Symfony 4
  53. Victoria Quirante @vicqr victoria@limenius.com May I use Symfony Flex with

    an old project? Yes, but installing Symfony Flex is not enough You need to update the directory structure https://symfony.com/doc/master/setup/flex.html#upgrading-existing-applications-to-flex
  54. WHAT HAS CHANGED Things we have to ‘relearn’ https://www.flickr.com/photos/vialbost/37167061631

  55. Do you remember those never-ending discussions about one VS multiple

    bundle apps?
  56. Guess what was the right answer…

  57. «[...] We worked hard during the last few months to

    make sure that Symfony 4 can embrace bundle-less applications. So Symfony 4 will recommend and generate bundle-less applications.» Fabien Potencier
  58. None
  59. «[...] We worked hard during the last few months to

    make sure that Symfony 4 can embrace bundle-less applications. So Symfony 4 will recommend and generate bundle-less applications.» Fabien Potencier «No more bundle for your code, just use App\ as a namespace for any class under src/. It reduces the perceived complexity. It also makes your code feel more decoupled from Symfony.» Fabien Potencier
  60. Victoria Quirante @vicqr victoria@limenius.com Bundle-less applications Change in best practices

    No more one-bundle-application Now zero-bundle-application is recommended In practice, not difficult to get used to this
  61. Victoria Quirante @vicqr victoria@limenius.com Directory structure my-project/ ├── config/ │

    ├── bundles.php │ ├── packages/ │ ├── routes.yaml │ └── services.yaml ├── public/ │ └── index.php ├── src/ │ ├── ... │ └── Kernel.php ├── templates/ └── vendor/ It may be a bit tricky at the beginning, but it is actually simpler
  62. Victoria Quirante @vicqr victoria@limenius.com config/bundles.php File where installed bundles get

    referenced Symfony Flex is going to write here
  63. Victoria Quirante @vicqr victoria@limenius.com config.yml -> packages/package-name.yaml Forget about the

    single long config file Now our configuration is splitted in different files One file per package/bundle and environment
  64. Victoria Quirante @vicqr victoria@limenius.com parameters.yml -> Environment variables Now we

    have .env More standard way of managing settings # .env APP_ENV=dev APP_DEBUG=1 APP_SECRET=d5b7eb4ea25adca8c17bsdsc126831c DATABASE_URL="mysql://travolta:travolta@127.0.0.1:3306/travolta"#
  65. Victoria Quirante @vicqr victoria@limenius.com Unified web front controller No more

    app.php and app_dev.php Just one (public/index.php) Trickier to switch between them But it is considered a better practice # public/index.php $kernel = new Kernel($_SERVER['APP_ENV'] ?? 'dev', $_SERVER['APP_DEBUG'] ?? false);
  66. WHAT IS NEW What new shiny things do we get?

    https://www.flickr.com/photos/blondinrikard/14419731227
  67. Of course, Symfony Flex, but what else?

  68. Victoria Quirante @vicqr victoria@limenius.com Some key things already introduced in

    SF 3 - Automated configuration: - Autowiring - _defaults, _instanceof - Autoconfiguration - Further standardization: - PSR-4 based service discovery - PSR-11 containers - ... https://symfony.com/blog
  69. Victoria Quirante @vicqr victoria@limenius.com Many not too flashy but yet

    powerful additions - Improvements in: - Guard authentication - Forms - Injection of tag services - Console exceptions - Overriding templates - ... - Integration with Bootstrap 4 form theme - ... https://symfony.com/blog
  70. AND, finally, just when we had lost almost all hope...

  71. A great solution for the assets

  72. Victoria Quirante @vicqr victoria@limenius.com Webpack Encore It simplifies the integration

    of our Symfony project with Webpack Webpack is a great tool to process the assets Configuring Webpack is not easy But Webpack Encore solves that
  73. DEMO TIME Let’s create a project with Symfony Flex https://www.flickr.com/photos/callmewhatever/30708918322

  74. Victoria Quirante @vicqr victoria@limenius.com Let’s create a project with Symfony

    Flex We are going to create a project with API Platform and EasyAdmin
  75. Victoria Quirante @vicqr victoria@limenius.com API Platform

  76. Victoria Quirante @vicqr victoria@limenius.com EasyAdmin

  77. Victoria Quirante @vicqr victoria@limenius.com composer create-project symfony/skeleton apiadmin-project cd apiadmin-project

    composer req api composer req admin composer req webserver - Create Entity - Config database bin/console doctrine:schema:update - Tell API Platform and EasyAdmin about our Entity bin/console server:run Demo time Let’s do it
  78. EVALUATING How good are these changes?

  79. Victoria Quirante @vicqr victoria@limenius.com Fair questions about SF 4 &

    SF Flex 1. Is it more difficult now to develop a ‘standard web project’? 2. Trying to make config extra simple… is it getting more obscure? 3. Are ‘official packages’ too promoted? Still early to know
  80. Victoria Quirante @vicqr victoria@limenius.com The good It makes sense not

    to carry dependencies that you are not using The things we need to adapt to are not difficult Moving further towards standardization
  81. Victoria Quirante @vicqr victoria@limenius.com The real good Trying to adapt

    to the upcoming challenges Webpack Encore Working together with the front-end, not fighting against it
  82. BET 1: Let’s embrace the position of the back-end framework

    in the landscape, and try to adapt to our time BET 2: Let’s keep our Symfony as powerful and flexible, while trying to compete against more high-level-oriented solutions
  83. Victoria Quirante @vicqr victoria@limenius.com Fears and hopes Great FW to

    create fully tailored-made apps SF It tries to gain ground on more high-level-oriented solutions It remains as good as always (or better) for that While making easier to build some “standard” stuff Optimistic outcome Pessimistic outcome It loses focus It loses love from traditional SF developers
  84. FINAL THOUGHTS What to remember https://www.flickr.com/photos/dewalick/15842170328

  85. Victoria Quirante @vicqr victoria@limenius.com To summarize S W O T

    Flexible Powerful Config times high Learning curve APIs everywhere Microservices needed Backends needed Drupal/Laravel Frontend revolution SF 2 Web development environment
  86. Victoria Quirante @vicqr victoria@limenius.com To summarize S W O T

    Flexible Powerful Config times high Learning curve APIs everywhere Microservices needed Backends needed Drupal/Laravel Frontend revolution SF 2 Web development environment
  87. Victoria Quirante @vicqr victoria@limenius.com To summarize S W O T

    Flexible Powerful Config times high Learning curve APIs everywhere Microservices needed Backends needed Drupal/Laravel Frontend revolution SF 2 Web development environment
  88. Victoria Quirante @vicqr victoria@limenius.com To summarize S W O T

    Flexible Powerful Config times high Learning curve APIs everywhere Microservices needed Backends needed Drupal/Laravel Frontend revolution SF 2 Web development environment
  89. Victoria Quirante @vicqr victoria@limenius.com To summarize Clear answer to the

    current times Imho, the direction taken looks promising There may be some risks, but it depends on how will it evolve The community has, of course, a lot to say in this
  90. Thanks! Victoria Quirante @vicqr victoria@limenius.com