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. Symfony 4 & Symfony Flex
    Core ideas, features and improvements
    Victoria Quirante

    View full-size slide

  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
    [email protected]

    View full-size slide

  3. SYMFONY 4 MOTIVATION
    What are the driving
    forces behind this new
    version
    https://www.flickr.com/photos/gsfc/14411386334

    View full-size slide

  4. SYMFONY 4 MOTIVATION
    Or why the hell
    do we have to change
    things again
    https://www.flickr.com/photos/mindaugasdanys/3766009204

    View full-size slide

  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

    View full-size slide

  6. 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

    View full-size slide

  7. Victoria Quirante
    @vicqr
    [email protected]
    Recent evolution of the web development environment
    Our favourite
    framework
    Some jQuery
    {
    {
    Back-end
    Front-end

    View full-size slide

  8. 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

    View full-size slide

  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
    Backbone.js Ember.js Angular.js
    Gulp Grunt
    Vue.js Webpack React.js
    chats notifications immediate
    validations
    page reloads

    View full-size slide

  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

    View full-size slide

  11. 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

    View full-size slide

  12. Then, what is expected
    from a back-end
    framework nowadays?

    View full-size slide

  13. 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

    View full-size slide

  14. 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

    View full-size slide

  15. In front of this, what
    things should we
    change?

    View full-size slide

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

    View full-size slide

  17. Victoria Quirante
    @vicqr
    [email protected]
    Symfony roadmap

    View full-size slide

  18. 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

    View full-size slide

  19. 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

    View full-size slide

  20. 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

    View full-size slide

  21. Victoria Quirante
    @vicqr
    [email protected]
    Symfony 2 VS Symfony 4 graphically
    SF 2
    web app
    SF 2
    API
    SF 2
    microservice

    View full-size slide

  22. 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

    View full-size slide

  23. Victoria Quirante
    @vicqr
    [email protected]
    Working with SF 4
    SF 4
    web app
    SF 4
    API
    SF 4
    microservice
    SF 4

    View full-size slide

  24. SF4 is not a new FW, it is
    a new mindset behind
    the same FW

    View full-size slide

  25. 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

    View full-size slide

  26. It is key that we can
    make our project grow
    or shrink very easily

    View full-size slide

  27. 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

    View full-size slide

  28. SYMFONY FLEX
    What exactly is it

    View full-size slide

  29. SF FLEX is not a version of
    SF, it is a tool to implement
    SF4’s philosophy

    View full-size slide

  30. 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

    View full-size slide

  31. 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

    View full-size slide

  32. Victoria Quirante
    @vicqr
    [email protected]
    How it works
    composer require mailer
    It installs and enables
    SwiftmailerBundle

    View full-size slide

  33. Victoria Quirante
    @vicqr
    [email protected]
    How it works
    composer req mailer
    It installs and enables
    SwiftmailerBundle

    View full-size slide

  34. Victoria Quirante
    @vicqr
    [email protected]
    How it works
    Your application with
    Symfony Flex
    composer require mailer

    View full-size slide

  35. 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?

    View full-size slide

  36. 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

    View full-size slide

  37. 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

    View full-size slide

  38. 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

    View full-size slide

  39. 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

    View full-size slide

  40. 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

    View full-size slide

  41. 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

    View full-size slide

  42. 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

    View full-size slide

  43. 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"]
    }

    View full-size slide

  44. 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

    View full-size slide

  45. 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

    View full-size slide

  46. 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

    View full-size slide

  47. 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"]
    }

    View full-size slide

  48. 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

    View full-size slide

  49. Victoria Quirante
    @vicqr
    [email protected]
    Creating a new Symfony app with Symfony Flex
    composer create-project symfony/skeleton my-project

    View full-size slide

  50. 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)

    View full-size slide

  51. 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

    View full-size slide

  52. 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

    View full-size slide

  53. 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

    View full-size slide

  54. WHAT HAS CHANGED
    Things we have to ‘relearn’
    https://www.flickr.com/photos/vialbost/37167061631

    View full-size slide

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

    View full-size slide

  56. Guess what was the right
    answer…

    View full-size slide

  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

    View full-size slide

  58. «[...] 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

    View full-size slide

  59. 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

    View full-size slide

  60. 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

    View full-size slide

  61. Victoria Quirante
    @vicqr
    [email protected]
    config/bundles.php
    File where installed bundles get referenced
    Symfony Flex is going to write here

    View full-size slide

  62. 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

    View full-size slide

  63. 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"#

    View full-size slide

  64. 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);

    View full-size slide

  65. WHAT IS NEW
    What new shiny things
    do we get?
    https://www.flickr.com/photos/blondinrikard/14419731227

    View full-size slide

  66. Of course, Symfony Flex,
    but what else?

    View full-size slide

  67. 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

    View full-size slide

  68. 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

    View full-size slide

  69. AND, finally, just when we
    had lost almost all hope...

    View full-size slide

  70. A great solution
    for the assets

    View full-size slide

  71. 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

    View full-size slide

  72. DEMO TIME
    Let’s create a project
    with Symfony Flex
    https://www.flickr.com/photos/callmewhatever/30708918322

    View full-size slide

  73. 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

    View full-size slide

  74. Victoria Quirante
    @vicqr
    [email protected]
    API Platform

    View full-size slide

  75. Victoria Quirante
    @vicqr
    [email protected]
    EasyAdmin

    View full-size slide

  76. 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

    View full-size slide

  77. EVALUATING
    How good are these changes?

    View full-size slide

  78. 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

    View full-size slide

  79. 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

    View full-size slide

  80. 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

    View full-size slide

  81. 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

    View full-size slide

  82. 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

    View full-size slide

  83. FINAL THOUGHTS
    What to remember
    https://www.flickr.com/photos/dewalick/15842170328

    View full-size slide

  84. 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

    View full-size slide

  85. 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

    View full-size slide

  86. 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

    View full-size slide

  87. 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

    View full-size slide

  88. 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

    View full-size slide

  89. Thanks!
    Victoria Quirante
    @vicqr
    [email protected]

    View full-size slide