This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Console/Tests
Fabien Potencier 4e1244ecdb feature #30997 [Console] Add callback support to Console\Question autocompleter (Mikkel Paulson)
This PR was merged into the 4.3-dev branch.

Discussion
----------

[Console] Add callback support to Console\Question autocompleter

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | minor edge case, see below
| Deprecations? | no
| Tests pass?   | yes (with expanded coverage)
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | symfony/symfony-docs#11349

Autocompletion is a useful feature, but it's not always possible to anticipate every input the user could provide in advance. For instance, if we're allowing the user to input a path to a file, it's not practical to populate an array with every file and directory in the filesystem, but we can easily build a callback function that populates its suggestions based on the path already inputted.

This change replaces the autocomplete logic that accepts an array of suggestions with an architecture that uses a callback function to populate suggestions in real time as the user provides input.

The first commit adds a test class covering all methods of the `Question` object, while the second commit modifies the `Question` object to accept and store a callback function. The existing `[gs]etAutocompleterValues()` methods are preserved, but instead of being referenced directly from the `QuestionHelper`, they create and call their own callbacks to emulate the current behaviour.

There is one edge case that is changed, as documented in the test: when a `Traversable` object is passed to `setAutocompleterValues()`, the return value of `getAutocompleterValues()` will be the unpacked (array) form of that object rather than the object itself. The unpacking is done lazily and cached on the callback function.

Commits
-------

caad562c11 [Console] Add callback support to Console\Question autocompleter
2019-04-08 17:52:58 +02:00
..
Command Merge branch '4.2' into short-array-master 2019-01-16 22:53:39 +01:00
CommandLoader switched array() to [] 2019-01-16 10:39:14 +01:00
DependencyInjection fixed CS 2019-01-16 19:35:49 +01:00
Descriptor switched array() to [] 2019-01-16 10:39:14 +01:00
EventListener switched array() to [] 2019-01-16 10:39:14 +01:00
Fixtures fixed CS 2019-01-16 19:35:49 +01:00
Formatter Merge branch '4.2' 2019-04-08 17:16:54 +02:00
Helper feature #30997 [Console] Add callback support to Console\Question autocompleter (Mikkel Paulson) 2019-04-08 17:52:58 +02:00
Input Merge branch '3.4' into 4.2 2019-02-23 16:17:42 +01:00
Logger switched array() to [] 2019-01-16 10:39:14 +01:00
Output fixed CS 2019-01-16 19:35:49 +01:00
Question [Console] Add callback support to Console\Question autocompleter 2019-04-08 17:48:46 +02:00
Style fix resetting the COLUMN environment variable 2019-04-08 11:29:13 +02:00
Tester Merge branch '3.4' into 4.2 2019-02-19 19:28:05 +01:00
ApplicationTest.php Merge branch '3.4' into 4.2 2019-04-08 13:36:05 +02:00
TerminalTest.php fix resetting the COLUMN environment variable 2019-04-08 11:29:13 +02:00