[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. 13.
  2. 15.

    The Core team: Thank you so much guys! # Bernhard

    Schussek (@webmozart) Abdellatif Ait Boudad (@aitboudad)
  3. 19.
  4. 20.
  5. 22.

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

    which version What’s that about?
  6. 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
  7. 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
  8. 26.
  9. 27.
  10. 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
  11. 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
  12. 35.

    3.3

  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 46.
  21. 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
  22. 48.
  23. 50.

    Firewall listener • Only executed listeners are loaded, just by

    upgrading! • And we get more info about execution of listeners: 3.4
  24. 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
  25. 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
  26. 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
  27. 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
  28. 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
  29. 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
  30. 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
  31. 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
  32. 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
  33. 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)%'
  34. 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
  35. 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
  36. 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
  37. 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
  38. 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
  39. 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 • …
  40. 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
  41. 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
  42. 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
  43. 81.
  44. 82.
  45. 83.
  46. 84.
  47. 85.