[SymfonyCon Cluj] A year of Symfony

34ade09dd3d11004ca8ee4174fd3d6a2?s=47 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.

34ade09dd3d11004ca8ee4174fd3d6a2?s=128

Sarah KHALIL

November 17, 2017
Tweet

Transcript

  1. @saro0h A year of Sarah Khalil

  2. A little disclaimer

  3. A little disclaimer E_TOO_MANY_NEWS

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

  5. A little disclaimer E_TOO_MANY_NEWS You won’t remember everything Relax Enjoy

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

    as much as you can " Mission: Adopt Symfony 4!
  7. Between decem ber 2016 & m arch 2017 https://speakerdeck.com/saro0h/symfonylive-paris-quoi-de-neuf-depuis-1-an

  8. What’s the plan?

  9. What’s the plan? Community

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

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

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

    of 4
  13. Community

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

    (@ogizanagi)
  15. The Core team: Thank you so much guys! # Bernhard

    Schussek (@webmozart) Abdellatif Ait Boudad (@aitboudad)
  16. Pull Requests & Issues since last SymfonyCon

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

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

    $ $ $ $ " %
  19. None
  20. None
  21. Let’s see some code! 3.3 3.4

  22. x.x Link to have a look later Some explanations Since

    which version What’s that about?
  23. Form and Validator components

  24. 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
  25. 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
  26. None
  27. None
  28. 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
  29. 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
  30. Validation improvement: new panel (1/2) 3.4 http://symfony.com/blog/new-in-symfony-3-4-validator-information-in-the-symfony-profiler

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

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

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

  34. Developer eXperience improvements

  35. 3.3

  36. 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
  37. 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
  38. debug:autowiring command 3.4 http://symfony.com/blog/new-in-symfony-3-4-debug-autowiring-command

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

  40. Translation: Support of XLIFF 2.0 notes <?xml version="1.0" encoding="utf-8"?> <xliff

    xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="fr-FR" trgLang="en-US"> <file id="messages.en_US"> <unit id="LCa0a2j"> <notes> <note category="state">new</note> <note category="approved">true</note> <note category="section" priority="1">user login</note> </notes> <segment> <source>original-content</source> <target>translated-content</target> </segment> </unit> </file> </xliff> http://symfony.com/blog/new-in-symfony-3-4-added-support-for-xliff-2-0-notes 3.4
  41. 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
  42. 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
  43. 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
  44. 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
  45. PHPUnit tests: Better code coverage reports (2/2) 3.4 <!-- phpunit.xml

    —> <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.0/phpunit.xsd" > <!-- ... --> <listeners> <listener class="Symfony\Bridge\PhpUnit\CoverageListener" /> </listeners> </phpunit> • 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
  46. Workflow

  47. 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
  48. Security

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

  50. Firewall listener • Only executed listeners are loaded, just by

    upgrading! • And we get more info about execution of listeners: 3.4
  51. 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
  52. 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
  53. 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
  54. Performance improvement

  55. 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
  56. 2 new components

  57. 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
  58. 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
  59. https://symfony.com/doc/current/service_container/3.3-di-changes.html

  60. Let’s see 5 of them

  61. Let’s see 5 of them

  62. 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
  63. 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
  64. 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
  65. 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
  66. 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
  67. 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)%'
  68. 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
  69. 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
  70. 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
  71. Just 2 more!

  72. 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
  73. 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
  74. New way of developing with 4

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

  76. 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 • …
  77. 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
  78. 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
  79. 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
  80. https://github.com/symfony/symfony/blob/master/UPGRADE-4.0.md

  81. None
  82. None
  83. None
  84. None
  85. None
  86. @catlannister Get more involved to get to learn more! ♥

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