April 10, 2019 Javier Eguiluz

The Console component provides an utility to autocomplete the answers to questions created with the Question Helper. This is used for example to autocomplete classes and entities in the MakerBundle to boost your productivity.

However, autocomplete requires to know all the possible suggestions beforehand. This is impossible if the suggestions depend on the user input and not practical if the completion is highly dynamic (e.g. when autocompleting the contents of directories).

In Symfony 4.3 we improved this feature with a new method called setAutocompleterCallback() that allows to use a callback function to generate the autocomplete suggestions dynamically. For example, this example shows how to autocomplete the user input with valid directory contents: