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

Symfony in 2019

Symfony in 2019

Fabien Potencier

June 20, 2019
Tweet

More Decks by Fabien Potencier

Other Decks in Programming

Transcript

  1. 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
  2. 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: [email protected] 1,000+ attendees and 30+ speakers will be there during our 2-day conference!
  3. What is Symfony 4? A new developer experience On a

    rock solid foundation From micro-style to monolith and prototypes
  4. Symfony Local Web Server $ symfony server:start -d # open

    in the browser $ symfony open:local # tail the logs $ symfony server:log
  5. • 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
  6. $ 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
  7. 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
  8. 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
  9. $ 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
  10. 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
  11. $ composer req twig Adding Twig + Controller as a

    service + No manual changes + No configuration + Auto-wiring Productivity++
  12. 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
  13. Full Automation works for… • Twig extensions • Event listeners

    • Doctrine entities/repositories • Commands • Voters • Registration form system • …
  14. $ composer req symfony/mailer Sending emails use Symfony\Component\Mailer\MailerInterface; public function

    index(MailerInterface $mailer) { $mailer->send( (new Email()) ->from('[email protected]') ->to('[email protected]') ->subject('Some subject') ->text('Some text...') ); MAILER_DSN=smtp://localhost + No configuration + No manual changes + Auto-wiring + Env vars
  15. Sending emails use Symfony\Component\Mailer\MailerInterface; public function index(MailerInterface $mailer) { $mailer->send(

    (new TemplatedEmail()) ->from('[email protected]') ->to('[email protected]') ->subject('Some subject') ->htmlTemplate('@emails/welcome.html.twig') ->context([ 'city' => 'Tunis' ]) );
  16. $ 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 %}
  17. I want to send rich and responsive emails
 from my

    controller
 via my provider's API
  18. I want to send rich and responsive emails
 from my

    controller
 via my provider's API
 asynchronously
  19. $ 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
  20. I want to send rich and responsive emails
 from my

    controller
 via my provider's API
 asynchronously with AMQP
  21. 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
  22. I want to send rich and responsive emails
 from my

    controller
 via my provider's API
 asynchronously with AMQP
  23. 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
  24. I want to send rich and responsive emails
 from my

    controller
 via my provider's API
 asynchronously with AMQP
 and manage failures gracefully
  25. framework: messenger: transports: email: dsn: "%env(RABBITMQ_DSN)%" retry_strategy: max_retries: 3 routing:

    Symfony\Component\Mailer\Messenger\SendEmailMessage: email Sending emails
  26. 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
  27. 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
  28. $ 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
  29. $ 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)%"
  30. Experience The new Components: http-client, messenger, mailer, container, ... Concepts:

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

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

    
 ... so, what have you done so far for Symfony 4.4?