New in Symfony 7.1: Commands Improvements
May 20, 2024 • Published by Javier Eguiluz
Symfony 7.1 is backed by:
Symfony includes many commands to perform common operations in your applications. In Symfony 7.1, we are improving some commands with new options and features.
New Command to Reveal Secrets
Symfony provides a feature to manage secrets that encrypts and stores the
given values in a secure vault. When developing applications, it might be
useful to see the original plain text value of a secret. That's why in
Symfony 7.1 we've introduced a new secrets:reveal
command:
1 2 3
# the command outputs the plain text value of the database password
# (e.g. you can pipe this output to another command)
$ php bin/console secrets:reveal DATABASE_PASSWORD
Improved the debug:serializer
Command
The debug:serializer
command helps you find issues when using the
Serializer component. In Symfony 7.1 we've improved it to also display the
serialized path:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
$ php bin/console debug:serializer 'App\Entity\Book'
App\Entity\Book
---------------
+----------+------------------------------------------------------------+
| Property | Options |
+----------+------------------------------------------------------------+
| name | ... |
| isbn | |
| | ... |
| | "serializedName" => null, |
| | "serializedPath" => [data][isbn], |
| ... | ... |
+----------+------------------------------------------------------------+
Improved messenger:consume
Command
When consuming messages of the Messenger component, you run the messenger:consume
command and pass the name of the receiver or service:
1
$ php bin/console messenger:consume async
In Symfony 7.1, we're adding a new --all
option so you can consume messages
from all the available receivers:
1
$ php bin/console messenger:consume --all
Improved twig:lint
Command
The lint:twig
command checks that your Twig templates don't have any syntax
errors. It's useful to run it before deploying your application to production
(e.g. in your continuous integration server).
If you have some special Twig templates (e.g. related to some data collector)
you may get false positives when linting them. That's why in Symfony 7.1 we're
adding a --excludes
option so you can ignore certain directories:
1
$ php bin/console lint:twig templates/ --excludes=data_collector/ --excludes=some_dev_tool/
Getting all Command Tokens
In Symfony 7.1 we also added a getRawTokens()
method to the
ArgvInput. This method allows to
fetch the raw input that was passed to the command, including all options and
arguments. This is useful to parse the input yourself or to pass the entire input
to another command.
For example, if you run this command:
1
$ php bin/console app:my-command foo --bar --baz=3 --qux=value1 --qux=value2
This would be the output of the new method:
1 2 3 4 5 6 7 8 9
$tokens = $input->getRawTokens();
// $tokens = ['app:my-command', 'foo', '--bar', '--baz=3', '--qux=value1', '--qux=value2'];
// pass true as argument to not include the original command name
$tokens = $input->getRawTokens(true);
// $tokens = ['foo', '--bar', '--baz=3', '--qux=value1', '--qux=value2'];
// pass the raw input to any other command (from Symfony or the operating system)
$process = new Process(['app:other-command', ...$input->getRawTokens(true)]);
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
Typo in the section title twig:lint instead of lint:twig?