Programmation PHP/Migration de Symfony 5 à 6

Un livre de Wikilivres.

La liste des dépréciations cassantes en Symfony 6 est disponible dans le Profiler d'un projet Symfony 5.4, à la section logs.

YAML[modifier | modifier le wikicode]

  • Dans security.firewalls.main, remplacer anonymous: true par lazy: true. Erreur sinon : Invalid firewall "main": user provider "users_in_memory" not found.
  • Dans framework.session, remplacer storage_id: session.storage.mock_file par storage_factory_id: session.storage.factory.mock_file. Erreur sinon : Unrecognized option "storage_id" under "framework.session".

PHP[modifier | modifier le wikicode]

  • Remplacer les injections de SessionInterface par RequestStack, et appeler sa méthode getSession(). Erreur sinon : "Cannot autowire service... SessionInterface".

Rector[modifier | modifier le wikicode]

Facultativement, on peut utiliser Rector pour convertir automatiquement les annotations en attributs[1].

Installation :

composer require rector/rector --dev
vendor/bin/rector init

Ensuite, il suffit de mettre ceci dans rector.php :

   $rectorConfig->sets([
       LevelSetList::UP_TO_PHP_82,
       DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
       SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES,
       SensiolabsSetList::FRAMEWORK_EXTRA_61,
   ]);

Puis de lancer :

vendor/bin/rector process src

Twig[modifier | modifier le wikicode]

  • Remplacer controller(App\\Controller\\HomeController:headerAction) par (App\\Controller\\HomeController::headerAction). Sinon, prendre le nom du contrôleur avec sa méthode visible dans bin/console debug:router --show-controllers en échappant ses antislashs. Erreur sinon : The controller for URI "/_fragment" is not callable.

Références[modifier | modifier le wikicode]