Programmation PHP/Migration de Symfony 5 à 6
La liste des dépréciations cassantes en Symfony 6 est disponible dans le Profiler d'un projet Symfony 5.4, à la section logs.
YAMLModifier
- Dans
security.firewalls.main
, remplaceranonymous: true
parlazy: true
. Erreur sinon : Invalid firewall "main": user provider "users_in_memory" not found. - Dans
framework.session
, remplacerstorage_id: session.storage.mock_file
parstorage_factory_id: session.storage.factory.mock_file
. Erreur sinon : Unrecognized option "storage_id" under "framework.session".
PHPModifier
- Remplacer les injections de
SessionInterface
parRequestStack
, et appeler sa méthodegetSession()
. Erreur sinon : "Cannot autowire service... SessionInterface".
RectorModifier
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
TwigModifier
- Remplacer
controller(App\\Controller\\HomeController:headerAction)
par(App\\Controller\\HomeController::headerAction)
. Sinon, prendre le nom du contrôleur avec sa méthode visible dansbin/console debug:router --show-controllers
en échappant ses antislashs. Erreur sinon : The controller for URI "/_fragment" is not callable.