@@ -191,39 +191,30 @@ provide a callback function to dynamically generate suggestions::
191191 // This function is called whenever the input changes and new
192192 // suggestions are needed.
193193 $callback = function (string $input): array {
194- // Strip any characters from the last slash to the end of the
195- // string - this is considered a complete path and should populate
196- // our autocomplete suggestions.
197- $inputPath = preg_replace(
198- '%(/|^)[^/]*$%',
199- '$1',
200- $input
201- );
202-
203- // All suggestions should start with the input the user has already
204- // provided (existing path), followed in this case by the contents
205- // of the referenced directory. Some suggestions may be ignored
206- // because they don't match the full string provided by the user,
207- // but the autocomplete helper will take care of that for us.
208- return array_map(
209- function ($suggestion) use ($inputPath) {
210- return $inputPath . $suggestion;
211- },
212- @scandir($inputPath === '' ? '.' : $inputPath) ?: []
213- );
194+ // Strip any characters from the last slash to the end of the string
195+ // to keep only the last directory and generate suggestions for it
196+ $inputPath = preg_replace('%(/|^)[^/]*$%', '$1', $userInput);
197+ $inputPath = '' === $inputPath ? '.' : $inputPath;
198+
199+ // CAUTION - this example code allows unrestricted access to the
200+ // entire filesystem. In real applications, restrict the directories
201+ // where files and dirs can be found
202+ $foundFilesAndDirs = @scandir($inputPath) ?: [];
203+
204+ return array_map(function ($dirOrFile) use ($inputPath) {
205+ return $inputPath.$dirOrFile;
206+ }, $foundFilesAndDirs);
214207 };
215208
216209 $question = new Question('Please provide the full path of a file to parse');
217210 $question->setAutocompleterCallback($callback);
218211
219- $filePath = $this->output->askQuestion( $question);
212+ $filePath = $helper->ask($input, $output, $question);
220213 }
221214
222- ..caution ::
215+ ..versionadded :: 4.3
223216
224- This example code allows unrestricted access to the host filesystem, and
225- should only ever be used in a local context, such as in a script being
226- manually invoked from the command line on a server you control.
217+ The ``setAutocompleterCallback() `` method was introduced in Symfony 4.3.
227218
228219Hiding the User's Response
229220~~~~~~~~~~~~~~~~~~~~~~~~~~