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

[SymfonyCon Cluj] A year of Symfony

Sarah KHALIL
November 17, 2017

[SymfonyCon Cluj] A year of Symfony

A lot happened! 52 blog posts to help you keep up with all new things, a looooot of pull requests, 2 new versions out… Well I'm sure you missed something. Let's review what happened during last year: basically we'll see and/or discover nice new features that appeared since the last year.

Sarah KHALIL

November 17, 2017
Tweet

More Decks by Sarah KHALIL

Other Decks in Technology

Transcript

  1. @saro0h
    A year of
    Sarah Khalil

    View full-size slide

  2. A little disclaimer

    View full-size slide

  3. A little disclaimer
    E_TOO_MANY_NEWS

    View full-size slide

  4. A little disclaimer
    E_TOO_MANY_NEWS
    You won’t remember
    everything

    View full-size slide

  5. A little disclaimer
    E_TOO_MANY_NEWS
    You won’t remember
    everything
    Relax Enjoy as much as you can
    "

    View full-size slide

  6. A little disclaimer
    E_TOO_MANY_NEWS
    You won’t remember
    everything
    Relax Enjoy as much as you can
    "
    Mission: Adopt Symfony 4!

    View full-size slide

  7. Between
    decem
    ber
    2016
    &
    m
    arch
    2017
    https://speakerdeck.com/saro0h/symfonylive-paris-quoi-de-neuf-depuis-1-an

    View full-size slide

  8. What’s the plan?

    View full-size slide

  9. What’s the plan?
    Community

    View full-size slide

  10. What’s the plan?
    Community
    Some code
    3.3 3.4

    View full-size slide

  11. What’s the plan?
    Community
    Some code
    3.3 3.4
    A little of
    4

    View full-size slide

  12. What’s the plan?
    Community
    Some code
    3.3 3.4
    A little of
    4

    View full-size slide

  13. The Core team: New members
    Robin Chalas (@chalasr) Maxime Steinhausser (@ogizanagi)

    View full-size slide

  14. The Core team: Thank you so much guys! #
    Bernhard Schussek (@webmozart) Abdellatif Ait Boudad (@aitboudad)

    View full-size slide

  15. Pull Requests & Issues since last SymfonyCon

    View full-size slide

  16. Pull Requests & Issues since last SymfonyCon
    $ $ $ $ $ $

    View full-size slide

  17. Pull Requests & Issues since last SymfonyCon
    $ $ $ $ $ $
    $ " %

    View full-size slide

  18. Let’s see some
    code!
    3.3 3.4

    View full-size slide

  19. x.x
    Link to have a look later
    Some explanations
    Since
    which version
    What’s that about?

    View full-size slide

  20. Form and Validator components

    View full-size slide

  21. Form improvements
    New HTML5 types:

    • TelType (obvi )

    • ColorType (color picker)

    • And some more! )*
    3.4
    http://symfony.com/blog/new-in-symfony-3-4-disable-global-form-themes
    http://symfony.com/blog/new-in-symfony-3-4-form-improvements
    http://symfony.com/blog/new-in-symfony-3-4-bootstrap-4-form-theme

    View full-size slide

  22. Form improvements
    New HTML5 types:

    • TelType (obvi )

    • ColorType (color picker)

    • And some more! )*
    3.4
    http://symfony.com/blog/new-in-symfony-3-4-disable-global-form-themes
    http://symfony.com/blog/new-in-symfony-3-4-form-improvements
    http://symfony.com/blog/new-in-symfony-3-4-bootstrap-4-form-theme

    View full-size slide

  23. debug:form command
    • Lists form types, service types, extensions and guessers.

    • Get precise information about a type.

    • Get information by passing the type and an option name.
    3.4
    http://symfony.com/blog/new-in-symfony-3-4-debug-form-command

    View full-size slide

  24. Validation improvement: Group validation in embedded object
    3.4
    class Author
    {
    /** @Assert\NotBlank */
    protected $firstName;
    /** @Assert\Valid(groups={"basic"}) */
    protected $address;
    }
    class Address
    {
    /** @Assert\NotBlank(groups={"basic"}) */
    protected $street;
    /** @Assert\Length(max = 5) */
    protected $zipCode;
    }
    http://symfony.com/blog/new-in-symfony-3-4-groups-support-for-the-valid-constraint

    View full-size slide

  25. Validation improvement: new panel (1/2)
    3.4
    http://symfony.com/blog/new-in-symfony-3-4-validator-information-in-the-symfony-profiler

    View full-size slide

  26. Validation improvement: new panel (2/2)
    3.4
    http://symfony.com/blog/new-in-symfony-3-4-validator-information-in-the-symfony-profiler

    View full-size slide

  27. Validation improvement: new panel (2/2)
    3.4
    http://symfony.com/blog/new-in-symfony-3-4-validator-information-in-the-symfony-profiler

    View full-size slide

  28. Validation improvement: new panel (2/2)
    3.4
    http://symfony.com/blog/new-in-symfony-3-4-validator-information-in-the-symfony-profiler

    View full-size slide

  29. Developer eXperience improvements

    View full-size slide

  30. Prefix in the route name
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
    /**
    * @Route("/blog",
    name="blog_")
    */
    class BlogController extends Controller
    {
    /**
    * @Route("/", defaults={"page": "1"},
    name="index")
    * @Route("/page/{page}", name="index_paginated")
    */
    public function indexAction($page, $_format) { ... }
    /**
    * @Route("/posts/{slug}",
    name="post")
    */
    public function showAction(Post $post) { ... }
    }
    • blog_index
    • blog_index_paginated
    • blog_post
    http://symfony.com/blog/new-in-symfony-3-4-prefix-all-controller-route-names
    3.4

    View full-size slide

  31. Get the project root directory
    http://symfony.com/blog/new-in-symfony-3-3-a-simpler-way-to-get-the-project-root-directory
    %kernel.root_dir%/../web/
    Before
    %kernel.project_dir%/web/
    After
    3.3

    View full-size slide

  32. debug:autowiring command
    3.4
    http://symfony.com/blog/new-in-symfony-3-4-debug-autowiring-command

    View full-size slide

  33. About command
    http://symfony.com/blog/new-in-symfony-3-3-about-command
    3.3

    View full-size slide

  34. Translation: Support of XLIFF 2.0 notes

    srcLang="fr-FR" trgLang="en-US">



    new
    true
    user login


    original-content
    translated-content




    http://symfony.com/blog/new-in-symfony-3-4-added-support-for-xliff-2-0-notes
    3.4

    View full-size slide

  35. PHPUnit tests: Better code coverage reports (1/2)
    • The code coverage = executed code.
    3.4
    Before
    http://symfony.com/blog/new-in-symfony-3-4-better-code-coverage-reports

    View full-size slide

  36. PHPUnit tests: Better code coverage reports (1/2)
    • The code coverage = executed code.
    3.4
    Before
    http://symfony.com/blog/new-in-symfony-3-4-better-code-coverage-reports

    View full-size slide

  37. PHPUnit tests: Better code coverage reports (1/2)
    • The code coverage = executed code.
    3.4
    • By hand, add @covers to specify what’s covered.
    Before
    http://symfony.com/blog/new-in-symfony-3-4-better-code-coverage-reports

    View full-size slide

  38. PHPUnit tests: Better code coverage reports (1/2)
    • The code coverage = executed code.
    3.4
    • By hand, add @covers to specify what’s covered.
    Before
    http://symfony.com/blog/new-in-symfony-3-4-better-code-coverage-reports

    View full-size slide

  39. PHPUnit tests: Better code coverage reports (2/2)
    3.4





    • Guesses the test class App\Tests\FooTest exists for App\Foo.

    • Adds @covers on classes that can be guessed.

    • You can do your own Listener if you don’t follow conventions.
    http://symfony.com/blog/new-in-symfony-3-4-better-code-coverage-reports
    After

    View full-size slide

  40. New twig functions
    {% if workflow_has_marked_place(cart, 'paid') %}
    ...
    {% endif %}
    http://symfony.com/blog/new-in-symfony-3-3-workflow-improvements
    {{ workflow_marked_places(post)|join(',') }}
    Check if the given object has the given state
    Get all possible places for a given object
    3.3

    View full-size slide

  41. UserPasswordEncoderCommand improved
    3.3
    https://symfony.com/blog/new-in-symfony-3-3-securitybundle-improvements

    View full-size slide

  42. Firewall listener
    • Only executed listeners are loaded, just by upgrading!

    • And we get more info about execution of listeners:
    3.4

    View full-size slide

  43. Improved impersonation
    • In the log we get impersonator_username along with
    user provider and the impersonated username.

    • More info in the WDT
    3.4
    http://symfony.com/blog/new-in-symfony-3-4-user-impersonation-improvements

    View full-size slide

  44. Supports of Argon2i password hasher
    • You need first to:

    • either run your Symfony app with PHP 7.2

    • or install the Libsodium PHP extension on your server

    • or install libsodium-php library to your project

    • Then:
    3.4
    # app/config/security.yml
    security:
    # ...
    encoders:
    Symfony\Component\Security\Core\User\User:
    algorithm: 'argon2i'
    http://symfony.com/blog/new-in-symfony-3-4-argon2i-password-hasher

    View full-size slide

  45. use Symfony\Component\Security\Guard\AbstractGuardAuthenticator;
    class TokenAuthenticator extends AbstractGuardAuthenticator
    {
    public function getCredentials(Request $request)
    {
    if (!$token = $request->headers->get('X-AUTH-TOKEN')) {
    return null;
    }
    return ['token' => $token];
    }
    }
    class TokenAuthenticator extends AbstractGuardAuthenticator
    {
    public function supports(Request $request)
    {
    return $request->headers->has('X-AUTH-TOKEN');
    }
    public function getCredentials(Request $request)
    {
    return ['token' => $request->headers->get('X-AUTH-TOKEN')];
    }
    }
    If returns null, you’ll
    get an exception.
    Before
    After

    View full-size slide

  46. Performance improvement

    View full-size slide

  47. Routing component: Faster routing
    Lots of micro improvements made to the URL matching process

    In an app that have 900 routes from 7.5ms to 2.5ms
    Interesting
    for app
    having
    lots
    of routes
    http://symfony.com/blog/new-in-symfony-3-3-faster-routing
    3.3

    View full-size slide

  48. 2 new components

    View full-size slide

  49. WebLink component
    • Specifications implementation: HTML5 Links, Preload, Resource hints

    • Assets preloading and prefetch (HTTP 2)

    • links between resources

    • HTTP/2 pushes
    http://symfony.com/blog/new-in-symfony-3-3-weblink-component
    Symfony\Bridge\Twig\Extension\WebLinkExtension

    3.3

    View full-size slide

  50. Webpack Encore component
    http://symfony.com/blog/introducing-webpack-encore-for-asset-management
    Symfony\Bridge\Twig\Extension\WebLinkExtension
    Manages assets (replaces Assetic)

    Webpack overlay

    CSS and Javascript processing

    Helps with the fastidious configuration
    3.3

    View full-size slide

  51. https://symfony.com/doc/current/service_container/3.3-di-changes.html


    View full-size slide

  52. Let’s
    see
    5
    of them

    View full-size slide

  53. Let’s
    see
    5
    of them

    View full-size slide

  54. PSR-4 based Service Discovery
    services:
    AppBundle\:
    resource: ../src/{Controller,Command}
    http://symfony.com/blog/new-in-symfony-3-3-psr-4-based-service-discovery
    services:
    AppBundle\:
    resource: '../../src/AppBundle/*'
    exclude: '../../src/AppBundle/{AppBundle.php,Entity}'
    3.3

    View full-size slide

  55. All services are private by default
    • Inject the container and get service(s) from there bad practice

    • Hides real dependencies

    • Coupled to external config

    • Hard to test

    • Hard to review…

    • No need to have public services anymore (most of the cases).
    3.4
    http://symfony.com/blog/new-in-symfony-3-4-services-are-private-by-default

    View full-size slide

  56. Local service binding (1/2)
    3.4
    services:
    # …
    App\Some\Service1:
    $projectDir: '%kernel.project_dir%'
    App\Some\Service2:
    $projectDir: '%kernel.project_dir%'
    App\Some\Service3:
    $projectDir: '%kernel.project_dir%'
    Before After
    services:
    _defaults:
    # …
    bind:
    $projectDir: '%kernel.project_dir%'
    http://symfony.com/blog/new-in-symfony-3-4-local-service-binding

    View full-size slide

  57. Local binding (2/2)
    services:
    _defaults:
    bind:
    BarInterface: '@normal_bar_service'
    # ... special case for
    Foo:
    bind:
    BarInterface: '@special_bar_service'
    3.4
    http://symfony.com/blog/new-in-symfony-3-4-local-service-binding

    View full-size slide

  58. Environment variables: very cool processing stuff (1/3)
    • Type cast (int, bool, float & string)

    • Resolve
    3.4
    parameters:
    # roughly equivalent to "(int) getenv('DATABASE_PORT')"
    app.connection.port: '%env(int:DATABASE_PORT)%'
    parameters:
    project_dir: '/foo/bar'
    env(DB): 'sqlite://%%project_dir%%/var/data.db'
    db_dsn: '%env(resolve:DB)%'
    http://symfony.com/blog/new-in-symfony-3-4-advanced-environment-variables

    View full-size slide

  59. Environment variables: very cool processing stuff (2/3)
    • File & Json

    • Base64

    • Const
    3.4
    parameters:
    env(SECRETS_FILE): '/etc/secure/example.com/secrets.json'
    app.secrets: '%env(json:file:SECRETS_FILE)%'
    parameters:
    env(SOME_VALUE): 'NWE3OWExYzg2NmVmZWY5Y2ExODAwZjk3MWQ2ODlmM2U='
    app.some_value: '%env(base64:SOME_VALUE)%'
    parameters:
    env(NUM_ITEMS): 'App\\Entity\\BlogPost::NUM_ITEMS'
    app.num_items: '%env(constant:NUM_ITEMS)%'

    View full-size slide

  60. Environment variables: very cool processing stuff (3/3)
    3.4
    And you can create your own processor!
    http://symfony.com/blog/new-in-symfony-3-4-advanced-environment-variables

    View full-size slide

  61. Environment variables: very cool processing stuff (3/3)
    3.4
    And you can create your own processor!
    http://symfony.com/blog/new-in-symfony-3-4-advanced-environment-variables

    View full-size slide

  62. Lazy loaded commands
    All commands needed to be instantiated to be registered.
    3.4
    Before
    After
    Make it lazy loaded by adding:
    app.command.complex_command:
    # ...
    tags:
    - { name: console.command, command: app:my-command }
    http://symfony.com/blog/new-in-symfony-3-4-lazy-commands

    View full-size slide

  63. Just 2 more!

    View full-size slide

  64. Trusted proxies: trusted_proxies parameter removed
    http://symfony.com/blog/fixing-the-trusted-proxies-configuration-for-symfony-3-3
    Before
    After
    # app/config/config.yml
    framework:
    # ...
    trusted_proxies: [192.0.0.1, 10.0.0.0/8]
    // app.php
    $kernel = new AppKernel('prod', false);
    Request::setTrustedProxies(
    ['192.0.0.1', ’10.0.0.0/8’],
    Request::HEADER_FORWARDED
    );
    $request = Request::createFromGlobals();
    3.3

    View full-size slide

  65. Assets: provide request context in console
    3.4
    http://symfony.com/blog/new-in-symfony-3-4-default-request-context-for-assets
    # app/config/parameters.yml
    asset.request_context.base_path: '/subfolder'
    asset.request_context.secure: false
    asset(‘/foo/image.jpg’) /subfolder/foo/image.jpg

    View full-size slide

  66. New way of
    developing with
    4

    View full-size slide

  67. Symfony Flex
    http://symfony.com/blog/symfony-4-a-new-way-to-develop-applications

    View full-size slide

  68. Have the minimum to begin easily with a light app
    • Symfony 4 === Features of 3.4!

    • Preparing the future:

    • PHP based config for everything (to avoid having to install yaml dependency)

    http://symfony.com/blog/new-in-symfony-3-4-php-based-configuration-for-services-and-routes
    • Simpler logger

    http://symfony.com/blog/new-in-symfony-3-4-minimalist-psr-3-logger
    • …

    View full-size slide

  69. About Bundle Inheritance: It’s gone!
    • No more bundles in Symfony 4

    • The inheritance for controllers, routes, templates, services… is still
    possible!

    • Use solutions that doesn’t involve bundles
    http://symfony.com/blog/new-in-symfony-3-4-deprecated-bundle-inheritance

    View full-size slide

  70. Let’s help to get there!
    • Please take time to test the version 4.

    • Documentation on Symfony 4 evolutions needs to be completed.

    • Bundles needs to become Symfony 4 compatible (have a at the Google
    sheet).

    • Create recipes for these bundles.
    https://symfony.com/blog/helping-prepare-for-symfony-4-bundle-support
    4.0

    View full-size slide

  71. Give help: Make a bundle compatible with Symfony 4
    • First steps:

    • In composer.json file, for any symfony/* lines, add |^4.0 to it.

    • In the .travis.yml file, make it test against Symfony 4.

    • Then:

    • Submit your pull request.

    • See if there are failures. To fix them
    https://symfony.com/blog/helping-prepare-for-symfony-4-bundle-support
    4.0

    View full-size slide

  72. https://github.com/symfony/symfony/blob/master/UPGRADE-4.0.md

    View full-size slide

  73. @catlannister
    Get more involved to get to
    learn more! ♥

    View full-size slide

  74. @catlannister
    Get more involved to get to
    learn more! ♥

    View full-size slide