Just a short overview of what I did to update my symfony applications to 5.1
First, I updated my composer.json according to the instructions here
Changed all 4.4.*
lines to 5.1.*
Change the extra.symfony.require line in composer.json
"extra": {
"symfony": {
"require": "5.1.*"
}
}
Run the update.
composer update "symfony/*" --with-all-dependencies
During the update, I ran into a version error with the symfony/web-server-bundle package.
Doing some research, It looks like we can now use symfony's cli tool to start local servers, so I simply removed this package and re-ran the update command.
composer remove symfony/web-server-bundle
composer update "symfony/*" --with-all-dependencies
Reloading the application, I started getting errors with my config/routes/dev/twig.yaml
file, specifically about the line @TwigBundle/Resources/config/routing/errors.xml
To fix this
framework.yml
# config/routes/dev/framework.yaml
_errors:
resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
prefix: /_error
I then ran into the error
Fatal error: Uncaught Error: Class 'Symfony\Component\Debug\Debug' not found in public/index.php:12 Stack trace: #0 {main} thrown in public/index.php on line 12
To fix this
Debug
class
// public/index.php
...
// This used to be "use Symfony\Component\Debug\Debug;"
use Symfony\Component\ErrorHandler\Debug;
...
This is not required but It is best to move away from depreciated code.
Update my configureRoutes()
method in Kernel.php
to use the new RoutingConfigurator
class.
// old src/Kernel.php
use Symfony\Component\Routing\RouteCollectionBuilder;
..
protected function configureRoutes(RouteCollectionBuilder $routes): void
{
$confDir = $this->getProjectDir().'/config';
$routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
}
// new src/Kernel.php
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
..
protected function configureRoutes(RoutingConfigurator $routes): void
{
$routes->import('../config/{routes}/'.$this->environment.'/*.yaml');
$routes->import('../config/{routes}/*.yaml');
if (file_exists(\dirname(__DIR__).'/config/routes.yaml')) {
$routes->import('../config/{routes}.yaml');
}
else {
$path = \dirname(__DIR__).'/config/routes.php';
(require $path)($routes->withPath($path), $this);
}
}
— and Voila!
My application was updated to the latest stable version without any depreciations!