In addition to the main features announced in previous posts of this series, Symfony 8.2 includes many smaller changes that make day-to-day work easier. This post highlights a third batch of them.
Shortcuts for Template and Redirect Routes
Symfony can render a template or redirect directly from a route, without
creating a controller. However, the route had to set the FQCN of a built-in
controller and pass everything else in defaults. Symfony 8.2 adds three
shortcuts for these routes: template, redirect_to_route and redirect_to:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# config/routes.yaml
faq:
path: /faq
- controller: Symfony\Bundle\FrameworkBundle\Controller\TemplateController
- defaults:
- template: 'pages/faq.html.twig'
- maxAge: 300
+ template: 'pages/faq.html.twig'
+ defaults: { maxAge: 300 }
legacy_docs:
path: /documentation/{page}
- controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController
- defaults:
- route: doc_page
- permanent: true
+ redirect_to_route: doc_page
+ defaults: { permanent: true }
status:
path: /status
- controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController
- defaults:
- path: 'https://status.example.com'
+ redirect_to: 'https://status.example.com'
The same shortcuts are available in PHP routes as template(),
redirectToRoute() and redirectTo().
The other options of those controllers (maxAge, context, permanent,
keepQueryParams, etc.) are still defined in defaults. The shortcuts are
resolved when routes are loaded, so they add no overhead at runtime and
debug:router shows the real controller of each route.
New debug:autoconfiguration Command
Thanks to autoconfiguration, implementing an interface or adding an attribute
is enough to turn a class into a command, an event listener, a Twig extension,
etc. The downside is that it's hard to know which classes, interfaces and
attributes trigger it. Symfony 8.2 adds a debug:autoconfiguration command
that lists them, with the tags, method calls and bindings that each one adds.
Pass an optional argument to filter the results:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
$ php bin/console debug:autoconfiguration console
Autoconfiguration
=================
(only showing rules matching console)
An autoconfigured service gets the configuration listed under each class
or interface that its class extends or implements.
Symfony\Component\Console\Command\Command
Base class for all commands.
tag console.command
tag console.command.service_arguments
An autoconfigured service is also configured by the following attributes,
when they are used on its class or on one of its members.
Symfony\Component\Console\Attribute\AsCommand
Service tag to autoconfigure commands.
// ...
Unused Environment Variables
As applications evolve, .env files accumulate variables that nothing reads
anymore. In Symfony 8.2, the debug:container --env-vars command adds a
Used column and also lists the variables defined in your .env files
that the container never references:
1 2 3 4 5 6 7 8 9
$ php bin/console debug:container --env-vars
--------------- --------------- --------------- ------
Name Default value Real value Used
--------------- --------------- --------------- ------
APP_SECRET n/a "471a..." yes
DATABASE_URL n/a "postgres..." yes
OLD_API_TOKEN n/a "abc123" no
--------------- --------------- --------------- ------
A variable is used when some %env(...)% placeholder reads it, with or
without processors. Defining only a default value for it (with a
env(OLD_API_TOKEN) parameter) doesn't count as using it.
Listing All Event Dispatchers
The debug:event-dispatcher command provides a --dispatcher option to
show the listeners of a specific dispatcher, which is useful for example because
each security firewall has its own. The problem was knowing the names of those
dispatchers. The new --dispatchers option lists them all:
1 2 3 4 5 6 7 8 9 10 11 12
$ php bin/console debug:event-dispatcher --dispatchers
---------------------------------
Event Dispatcher
---------------------------------
event_dispatcher
security.event_dispatcher.main
security.event_dispatcher.api
security.event_dispatcher.admin
---------------------------------
$ php bin/console debug:event-dispatcher --dispatcher=security.event_dispatcher.api
Routing Information in debug:messenger
The debug:messenger command lists the messages of each bus and their
handlers, but it didn't tell you where those messages are sent. In Symfony 8.2,
each message shows a routed to line with its transports, and a new
Transports section shows the routing rules and the failure transport of
each transport:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
$ php bin/console debug:messenger
// ...
Transports
----------
[INFO] TransportNamesStamp can override this routing at dispatch time.
async
App\Message\OrderPlaced
App\Message\Billing\* (namespace)
App\Message\AuditableInterface (interface, matches implementers)
App\Message\SendNewsletter (from #[AsMessage])
failed messages are routed to failed
failed
* (fallback for messages with no other route)
The new --message option shows only the handlers, transports and rules that
apply to the given message class. It resolves them like the bus does when
dispatching the message: parent classes, interfaces, namespace wildcards, the
* fallback and #[AsMessage] attributes:
1
$ php bin/console debug:messenger --message='App\Message\OrderPlaced'
Listing the Middleware of Each Bus
The middleware stack of each bus is built when compiling the container (default
middleware, your own middleware, etc.), so the only way to see the result was to
dig through debug:container. In Symfony 8.2, the debug:messenger
command adds a --middleware option that lists them in the order in which
they are called:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
$ php bin/console debug:messenger --middleware
messenger.bus.default
---------------------
The following middleware are called, in this order:
----------------------------------------------------------------------
messenger.bus.default.middleware.add_bus_name_stamp_middleware
Symfony\Component\Messenger\Middleware\AddBusNameStampMiddleware
Adds the BusNameStamp to the bus.
messenger.bus.default.middleware.send_message
Symfony\Component\Messenger\Middleware\SendMessageMiddleware
messenger.bus.default.middleware.handle_message
Symfony\Component\Messenger\Middleware\HandleMessageMiddleware
----------------------------------------------------------------------
// ...
Time Until the Next Scheduler Run
The debug:scheduler command shows the date of the next run of each recurring
message. That's hard to read at a glance, especially when schedules use several
timezones. Symfony 8.2 renames that column to Next Run On and adds a
Next Run In column with the time left until that run:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
$ php bin/console debug:scheduler
Scheduler
=========
default
-------
----------------- ------------------------ --------------------------------- --------------------
Trigger Provider Next Run On Next Run In
----------------- ------------------------ --------------------------------- --------------------
every 5 minutes App\Message\SyncStock Mon, 18 May 2026 07:00:08 +0000 5 min, 3 s
0 15 * * * App\Message\SendDigest Mon, 18 May 2026 15:00:00 +0000 8 h, 4 min, 55 s
0 3 * * * App\Message\PurgeCarts Tue, 19 May 2026 03:00:00 +0930 10 h, 34 min, 55 s
----------------- ------------------------ --------------------------------- --------------------
Profiler URL in Logs
When you work on an API, a webhook or any other request that doesn't display
the web debug toolbar, finding its profile means looking up the token in the
response headers or searching the profiler. In Symfony 8.2, the profiler logs
the URL of the profile of each request, at the debug level and on the
profiler channel, so you can open it straight from your terminal or log
viewer:
1
[Application] May 21 17:05:15 |DEBUG | PROFIL See profiler at https://127.0.0.1:8000/_profiler/92ff6e
Reporting Attributes with a Missing Import
PHP only loads the class of an attribute when something instantiates it. If you
forget its use statement, PHP resolves the attribute name in the current
namespace, where no such class exists, and the attribute silently does nothing:
1 2 3 4 5 6 7 8 9 10
// src/Entity/Patient.php
namespace App\Entity;
// missing: use Symfony\Component\Validator\Constraints as Assert;
class Patient
{
#[Assert\NotBlank]
public string $phone;
}
In Symfony 8.2, the DebugClassLoader (which is enabled in debug mode) checks
the attributes of classes, constants, properties, methods and parameters, and
reports those that point to a non-existent class in the namespace of the class
that uses them, or below it:
1 2
Attribute "App\Entity\Assert\NotBlank" used on "App\Entity\Patient::$phone"
does not exist. Did you forget a "use" statement?
Attributes of other namespaces are not checked, because they may belong to a package that is not installed on purpose.
This is the last post of the New in Symfony 8.2 series. We hope you enjoyed it and that you are now ready to upgrade your applications to Symfony 8.2.