gnugat/redaktilo — pull request #5 by gnugat (2014-05-12 18:50:33+00:00)
Title: [WIP] SearchEngine

This PR offers both a refactoring and a feature.

`Editor` now depends on `SearchEngine` which contains `SearchStrategy`. This allow to extend the search behavior without having to modify `Editor`'s API.
The line matching mechanism has been moved to `LineSearchStrategy`, and a new kind of search has been added: `LineNumberSearchStrategy`.

I'm open to any code reviews/remarks/propositions.
Thanks to @WouterJ for all his help!

Here's a small code sample:

```php
registerStrategy($lineSearchStrategy);

$lineNumberSearchStrategy = new LineNumberSearchStrategy();
$searchEngine->registerStrategy($lineNumberSearchStrategy);

$symfonyFilesystem = new SymfonyFilesystem();
$filesystem = new Filesystem($symfonyFilesystem);
$editor = new Editor($filesystem, $searchEngine);

// Things that haven't change
$file = $editor->open('/tmp/monty.py');
$editor->jumpDownTo($file, 'Hello world');
$editor->jumpUpTo($file, 'I like bacon');
$editor->has($file, "Oh, a gahp. A gahp in one's hhhhhoop. Pardon me, but I'm off to play the grand piano.");

$file->setCurrentLineNumber(42);

// Next time, check if the file actually has 42 lines:
use Gnugat\Redaktilo\Search\FactoryMethod\LineNumber;
$editor->has($file, LineNumber::absolute(42));

// Jump two lines bellow:
$editor->jumpDownTo($file, LineNumber::down(2));
// Or Five lines above:
$editor->jumpUpTo($file, LineNumber::up(5));
```