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

Drupal 10 from the pov of a Symfony 6 core-contributor

Drupal 10 from the pov of a Symfony 6 core-contributor

While Drupal 8 & 9 rely on Symfony 3.4 & 4.4 respectively, Drupal 10 is going to be based on Symfony 6.2. That's a nice a leap forward that will allow Drupalers to catch up on almost 3 years of innovation on Symfony's side \o/

In this presentation, we'll review the new features coming to core from Symfony that you could take advantage of. Think about more expressive/automated ways to do dependency-injection, using PHP 8 attributes to configure all-the-things, translation providers, safer sub-processes, etc.

So much new power-tools at your disposal that just wait to be learned about!

Nicolas Grekas

September 22, 2022
Tweet

More Decks by Nicolas Grekas

Other Decks in Programming

Transcript

  1. @nicolasgrekas #DrupalConPrague
    Drupal 10 from the pov of
    a Symfony 6 core-contributor
    Nicolas Grekas

    View Slide

  2. @nicolasgrekas
    General Manager at Symfony Corp.
    Core-team member since 2014
    ~3000 PRs sent to symfony/symfony

    View Slide

  3. Symfony
    TL;DR

    View Slide

  4. Symfony OSS
    •
    Open Source Software since 2011 (v2)
    •
    Built for the web, built in PHP
    •
    The top-most used PHP components
    •
    The second top-most used PHP framework
    •
    3 000 contributors
    •
    ~60 core components, ~200 packages
    •
    14B cumulated downloads

    View Slide

  5. Designed for cheap upgrades
    Within the same major:
    The Backward Compatibility Promise
    Across major versions:
    The Continuous Upgrade Path
    TL;DR
    composer up symfony/* every 1 month
    Upgrade to the next “minor” every 6 months
    (in June and December) and fix deprecations
    Roadmap

    View Slide

  6. 1.
    Any planned break MUST issue
    a deprecation notice
    2.
    Deprecating and upgrading
    must be done in the same PR
    3.
    You should be able to upgrade
    Symfony XOR php
    Continuous Upgrade Path

    View Slide

  7. •
    Core-Team
    •
    Security Policy
    •
    Welcoming Spaces
    •
    CARE Team
    •
    Friendly CI
    Community Principles

    View Slide

  8. Cutting Edge Practices
    •
    v4.4 : Support for PHP 8.0, 8.1 and 8.2(!) deprecation-less
    •
    v5.4 : Support new features of the language (attributes, enums)
    •
    v6.0 : Drop deprecated code
    •
    v6.1 : Use modern-style syntax
    •
    v6.1 : Better type declarations with native and generic types
    •
    v6.2 : Still WIP - More attributes
    Last 12 months
    •
    +8000 files modified -- +470/-430k files
    •
    +2000 PRs - 6/day
    •
    400 features -- 700 bugs -- +900(!) minors

    View Slide

  9. https://dri.es/

    View Slide

  10. Drupal 10
    From Symfony 4.4 to 6.2

    View Slide

  11. Drupal 10 Core
    •
    Console
    •
    DependencyInjection
    •
    EventDispatcher
    •
    HttpFoundation
    •
    HttpKernel
    •
    Mime
    •
    Process
    •
    Routing
    •
    Serializer
    •
    String
    •
    Validator
    •
    VarExporter
    •
    VarDumper
    •
    Yaml
    •
    Twig
    •
    Cache
    •
    Clock
    •
    Dotenv
    •
    ErrorHandler
    •
    HttpClient
    •
    HtmlSanitizer
    •
    Mailer
    •
    Messenger
    •
    Notifier
    •
    Uid
    •
    Workflow

    View Slide

  12. PHP >= 8.1
    •
    Native return types
    •
    (nested) Attributes
    •
    Enums
    •
    Serializable

    View Slide

  13. Symfony String
    Object-oriented abstraction to deal with binary and Unicode strings
    u('Symfony is great')->slice(0, 7); // 'Symfony'
    Slugger
    $slugger->slug('Wôrķšƥáçè sèťtïñğš '); // 'Workspace-settings-smiley-cat'
    Inflector
    $inflector->singularize('teeth'); // ['tooth']

    View Slide

  14. Symfony Process
    Arrays for single processes
    new Process(['ls', '-lsa', $path])
    Prepared command-lines when needing a shell
    $process = Process::fromShellCommandline('ls -lsa "${:path}" | grep foo');
    $process->run(null, ['path' => '/path/to/some/dir']);

    View Slide

  15. Symfony Routing
    #[Route(
    path: '/users/{id}',
    requirements: ['id' => Requirement::ULID]
    )]
    public const ULID = '[0-7][0-9A-HJKMNP-TV-Z]{25}';
    public const DIGITS = '[0-9]+';
    // ...
    # modules/custom/custom/coffee_shop/coffee_shop.routing.yml
    coffee_shop:
    resource: src/Controller/
    type: attribute

    View Slide

  16. Symfony HttpFoundation
    RFC 8674 - Avoid objectionable content, as defined by the origin server
    $request->preferSafeContent(); // Prefer: safe
    $response->setContentSafe(); // Preference-Applied: safe
    // Vary: Prefer

    View Slide

  17. Symfony HttpKernel
    •
    Replace KernelEvent::isMasterRequest() by isMainRequest()
    •
    Add argument $catchThrowable to HttpKernel::__construct()?
    •
    #[AsController] - needs RegisterControllerArgumentLocatorsPass
    •
    #[Cache] - needs CacheAttributeListener
    •
    Value resolvers for DateTime, BackedEnum and Uid

    View Slide

  18. Symfony DependencyInjection
    •
    #[Autowire('%foo%')]
    •
    #[TaggedIterator + TaggedLocator + AsTaggedItem]
    •
    #[AsDecorator + MapDecorated + .inner]
    •
    #[Target]
    •
    #[Required]

    View Slide

  19. Symfony DependencyInjection
    •
    #[Autoconfigure] and #[AutoconfigureTag]
    •
    Expressions as service factories
    •
    Native lazy-loading services

    View Slide

  20. Let’s run a barista

    View Slide

  21. Let’s run a barista

    View Slide

  22. Let’s run a barista

    View Slide

  23. Let’s run a barista

    View Slide

  24. Let’s run a barista

    View Slide

  25. Put *.services.yml on a diet
    •
    Enable auto-discovery – RIP providers
    •
    Enable auto-configuration – RIP tags/passes
    •
    Enable controllers as services – RIP Drupal::service()
    •
    Enable custom value resolvers – at least enable the new ones in core
    •
    Enable #[Autowire('%env(FOO)%')]
    •
    Enable #[Route]
    •
    (Don’t force lowercase service ids)
    •
    (Document how to auto-invalidate the container from CLI)

    View Slide

  26. Undergo change or be the change
    •
    Be creative
    •
    Grow your roots and standardize
    •
    Embrace deprecations
    •
    And delete code!

    View Slide

  27. Kudos!
    D+S=<3

    View Slide

  28. the general
    conference survey
    Flash the QR code
    OR
    It will be sent by email
    the Individual
    session surveys
    (located under each session description)
    1 2

    View Slide