Symfony 8.1, the big CLI update

php dev.to

When I saw the change list in the Symfony 8.1 beta 1 announcement The first thing that I noticed is that there are a lot of Console and CLI related changes.
The first few "New in Symfony 8.1" posts confirm this.

Added the TUI component

I have written about the TUI component but now it is a part of the framework.

The quick explanation for the people who are unaware of the component.
Think Claude code/OpenCode, Midnight commander/Yazi, basically everything in Awesome TUI's you can now make in PHP.

HTTP-less application

While this change goes further than only Console, it streamlines creating commands with multiple dependencies or config values.

Up till now when you didn't want the HTTP functionality of the Kernel, you needed to inject the services explicitly or create your own container.
While they are still options, adding a HTTP-less Kernel causes less friction because of the familiarity with the web kernel.

Input improvements

Argument resolvers in Console is a big one.
This brings command arguments on the same level as the Controller arguments.
Method based commands makes it possible to group commands like you would with a Controller. While it gives you more options the argument resolvers addition allows to inject services as an method argument so there is less need to use constructor dependency injection.

I'm sure a future article in the new series will be the image support for QuestionHelper and #Ask.
This will only work on terminals that support image rendering. But having the distinction between images and other files gives you more options.

It will be possible to add validation constraints to QuestionHelper and #Ask and #MapInput.
It is already possible to add a Validator, but the using the constraints makes the argument a lot cleaner.

Adding any type as a default for an argument is going bring more type safety to command arguments. The current restriction felt arbitrary.

Exposing the raw input values is great when the command exposes another command you want to limit.

Preventing incompatible mode flags might be a less important change after this list, but I think it is an important one.

Miscellaneous

Added OSC progress state. You probably seen the progressbar on top of the page when you are reading an article on a website. This is also possible in the terminal. I didn't know that, but it is nice when you scrolled up in the terminal.

The partial command name list is now alphabetical. Having order is always better than chaos.

Conclusion

Of course the release contains other features, like DeepCloner, but the main focus seems to be on CLI features.

And with the HTTP-less application the framework is moving from a web focused framework to a general use framework. Where the TUI component showed PHP CLI code isn't only for basic commands, Symfony 8.1 shows it can do more than only websites. It was already possible when you brought your own tools, but now you can do it using Symfony conventions.

This is going to be a great release!

Source: dev.to

arrow_back Back to Tutorials