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. 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]
  2. Victoria Quirante @vicqr [email protected] Symfony evolution SF 1 SF 2

    SF 3 SF 4 A different FW A new, better approach Monolithic
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. Victoria Quirante @vicqr [email protected] Recent evolution of the web development

    environment Our favourite framework Some jQuery { { Back-end Front-end
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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”
  18. 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
  19. «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
  20. SF4 is not a new FW, it is a new

    mindset behind the same FW
  21. 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
  22. 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
  23. SF FLEX is not a version of SF, it is

    a tool to implement SF4’s philosophy
  24. «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
  25. 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
  26. 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
  27. Victoria Quirante @vicqr [email protected] How does it work composer req

    mailer It installs and enables SwiftmailerBundle composer require mailer
  28. 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
  29. 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
  30. 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
  31. 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
  32. 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?
  33. 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”
  34. 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
  35. 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
  36. 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
  37. 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
  38. 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
  39. 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
  40. 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
  41. It doesn’t matter how simple a project looks at the

    beginning... Andhrastea Pipperly - https://unsplash.com/@thepipperly
  42. 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
  43. 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
  44. 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
  45. 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
  46. The learning curve is not so steep, but there are

    easier things out there if you want
  47. 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
  48. Victoria Quirante @vicqr [email protected] Typing less saves time… Or not.

    It depends. difficulty to build sth simple difficulty to build sth complex
  49. What the best tool is depends on your goals, your

    team, your resources Don’t be a hooligan
  50. 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]
  51. 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]
  52. WHAT ABOUT THE FUTURE Can we predict what will happen?

    https://www.flickr.com/photos/imagesnewman/33023955620
  53. Victoria Quirante @vicqr [email protected] How does it feel developing with

    Symfony? Boring = Solid Consistent Predictable Tidy
  54. 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
  55. 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
  56. 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) :)