Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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.

Victoria Quirante

October 24, 2017
Tweet

More Decks by Victoria Quirante

Other Decks in Programming

Transcript

  1. 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 [email protected]
  2. SYMFONY 4 MOTIVATION What are the driving forces behind this

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

    to change things again https://www.flickr.com/photos/mindaugasdanys/3766009204
  4. «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
  5. Victoria Quirante @vicqr [email protected] SF 4 seems like the result

    of a SWOT analysis Victoria Quirante @vicqr [email protected] S W O T Flexible Powerful Config time high Learning curve SF 2 Web development environment
  6. Victoria Quirante @vicqr [email protected] Recent evolution of the web development

    environment Our favourite framework Some jQuery { { Back-end Front-end
  7. Victoria Quirante @vicqr [email protected] 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
  8. Victoria Quirante @vicqr [email protected] 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
  9. Victoria Quirante @vicqr [email protected] 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
  10. Victoria Quirante @vicqr [email protected] 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
  11. Victoria Quirante @vicqr [email protected] - 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
  12. Victoria Quirante @vicqr [email protected] 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
  13. Victoria Quirante @vicqr [email protected] Symfony 2 was two things 1.

    A full stack framework 1. A full stack framework 2. A set of independent components
  14. Victoria Quirante @vicqr [email protected] Symfony 2 was two things 1.

    A full stack framework But “developing in Symfony 2” generally meant using the full framework
  15. Victoria Quirante @vicqr [email protected] 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
  16. Victoria Quirante @vicqr [email protected] 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
  17. SF4 is not a new FW, it is a new

    mindset behind the same FW
  18. Victoria Quirante @vicqr [email protected] Symfony 4 - Compose your application

    Make easy to create projects with lots or few dependencies For that, they wanted automate bundle installation/configuration
  19. Victoria Quirante @vicqr [email protected] Working with SF 4 SF 4

    web app SF 4 API SF 4 microservice SF 4 We need something to smooth out this transformations
  20. SF FLEX is not a version of SF, it is

    a tool to implement SF4’s philosophy
  21. Victoria Quirante @vicqr [email protected] 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
  22. Victoria Quirante @vicqr [email protected] Internals Modifies the behaviour of the

    require and update commands Allows Symfony to perform tasks before or after the Composer commands
  23. Victoria Quirante @vicqr [email protected] How it works Your application with

    Symfony Flex composer require mailer Symfony Flex server Is there information about this package?
  24. Victoria Quirante @vicqr [email protected] 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
  25. Victoria Quirante @vicqr [email protected] How it works Your application with

    Symfony Flex composer require mailer Is there information about this package? Symfony Flex server
  26. Victoria Quirante @vicqr [email protected] 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
  27. Victoria Quirante @vicqr [email protected] 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
  28. Victoria Quirante @vicqr [email protected] 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
  29. Victoria Quirante @vicqr [email protected] 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
  30. Victoria Quirante @vicqr [email protected] Recipes Defined in a manifest.json file

    May contain other files or directories It ‘explains’ Symfony Flex what things need to be done
  31. Victoria Quirante @vicqr [email protected] 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"] }
  32. Victoria Quirante @vicqr [email protected] 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
  33. Victoria Quirante @vicqr [email protected] 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
  34. Victoria Quirante @vicqr [email protected] 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
  35. Victoria Quirante @vicqr [email protected] 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"] }
  36. Victoria Quirante @vicqr [email protected] 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
  37. Victoria Quirante @vicqr [email protected] Creating a new Symfony app with

    Symfony Flex composer create-project symfony/skeleton my-project
  38. Victoria Quirante @vicqr [email protected] 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)
  39. Victoria Quirante @vicqr [email protected] 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
  40. Victoria Quirante @vicqr [email protected] 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
  41. Victoria Quirante @vicqr [email protected] 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
  42. «[...] 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
  43. «[...] 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
  44. Victoria Quirante @vicqr [email protected] 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
  45. Victoria Quirante @vicqr [email protected] 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
  46. Victoria Quirante @vicqr [email protected] 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
  47. Victoria Quirante @vicqr [email protected] 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:[email protected]:3306/travolta"#
  48. Victoria Quirante @vicqr [email protected] 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);
  49. WHAT IS NEW What new shiny things do we get?

    https://www.flickr.com/photos/blondinrikard/14419731227
  50. Victoria Quirante @vicqr [email protected] 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
  51. Victoria Quirante @vicqr [email protected] 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
  52. Victoria Quirante @vicqr [email protected] 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
  53. Victoria Quirante @vicqr [email protected] Let’s create a project with Symfony

    Flex We are going to create a project with API Platform and EasyAdmin
  54. Victoria Quirante @vicqr [email protected] 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
  55. Victoria Quirante @vicqr [email protected] 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
  56. Victoria Quirante @vicqr [email protected] 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
  57. Victoria Quirante @vicqr [email protected] The real good Trying to adapt

    to the upcoming challenges Webpack Encore Working together with the front-end, not fighting against it
  58. 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
  59. Victoria Quirante @vicqr [email protected] 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
  60. Victoria Quirante @vicqr [email protected] 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
  61. Victoria Quirante @vicqr [email protected] 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
  62. Victoria Quirante @vicqr [email protected] 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
  63. Victoria Quirante @vicqr [email protected] 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
  64. Victoria Quirante @vicqr [email protected] 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