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

Developing with Symfony 4

Victoria Quirante
June 07, 2018
160

Developing with Symfony 4

Is Symfony 4 the framework that you want to use for your next project? 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. But there are many different types of projects and developers out there, and it is always good to get some insight in a technology before jumping into it. In this talk we will analyze the strengths and weaknesses of the framework, checking them against other alternatives, and learning the type of projects and developers that can benefit from it to a larger extent. We will also review the most important changes introduced in the last version of Symfony, understanding the motivations behind them, evaluating the current state of the framework in the web development environment, and trying to foresee the future of this technology.

Victoria Quirante

June 07, 2018
Tweet

Transcript

  1. Developing with Symfony 4
    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
    Symfony 4 has been a significant
    evolution
    Victoria Quirante
    @vicqr
    [email protected]

    View full-size slide

  3. SYMFONY EVOLUTION
    A brief history of time
    https://www.flickr.com/photos/gsfc/14411386334

    View full-size slide

  4. Victoria Quirante
    @vicqr
    [email protected]
    Symfony evolution

    View full-size slide

  5. Victoria Quirante
    @vicqr
    [email protected]
    Symfony evolution
    SF 1 SF 2 SF 3 SF 4
    A different FW A new, better approach
    Monolithic

    View full-size slide

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

  7. Victoria Quirante
    @vicqr
    [email protected]
    Symfony Components

    View full-size slide

  8. Victoria Quirante
    @vicqr
    [email protected]
    Doctrine

    View full-size slide

  9. Victoria Quirante
    @vicqr
    [email protected]
    Propel

    View full-size slide

  10. Victoria Quirante
    @vicqr
    [email protected]
    Silex

    View full-size slide

  11. Victoria Quirante
    @vicqr
    [email protected]
    Drupal

    View full-size slide

  12. Victoria Quirante
    @vicqr
    [email protected]
    Laravel

    View full-size slide

  13. Victoria Quirante
    @vicqr
    [email protected]
    Symfony evolution
    SF 1 SF 2 SF 3 SF 4
    A different FW A new, better approach
    Symfony Components
    Dependency Injection

    View full-size slide

  14. Victoria Quirante
    @vicqr
    [email protected]
    Dependency Injection
    Some code
    Some
    dependency
    created right
    here
    Coupled services Services decoupled with DI
    Some
    code
    Some
    dependency
    The dependency gets
    injected

    View full-size slide

  15. Victoria Quirante
    @vicqr
    [email protected]
    Symfony evolution
    SF 1 SF 2 SF 3 SF 4
    A different FW A step in between
    A new, better approach
    Symfony Components
    Dependency Injection
    More modular
    More flexible
    More decoupled

    View full-size slide

  16. Victoria Quirante
    @vicqr
    [email protected]
    Symfony evolution
    SF 1 SF 2 SF 3 SF 4
    A different FW A step in between
    What has changed between
    these two and why?
    Many dependencies
    High configuration times
    Steep learning curve

    View full-size slide

  17. Victoria Quirante
    @vicqr
    [email protected]
    Symfony evolution
    SF 1 SF 2 SF 3 SF 4
    A different FW A step in between
    They have tried to keep/enhance
    the good and improve the bad
    Many dependencies
    High configuration times
    Steep learning curve

    View full-size slide

  18. Victoria Quirante
    @vicqr
    [email protected]
    Symfony evolution
    SF 1 SF 2 SF 3 SF 4
    A different FW A step in between
    Many dependencies
    High configuration times
    Steep learning curve
    And adapt to the challenges of the current
    web development environment

    View full-size slide

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

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

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

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

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

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

    View full-size slide

  25. Victoria Quirante
    @vicqr
    [email protected]
    What is expected from a back-end framework nowadays?
    - 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
    - ...
    To take good care of the back-end
    And, ideally, to play well with the front-end

    View full-size slide

  26. How does Symfony 4
    provide this?

    View full-size slide

  27. SYMFONY 4 PHILOSOPHY
    https://www.flickr.com/photos/68532869@N08/16357411958
    How are things now

    View full-size slide

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

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

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

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

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

  33. «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

    View full-size slide

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

    View full-size slide

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

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

    View full-size slide

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

  38. SYMFONY FLEX
    What exactly is it

    View full-size slide

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

    View full-size slide

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

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

    View full-size slide

  42. Victoria Quirante
    @vicqr
    [email protected]
    Internals
    Modifies the behaviour of the require, update and remove commands
    Allows Symfony to perform tasks before or after the Composer commands

    View full-size slide

  43. Victoria Quirante
    @vicqr
    [email protected]
    How does it work
    composer req mailer
    It installs and enables
    SwiftmailerBundle
    composer require mailer

    View full-size slide

  44. Victoria Quirante
    @vicqr
    [email protected]
    How does it work
    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

  45. Victoria Quirante
    @vicqr
    [email protected]
    How does it work
    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 required tasks
    Symfony Flex
    server

    View full-size slide

  46. Victoria Quirante
    @vicqr
    [email protected]
    Creating a new Symfony app with Symfony Flex
    composer create-project symfony/skeleton my-project
    "require": {
    "php": "^7.1.3",
    "ext-iconv": "*",
    "symfony/console": "^4.0",
    "symfony/flex": "^1.0",
    "symfony/framework-bundle": "^4.0",
    "symfony/lts": "^4@dev",
    "symfony/yaml": "^4.0"
    },
    Downloads the Symfony skeleton
    (just one composer.json)
    composer install
    And runs
    As soon as Symfony Flex is installed,
    it hooks into the process

    View full-size slide

  47. Any other big news in
    Symfony 4?

    View full-size slide

  48. A great solution for
    the assets

    View full-size slide

  49. 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
    Working together with the front-end, not fighting against it

    View full-size slide

  50. Victoria Quirante
    @vicqr
    [email protected]
    Keeping/enhancing the good and improving the bad
    SF 1 SF 2 SF 3 SF 4
    A different FW A step in between
    What has changed between
    these two?

    View full-size slide

  51. Victoria Quirante
    @vicqr
    [email protected]
    Solid
    Powerful
    Flexible
    Good for large long-term projects
    Keeping/enhancing the good and improving the bad
    Steep learning curve
    High configuration times
    Many dependencies
    A bit too much for small/quick projects
    A bit too much for small/quick projects -> Good for small/quick projects
    Many dependencies -> Only the dependencies you need
    High configuration times -> Low configuration times (if you want)
    Steep learning curve -> You can start “easy”

    View full-size slide

  52. Victoria Quirante
    @vicqr
    [email protected]
    Keeping/enhancing the good and improving the bad
    SF 1 SF 2 SF 3 SF 4
    A different FW A step in between Equally powerful
    More flexible
    Easier to start with
    Lower configuration times
    Better integration with the front-end
    Moved further towards standardization
    A new, better approach

    View full-size slide

  53. STRENGTHS
    Andreas Fidler - https://unsplash.com/@speckfechta
    What is Symfony
    very good at

    View full-size slide

  54. Good for large and small
    projects

    View full-size slide

  55. Victoria Quirante
    @vicqr
    [email protected]
    Good for large and small projects
    You don’t have to carry unneeded dependencies
    The feeling of “SF is too much for this project” is not there anymore

    View full-size slide

  56. Victoria Quirante
    @vicqr
    [email protected]
    Good for large and small projects
    APIs
    Admin panels Mobile backends
    Enterprise
    software
    Complex web
    apps
    Prototypes MVPs Side projects
    Simple web
    apps
    Presentation
    sites

    View full-size slide

  57. Victoria Quirante
    @vicqr
    [email protected]
    "require": {
    "php": "^7.1.3",
    "ext-iconv": "*",
    "symfony/console": "^4.0",
    "symfony/flex": "^1.0",
    "symfony/framework-bundle": "^4.0",
    "symfony/lts": "^4@dev",
    "symfony/yaml": "^4.0"
    }
    "require": {
    "php": "^7.1.3",
    "ext-iconv": "*",
    "sensio/framework-extra-bundle": "^5.1",
    "symfony/asset": "^4.0",
    "symfony/console": "^4.0",
    "symfony/expression-language": "^4.0",
    "symfony/flex": "^1.0",
    "symfony/form": "^4.0",
    "symfony/framework-bundle": "^4.0",
    "symfony/lts": "^4@dev",
    "symfony/monolog-bundle": "^3.1",
    "symfony/orm-pack": "*",
    "symfony/process": "^4.0",
    "symfony/security-bundle": "^4.0",
    "symfony/serializer-pack": "*",
    "symfony/swiftmailer-bundle": "^3.1",
    "symfony/twig-bundle": "^4.0",
    "symfony/validator": "^4.0",
    "symfony/web-link": "^4.0",
    "symfony/webpack-encore-pack": "*",
    "symfony/yaml": "^4.0"
    }
    "A minimal Symfony
    project recommended to
    create bare bones
    applications"
    "A skeleton to start a
    new Symfony
    website"
    symfony/skeleton symfony/website-skeleton

    View full-size slide

  58. Victoria Quirante
    @vicqr
    [email protected]
    Good for large and small projects

    View full-size slide

  59. Good if you know a lot or
    a little

    View full-size slide

  60. Victoria Quirante
    @vicqr
    [email protected]
    Good if you know a lot or a little
    You can start using SF without a deep understanding of the FW
    Understanding the FW will allow you to master it

    View full-size slide

  61. Good to develop “fast”
    and “slow”

    View full-size slide

  62. Victoria Quirante
    @vicqr
    [email protected]
    Good to develop fast and slow
    With Symfony you can go for RAD
    SF makes your life easier, but the decisions are yours
    Emphasizing working software and
    user feedback over strict planning
    and requirements recording
    But you can also go for DDD/CQRS if you want

    View full-size slide

  63. Whatever the case, it is
    going to help developing
    better code faster

    View full-size slide

  64. It pushes you to write
    good code

    View full-size slide

  65. Victoria Quirante
    @vicqr
    [email protected]
    It pushes you to write good code
    Decoupled services
    Thin controllers
    Clean templates
    ...
    Code that is easy to test, read, maintain and refactor

    View full-size slide

  66. It makes easy to grow

    View full-size slide

  67. It doesn’t matter how
    simple a project looks at
    the beginning...
    Andhrastea Pipperly - https://unsplash.com/@thepipperly

    View full-size slide

  68. Complexity will find its way

    View full-size slide

  69. It makes easy to grow

    View full-size slide

  70. It makes easy to grow in
    a right way

    View full-size slide

  71. “WEAKNESSES”...
    Or what is Symfony
    not suited for

    View full-size slide

  72. Victoria Quirante
    @vicqr
    [email protected]
    Not the coolest newest thing
    Symfony is a mature technology
    It helps you writing better code faster
    Helping you looking cool is not part of its work

    View full-size slide

  73. Victoria Quirante
    @vicqr
    [email protected]
    Not a front-end framework!
    Rich front-ends require a front-end framework
    Don’t try to build a rich front-end with a back-end framework

    View full-size slide

  74. Victoria Quirante
    @vicqr
    [email protected]
    Not if there is nothing custom in your software
    Symfony helps a lot building custom software
    If you want to build something very standard, SF won’t save time

    View full-size slide

  75. Victoria Quirante
    @vicqr
    [email protected]
    Not if you want everything done for you
    Symfony makes life easier, but it needs you to work and take decisions
    If you want everything done out-of-the-box, pick something else

    View full-size slide

  76. The learning curve is not
    so steep, but there are
    easier things out there if
    you want

    View full-size slide

  77. Victoria Quirante
    @vicqr
    [email protected]
    Some other solutions are...
    Easier to start with
    Perhaps not as flexible / powerful, but it depends on what you look for

    View full-size slide

  78. Victoria Quirante
    @vicqr
    [email protected]
    Typing less saves time… Or not. It depends.
    difficulty to build
    sth simple
    difficulty to
    build sth
    complex

    View full-size slide

  79. What the best
    tool is depends
    on your goals,
    your team, your
    resources
    Don’t be a hooligan

    View full-size slide

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

    View full-size slide

  81. 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
    Victoria Quirante
    @vicqr
    [email protected]

    View full-size slide

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

    View full-size slide

  83. Victoria Quirante
    @vicqr
    [email protected]
    EasyAdmin
    Victoria Quirante
    @vicqr
    [email protected]

    View full-size slide

  84. 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
    Victoria Quirante
    @vicqr
    [email protected]

    View full-size slide

  85. WHAT ABOUT THE FUTURE
    Can we predict what
    will happen?
    https://www.flickr.com/photos/imagesnewman/33023955620

    View full-size slide

  86. How does it feel
    developing in SF once
    you are comfortable with
    it?

    View full-size slide

  87. Robert Szaskowski - https://unsplash.com/@robert_szadkowski
    As it should
    Boring

    View full-size slide

  88. Blake Lipthratt - https://unsplash.com/@blake_lipthratt
    As it should
    Boring

    View full-size slide

  89. Victoria Quirante
    @vicqr
    [email protected]
    How does it feel developing with Symfony?
    Boring =
    Solid
    Consistent
    Predictable
    Tidy

    View full-size slide

  90. Victoria Quirante
    @vicqr
    [email protected]
    We cannot predict but...
    SF has proven to be a powerful and solid solution for backends
    Companies like mature technologies
    Many have been/are changing their spaghetti code to SF
    The FW is successfully adapting the new challenges
    We are going to need APIs, admin panels, etc. for a long time
    Imho, SF is going to be around for a good while

    View full-size slide

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

    View full-size slide

  92. Victoria Quirante
    @vicqr
    [email protected]
    Summarizing
    SF4 has been a significant evolution
    On top of a mature, powerful, flexible framework
    It is possible to start easy
    And make something as complex as you need
    While following best practices and keeping your code nice and clean
    That makes it for me a very good choice for the back-end

    View full-size slide

  93. Victoria Quirante
    @vicqr
    [email protected]
    Summarizing
    It is a mature, powerful, flexible framework
    It is not the one with the easiest learning curve
    But it is possible to start easy
    And make something as complex as you need
    While following best practices and keeping your code nice and clean
    That makes it for me a very good choice for the back-end
    It may be also for
    you (or not) :)

    View full-size slide

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

    View full-size slide