Symfony in 2019

Symfony in 2019

9a22d09f92d50fa3d2a16766d0ba52f8?s=128

Fabien Potencier

June 20, 2019
Tweet

Transcript

  1. Fabien Potencier @fabpot in 2019

  2. How many of are going
 to SymfonyCon Amsterdam?

  3. Join us for a week of Symfony, November 19-23, at

    the Beurs van Berlage: • November 19-20: 2-day pre- conference workshops • November 21-22: 2-day conference (3 tracks and 1 Unconference) • November 23: 1-day Hackday Get an exclusive 10% discount on your registration using the code: SFC19PHPAMS Code available until June 26 2019 amsterdam2019.symfony.com
  4. Come to meet the international Symfony and PHP communities! Become

    a Sponsor of the event! Support the framework and get visibility for your company during the conference! Contact us: events@symfony.com 1,000+ attendees and 30+ speakers will be there during our 2-day conference!
  5. Which
 Symfony version(s)
 are you using? 1.x? 2.x? 3.x? 4.x?

  6. What is Symfony 4? A new developer experience On a

    rock solid foundation From micro-style to monolith and prototypes
  7. Wired? Tired? or

  8. Symfony
 Encore Webpack Assetic

  9. Symfony Local Web Server Built-in
 PHP server

  10. Symfony Local Web Server $ symfony server:start -d # open

    in the browser $ symfony open:local # tail the logs $ symfony server:log
  11. • PHP-FPM (concurrent requests) • HTTP 2 • TLS •

    Local domain names • No dependencies / single binary (MacOS, Linux, and Windows) • Manages background commands (Encore, Messenger, ...) • Consolidated logs (PHP , Web server, app, background commands) • Docker integration (and SymfonyCloud) • Multiple versions of PHP • HTTP Link/pre-load/push support Symfony Local Web Server
  12. 12 https://symfony.com/download

  13. $ symfony new demo $ symfony new demo --cloud --debug

    # Want to try Symfony 5.0 (dev version)? $ symfony new demo --version=dev-master Creating a new project
  14. Symfony CLI SensioLabs Security Checker

  15. $ symfony security:check Does not call
 https://security.symfony.com/ Clones and caches


    https://github.com/FriendsOfPHP/security-advisories/
  16. Symfony
 Components symfony/symfony

  17. Symfony 2+/3+ Monolog Bundle SwiftMailer Bundle Polyfill Util Polyfill PHP

    7.0 Polyfill PHP 5.6 Polyfill Mbstring Polyfill Intl ICU Polyfill APCu PHPUnit Bridge Debug Bundle Framework Bundle Security Bundle Twig Bundle WebProfiler Bundle WebServer Bundle Doctrine Bridge Monolog Bridge Twig Bridge Monolog Doctrine (11) SecurityChecker Generator Bundle ParamHandler FrameworkExtra Bundle Distribution Bundle Asset BrowserKit Cache ClassLoader Config Console CssSelector Debug DependencyInjection DomCrawler Dotenv EventDispatcher ExpressionLanguage Filesystem Finder Form HttpFoundation HttpKernel Inflector Intl Ldap OptionsResolver Process PropertyAccess PropertyInfo Routing Security Serializer Stopwatch Templating Translation Validator VarDumper WebLink Workflow Yaml 4 bridges 15 librairies 11 bundles 42 components SwiftMailer
  18. Symfony 4+/5+ Polyfill Mbstring Framework Bundle Cache Config Debug DependencyInjection

    Dotenv EventDispatcher Filesystem Finder HttpFoundation HttpKernel Routing Yaml 0 bridges 1 library 1 bundle 13 components Flex
  19. $ symfony new demo # Forms are ❌ disabled as

    symfony/form is not installed $ composer req form # Forms are automatically ✅ enabled as symfony/form is installed + Auto-configuration + No manual changes + Better performance
  20. Third-party
 Bundles with recipes Application
 Bundles

  21. $ cat src/Controller/DefaultController.php App vs Bundles src/ is about YOUR

    code
  22. Environment Variables Class Constants Parameters n/a

  23. Parameter Class constant Environment variable Can be provided
 by a

    third party ("standard") ❌ ❌ ✅ Can be changed
 without cache:clear ❌ ❌ ✅ Easy to use in code ❌ ✅ Can be changed
 without redeploy ❌ ✅ Can be different
 in dev and prod ✅ ❌ ✅ Can be stored
 outside of a Git repo ✅ ❌ ✅ Rich type support via processors Example Configure
 behavior Configure
 behavior Configure
 infrastructure
  24. Container Auto-discovery Auto-configuration Auto-wiring Service
 Configuration

  25. $ composer req twig Adding Twig + Controller as a

    service + No manual changes + No configuration + Auto-wiring Productivity++
  26. Never define
 your service again*

  27. Maker
 Bundle Generator
 Bundle

  28. $ ./bin/console list make Symfony Maker Bundle

  29. $ ./bin/console make:controller DefaultController Symfony Maker Bundle

  30. $ cat src/Controller/DefaultController.php Symfony Maker Bundle Annotations Everything in one

    file
  31. Adding a Twig Extension Where do I store the Twig

    extension class? Which file do I need to change to register it? Which tag do I need to use? How do I declare a tag in YAML? Which interface/class do I need to implement/ extend? It’s too complex. What about doing it the dirty way and do it in the controller instead? hmm, ok
  32. $ ./bin/console make:twig-extension Adding a Twig Extension Add your logic

    in the generated class… DONE!
  33. Full Automation works for… • Twig extensions • Event listeners

    • Doctrine entities/repositories • Commands • Voters • Registration form system • …
  34. Twig
 Templates PHP
 Templates

  35. You can use PHP templates But Twig benefits
 from a

    fully maintained integration
  36. Symfony
 Mailer Swiftmailer

  37. A great example of
 how we leverage
 the "new" Symfony

    infrastructure
  38. I want to send emails
 from my controller

  39. $ composer req symfony/mailer Sending emails use Symfony\Component\Mailer\MailerInterface; public function

    index(MailerInterface $mailer) { $mailer->send( (new Email()) ->from('fabien@symfony.com') ->to('fabien@symfony.com') ->subject('Some subject') ->text('Some text...') ); MAILER_DSN=smtp://localhost + No configuration + No manual changes + Auto-wiring + Env vars
  40. I want to send rich emails
 from my controller

  41. Sending emails use Symfony\Component\Mailer\MailerInterface; public function index(MailerInterface $mailer) { $mailer->send(

    (new TemplatedEmail()) ->from('fabien@symfony.com') ->to('fabien@symfony.com') ->subject('Some subject') ->htmlTemplate('@emails/welcome.html.twig') ->context([ 'city' => 'Tunis' ]) );
  42. I want to send rich and responsive emails
 from my

    controller
  43. $ composer req twig/inky-extension twig/cssinliner-extension Sending emails {% apply inky|inline_css(source("@zurb/stylesheets/main.css"))

    %} <container> <row class="header"> <columns> <spacer size="16"></spacer> <h4 class="text-center">Symfony Connect</h4> </columns> </row> <row> <columns> <spacer size="32"></spacer> <center><img width="100px" src="{{ email.image("@images/symfony.png") }}"></center> <spacer size="16"></spacer> <h1 class="text-center">Forgot Your Password?</h1> <spacer size="16"></spacer> <p class="text-center">It happens. Click the link below to reset it.</p> <button class="large expand" href="#">Reset Password</button> <hr/> <p><small><center><a href="#">unsubscribe here</a>.</small></center></p> </columns> </row> </container> {% endapply %}
  44. I want to send rich and responsive emails
 from my

    controller
 via my provider's API
  45. $ composer req mailgun-mailer MAILER_DSN=http://$MAILGUN_KEY:$MAILGUN_DOMAIN@mailgun Sending emails Amazon SES Google

    Gmail Mandrill Mailgun Postmark Sendgrid
  46. I want to send rich and responsive emails
 from my

    controller
 via my provider's API
 asynchronously
  47. $ composer req messenger framework: messenger: transports: email: "doctrine://default" routing:

    Symfony\Component\Mailer\Messenger\SendEmailMessage: email $ ./bin/console messenger:consume $ symfony run -d ./bin/console messenger:consume -vv Sending emails Go to the background
  48. $ symfony server:status $ symfony server:log Sending emails

  49. I want to send rich and responsive emails
 from my

    controller
 via my provider's API
 asynchronously with AMQP
  50. At this point, think about
 how you would do it


    with Symfony 3.4 Here, we have not written
 a single line of code
 and barely changed the configuration
  51. We are only using Symfony components

  52. I want to send rich and responsive emails
 from my

    controller
 via my provider's API
 asynchronously with AMQP
  53. framework: messenger: transports: email: "%env(RABBITMQ_DSN)%" routing: Symfony\Component\Mailer\Messenger\SendEmailMessage: email $ docker-compose

    up -d Sending emails rabbitmq: image: rabbitmq ports: - 5672 docker-compose.yml Symfony Local Web Server
 Env vars "auto-wiring" Local port is random
  54. I want to send rich and responsive emails
 from my

    controller
 via my provider's API
 asynchronously with AMQP
 and manage failures gracefully
  55. $ composer req symfony/sendgrid-mailer MAILER_DSN=http://key:domain@mailgun || http://key@sendgrid Sending emails

  56. framework: messenger: transports: email: dsn: "%env(RABBITMQ_DSN)%" retry_strategy: max_retries: 3 routing:

    Symfony\Component\Mailer\Messenger\SendEmailMessage: email Sending emails
  57. framework: messenger: failure_transport: failed transports: failed: 'doctrine://default?queue_name=failed' email: dsn: "%env(RABBITMQ_DSN)%"

    retry_strategy: max_retries: 3 routing: Symfony\Component\Mailer\Messenger\SendEmailMessage: email $ symfony server:log $ ./bin/console messenger:failed:show $ ./bin/console messenger:failed:retry Sending emails
  58. Sending emails

  59. I want to send rich and responsive emails
 from my

    controller
 via my provider's API
 asynchronously with AMQP
 and manage failures gracefully
 without Docker
  60. $ symfony project:init $ symfony deploy $ symfony log --worker=send_emails

    all Sending emails rabbitmq: type: rabbitmq:3.7 disk: 1500 .symfony/services.yaml .symfony.cloud.yaml runtime: extensions: [ "amqp" ] relationships: rabbitmq: "rabbitmq:rabbitmq" workers: send_emails: commands: start: | set -x -e (>&2 symfony-deploy) bin/console messenger:consume -vv email Production ready
  61. $ symfony tunnel:open Sending emails Symfony Local Web Server
 Env

    vars "auto-wiring" .symfony.cloud.yaml relationships: rabbitmq: "rabbitmq:rabbitmq" Development ready framework: messenger: transports: email: "%env(RABBITMQ_DSN)%"
  62. Experience The new Components: http-client, messenger, mailer, container, ... Concepts:

    Flex, auto-configuration, env vars, ... Tools: Symfony CLI, SymfonyCloud, Docker
  63. is a fantastic set of low-level building blocks
 that you

    can assemble to develop
 powerful high-level features easily
  64. What about the future? Nobody knows, it depends on you

    
 ... so, what have you done so far for Symfony 4.4?
  65. HTTP errors without Twig Important for API-only applications

  66. PHP 7.4 preload support Performance FTW

  67. A better Security component? https://github.com/symfony/symfony/issues/30914
 https://github.com/symfony/symfony/issues/30765

  68. ... to be continued

  69. Thank you and see you soon!