hoaproject/Console — pull request #11 by Hywan (2014-03-10 14:53:26+00:00)
Title: New autocompleters: aggregate and path

# Introduction

Firstly, an example:
```php
setAutocompleter(
new Hoa\Console\Readline\Autocompleter\Aggregate([
new Hoa\Console\Readline\Autocompleter\Path(),
new Hoa\Console\Readline\Autocompleter\Word(
get_defined_functions()['internal']
)
])
);

do {

$rl = $readline->readLine('> ');
echo '< ', $rl, "\n";

} while(true);
```
will produce:
![path_autocompleter](https://f.cloud.github.com/assets/946104/2374582/ae5c5452-a861-11e3-9eea-9c9a7184fe19.gif)
This example is a mix between the `Path` and `Word` autocompleters, gathered into the `Aggregate` autocompleter.

# “Regression”

The `Hoa\Console\Readline\Autocompleter\Autocompleter::complete` method sees its only argument passed by-reference (previously `$prefix`, now `&$prefix`). The impact is not important since the update is really easy and without any trivial side-effect. Moreover, this only concerns the readline when working on a regular STDIN, not a critical part of any applications.

# `Aggregate`

The order of autocompleters is important. If an autocompleter is not able to recognize a word, we try another one. If it recognizes, but not able to autocomplete, then we try another one. Does it seem legit enough for you? We can go further and propose different menus for each autocompleters, but it starts to be difficult ;-) (and the code is so clean for now… :-]).

Pro tips: the `getWordDefinition` returns `.*` to get everything from the beginning of the line to the cursor.

# `Path`

The `Path` autocompleter is able to autocomplete paths. I'm not sure about the word definition for a path. Can someone review it?
It autocompletes based on a list of `SplFileInfo` instances (do we need to test with an `instanceof` in the code?) through an iterator. The iterator can be very sophisticated, e.g. [`Hoa\File\Finder`](https://github.com/hoaproject/File/blob/master/Finder.php), in order to select a subset of files based on their group, size, *x* time etc. However, a default iterator factory based on `DirectoryIterator` is provided. The factory takes the form of a simple closure.
By default, the root is set to the current working directory. If we would like to work with absolute paths, we have to set the root to `/`.

Thoughts?