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

Symfony4 - A new way of developing web applications

Symfony4 - A new way of developing web applications

Symfony4 is here and it is better than ever. With Flex it can be a micro framework and an amazing beast with any feature you want.

What changed from version 3, what are new best practices and why Symfony is moving PHP world forward once again you can find in this talk.

Antonio Peric-Mazar

August 16, 2018
Tweet

More Decks by Antonio Peric-Mazar

Other Decks in Programming

Transcript

  1. Symfony4
    A new way to develop web applications
    Antonio Perić-Mažar, Locastic

    View Slide

  2. Antonio Perić-Mažar
    CEO @ Locastic
    Co-Organizer @ BlockSplit Conference
    Tinel Meetup
    [email protected]
    @antonioperic
    @antonioperic

    View Slide

  3. Locastic
    ● We help clients create amazing web and mobile
    apps (since 2011)
    ○ mobile development
    ○ web development
    ○ UX/UI
    ○ Training and Consulting
    ● @locastic
    ● www.locastic.com
    ● Split, Croatia
    @antonioperic

    View Slide

  4. @antonioperic
    Photo: Goran Leš

    View Slide

  5. Text
    @antonioperic
    https://lifestyle.clickhole.com/the-evolution-of-man-7-new-physical-traits-that-humans-1825122200

    View Slide

  6. Text
    @antonioperic

    View Slide

  7. Text
    @antonioperic

    View Slide

  8. Text
    @antonioperic

    View Slide

  9. Text
    @antonioperic
    30.11.2017

    View Slide

  10. @antonioperic
    Fabien Potencier

    View Slide

  11. We can do better
    ● Installing a Bundle is too cumbersome
    ● Remove a Bundle is too cumbersome
    @antonioperic

    View Slide

  12. We can do better
    ● Installing a Bundle is too cumbersome
    ● Remove a Bundle is too cumbersome
    ● The standard edition is not good enough
    @antonioperic

    View Slide

  13. We can do better
    ● Installing a Bundle is too cumbersome
    ● Remove a Bundle is too cumbersome
    ● The standard edition is not good enough
    ● You always have a lot of code that you are not using
    but it is to hard to remove it
    @antonioperic

    View Slide

  14. @antonioperic
    Fabien Potencier

    View Slide

  15. Symfony4
    ● Starting as micro framework
    ● Compose your application / setup your stack
    ● Build API, console app, traditional web app or
    whatever you want
    @antonioperic

    View Slide

  16. @antonioperic

    View Slide

  17. Symfony Flex
    ● Composer plugin
    ● Auto-configuration via recipes
    @antonioperic

    View Slide

  18. Symfony Flex
    ● Composer plugin
    ● Auto-configuration via recipes
    @antonioperic
    Fabien Potencier

    View Slide

  19. Symfony flex
    @antonioperic

    View Slide

  20. Symfony flex
    @antonioperic

    View Slide

  21. Mailer manifest.json
    @antonioperic

    View Slide

  22. Symfony flex recipies
    ● Two repositories
    ● symfony/recipies
    ○ maintained by Symfony Core Team and holds only recipies
    for Symfony components and bundles ‘opinionated’ by them
    ○ Can use alias
    ● symfony/recipies-contrib
    ○ Anyone can contribute
    ○ Cannot use alias
    @antonioperic

    View Slide

  23. www.symfony.sh
    @antonioperic

    View Slide

  24. Directory structure
    @antonioperic

    View Slide

  25. Directory structure
    @antonioperic

    View Slide

  26. Directory structure
    @antonioperic
    we say goodby to app.php and
    app_dev.php — this is now one
    standard index.php file and
    environment is set with
    environmental variable APP_ENV

    View Slide

  27. Directory structure
    @antonioperic

    View Slide

  28. Directory structure
    @antonioperic

    View Slide

  29. Directory structure
    @antonioperic

    View Slide

  30. Directory structure
    @antonioperic
    Flex keeps tracks of the recipes it installed in a
    symfony.lock file, which must be committed to
    your code repository.

    View Slide

  31. Bundle-less applications
    ● Bundle vs no-bundle apps
    ● All in src folder
    ○ App/ namespace
    ○ You should separate, but no need for bundles
    ● Moving forward to standardisation
    ● It reduces the perceived complexity, also makes
    your code feels more decoupled from symfony
    ● Bundle inheritance mechanisms are deprecated in
    3.4 and were removed in 4.0
    @antonioperic

    View Slide

  32. Let’s call this a small demo
    - Our task will be to create simple Symfony console
    application, a web crawler
    - Steps:
    - Create new symfony application
    - composer create-project symfony/skeleton my_project
    - Add Console component
    - Add Doctrine
    - Add Symfony Crawler component
    - Do some code (we will not do code, idea is just to see the
    flow of working with Symfony4)
    @antonioperic

    View Slide

  33. Create new Symfony4 application
    @antonioperic

    View Slide

  34. Create new Symfony4 application
    @antonioperic

    View Slide

  35. Add components
    ● Composer req cli
    ● Composer req doctrine
    ● Composer req symfony/dom-crawler
    @antonioperic

    View Slide

  36. Autowiring
    ● Introduced in Symfony 3 version
    ● Autowiring allows you to manage services in the
    container with minimal configuration
    ● It reads the type-hints on your constructor (or other
    methods) and automatically passes the correct
    services to each method.
    ● Symfony's autowiring is designed to be predictable:
    if it is not absolutely clear which dependency should
    be passed, you'll see an actionable exception. @antonioperic

    View Slide

  37. Autowire
    @antonioperic

    View Slide

  38. Autowiring
    @antonioperic

    View Slide

  39. Symfony Webpack Encore
    ● Webpack encore is a simpler way to integrate
    Webpack into your application
    ● Step forward after AsseticBundle
    ● composer require webpack-encore
    ● It can work outside of Symfony
    @antonioperic

    View Slide

  40. About me
    Text
    @antonioperic

    View Slide

  41. DotEnv component
    ● The Dotenv Component parses .env files to make
    environment variables stored in them accessible via
    getenv(), $_ENV or $_SERVER.
    ● composer require symfony/dotenv
    @antonioperic

    View Slide

  42. DotEnv component
    @antonioperic

    View Slide

  43. Performance
    Hello world test
    @antonioperic
    Fabien Potencier

    View Slide

  44. Performance
    @antonioperic

    View Slide

  45. Performance
    @antonioperic
    Fabien Potencier

    View Slide

  46. Updating to Symfony
    ● It is possible, not even to complex
    ● Need a little bit of time
    ● If you are using Symfony2.x, upgrade first to 3.4
    @antonioperic

    View Slide

  47. Symfony 4.1 improvements
    ● Made csrf_token() useable without forms
    ● Csv processor for env variables
    ● Display DotEnv variables in profiler
    ● Session improvements
    ● Console improvements
    ● Workflow improvements
    ● Messenger component
    https://symfony.com/blog/symfony-4-1-curated-new-
    features @antonioperic

    View Slide

  48. Roadmap
    @antonioperic

    View Slide

  49. 7 months later
    ● It is great feeling to works with Symfony4
    ● Seems that Fabien and core team are making great
    progress moving Symfony forward
    ● I love Flex
    ● It is seems much more natural to navigate through
    new code structure and DX is much better
    ● Symfony community is awesome
    @antonioperic

    View Slide

  50. 7 months later
    ● Symfony is great as microframework
    ● With higher level of abstraction is more better for
    prototyping and building things fast
    ● It will be much easier to start, but maybe even
    harder to master for newbies (symfony2 wasn’t easy
    to master)
    @antonioperic

    View Slide

  51. Thank you!
    @antonioperic

    View Slide

  52. Questions?
    @antonioperic

    View Slide