How to handle Symfony 5.3 deprecations?
Asked Answered
R

1

6

After upgrading Symfony from 4.4 -> 5.3 i get some deprecations which I cant located to solve.

Here are 3 deprecations as example:

User Deprecated: Since symfony/framework-bundle 5.3: The "session.storage.factory.service" service is deprecated, use "session.storage.factory.native", "session.storage.factory.php_bridge" or "session.storage.factory.mock_file" instead.
User Deprecated: Since symfony/security-core 5.3: The "Symfony\Component\Security\Core\Event\AuthenticationFailureEvent" class is deprecated, use "Symfony\Component\Security\Http\Event\LoginFailureEvent"
User Deprecated: Since symfony/http-kernel 5.3: "Symfony\Component\HttpKernel\Event\KernelEvent::isMasterRequest()" is deprecated, use "isMainRequest()" instead.

It's only 3 of more as 30 deprecations. My question is: How is the correct way to solve this warnings. (I need to solve, because I have many Requests/minute and every time this warnings get wrote in dev.log - this file is exploding)

I want to start with the 3rd warning. Here is the trace:

../vendor/symfony/http-kernel/Event/KernelEvent.php:88 {▶}
../vendor/symfony/web-link/EventListener/AddLinkHeaderListener.php:41 {▶}
../vendor/symfony/event-dispatcher/Debug/WrappedListener.php:117 {▶}
../vendor/symfony/event-dispatcher/EventDispatcher.php:230 {▶}
../vendor/symfony/event-dispatcher/EventDispatcher.php:59 {▶}
../vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:151 {▶}
../vendor/symfony/http-kernel/HttpKernel.php:190 {▶}
../vendor/symfony/http-kernel/HttpKernel.php:178 {▶}
../vendor/symfony/http-kernel/HttpKernel.php:79 {▶}
../vendor/symfony/http-kernel/EventListener/ErrorListener.php:60 {▶}
../vendor/symfony/event-dispatcher/Debug/WrappedListener.php:117 {▶}
../vendor/symfony/event-dispatcher/EventDispatcher.php:230 {▶}
../vendor/symfony/event-dispatcher/EventDispatcher.php:59 {▶}
../vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:151 {▶}
../vendor/symfony/http-kernel/HttpKernel.php:218 {▶}
../vendor/symfony/http-kernel/HttpKernel.php:90 {▶}
../vendor/symfony/http-kernel/Kernel.php:199 {▶}
../public/index.php:25 {▶}

All files comes directly from symfony, nothing from me, thats why my question where to start to solve this warnings.

Rape answered 21/8, 2021 at 6:30 Comment(6)
Just for context... Do you mean that you didn't see the notices until the upgrade was finished and deployed to live? Do you want to prevent them from getting logged as opposed to upgrading to the replacement features?Academic
Before Upgrade was finished there was no deprecations. Now i get many (its normal) but i have to solve the deprecations for later upgrading. in V6 many of these deprecations would be errors then, no warnings like yet.Rape
I think you have an issue with the way you upgraded and you have out of date Symfony components. I did a search under vendor/symfony for isMasterRequest and the only hits I got involved the actual RequestEvent object. In other words, everything that used to use it has been changed to isMainRequest. I had suspected a third party issue or even your app code but your stack trace shows only symfony stuff.Wandy
Just to follow up, do you get a 5.3.x version for 'composer show symfony/web-link'?Wandy
Most of the deprecations are fixed now. I want to write something about this tomorrow evening (nightshift ;) ) There are many important things to now by upgrading this big step. U have to change some core files which was not updated by upgrading.Rape
What have you tried so far? Where are you stuck? Maybe these are trigged by outdated configuration? Do you still see them after syncing the Flex recipes?Lenwood
R
12

Ok, now im deprecation free but there are some things to now after upgrading from 4.4 to 5.3

To find all warnings I created a new symfony project to compare different files

  1. KernelEvent::isMasterRequest()" is deprecated, use "isMainRequest()

    take a look into your file src/Kernel.php - there u can find the deprecated method

  2. The "session.storage.factory.service" service is deprecated

    open your framework.yaml and compare with the following code. Maybe it could help you:

    session:
      handler_id: session.handler.native_file
      save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'
      # 2 Days lifetime (172800 seconds)
      cookie_lifetime: 172800
      cookie_secure: 'auto'
      cookie_samesite: 'lax'
      #storage_id: session.storage.mock_file
      storage_factory_id: session.storage.factory.native  
    
  3. The "Symfony\Component\HttpFoundation\Session\SessionInterface are deprecated

    I found this in my old LoginAuthenticator ('App\Security...' by default). Replace it with use Symfony\Component\HttpFoundation\RequestStack; Now u can inject it and make it available as $this->requestStack and then change all $this->session with $this->requestStack->getSession() Done!

  4. Most of all other deprecations are in connection with the new authenticator-based system which was introduced in symfony 5.1. U have to edit your security.yaml. I show you my changes:

    security:
        enable_authenticator_manager: true
        password_hashers:
           Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
        providers:
            users_in_memory: { memory: null }
            app_user_provider:
               entity:
                 class: App\Entity\User
                 property: username
        firewalls:
            main: 
                # default stuff
                provider: app_user_provider
                http_basic: ~
                form_login:
                    default_target_path: mission 
                    use_referer: true
                    target_path_parameter: redirect_url
                    login_path: login
                    check_path: login
                entry_point: form_login
                access_denied_handler: App\Security\AccessDeniedHandler
                custom_authenticator: App\Security\CustomAuthenticator
    

    To make the auth warnings more understandable create a new CustomAuthenticator with the maker bundle. Now you can compare your old Authenticator with the new one and put the new methods into your old Authenticator. There are some changes that you need to make.

Thats it. Most of deprecations should solve now.

Rape answered 24/8, 2021 at 17:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.