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

Developing with Symfony 4

Victoria Quirante
June 07, 2018
140

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 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 Slide

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

    View Slide

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

    View 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 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 Slide

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

    View Slide

  8. Victoria Quirante
    @vicqr
    [email protected]
    Doctrine

    View Slide

  9. Victoria Quirante
    @vicqr
    [email protected]
    Propel

    View Slide

  10. Victoria Quirante
    @vicqr
    [email protected]
    Silex

    View Slide

  11. Victoria Quirante
    @vicqr
    [email protected]
    Drupal

    View Slide

  12. Victoria Quirante
    @vicqr
    [email protected]
    Laravel

    View 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 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 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 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 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 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 Slide

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

    View 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 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 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 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 Slide

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

    View 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 Slide

  26. How does Symfony 4
    provide this?

    View Slide

  27. SYMFONY 4 PHILOSOPHY
    https://www.flickr.com/photos/[email protected]/16357411958
    How are things now

    View 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 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 Slide

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

    View 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 Slide

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

    View 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 Slide

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

    View 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 Slide

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

    View 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 Slide

  38. SYMFONY FLEX
    What exactly is it

    View Slide

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

    View 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 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 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 Slide

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

    View 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 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 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": "^[email protected]",
    "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 Slide

  47. Any other big news in
    Symfony 4?

    View Slide

  48. A great solution for
    the assets

    View 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 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 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 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 Slide

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

    View Slide

  54. Good for large and small
    projects

    View 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 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 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": "^[email protected]",
    "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": "^[email protected]",
    "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 Slide

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

    View Slide

  59. Good if you know a lot or
    a little

    View 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 Slide

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

    View 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 Slide

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

    View Slide

  64. It pushes you to write
    good code

    View 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 Slide

  66. It makes easy to grow

    View Slide

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

    View Slide

  68. Complexity will find its way

    View Slide

  69. It makes easy to grow

    View Slide

  70. It makes easy to grow in
    a right way

    View Slide

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

    View 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 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 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 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 Slide

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

    View 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 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 Slide

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

    View Slide

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

    View 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]m

    View Slide

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

    View Slide

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

    View 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 Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View 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 Slide

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

    View 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 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 Slide

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

    View Slide