| 1 | <?php |
||
| 14 | class RecordReader |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var Matcher\Matcher |
||
| 18 | */ |
||
| 19 | private $matchers = []; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var callable Record builder |
||
| 23 | */ |
||
| 24 | private $builder; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Inject matchers and builder |
||
| 28 | * |
||
| 29 | * The builder should take an array of values captured by registered |
||
| 30 | * matchers and return a Record object. |
||
| 31 | */ |
||
| 32 | 1 | public function __construct(array $matchers, callable $builder) |
|
| 39 | |||
| 40 | /** |
||
| 41 | * Create Record from matched $line content |
||
| 42 | */ |
||
| 43 | 1 | public function readRecord(Line $line): Record |
|
| 53 | |||
| 54 | /** |
||
| 55 | * Add content matcher |
||
| 56 | */ |
||
| 57 | 1 | protected function addMatcher(string $key, Matcher\Matcher $matcher) |
|
| 61 | |||
| 62 | /** |
||
| 63 | * Set record builder |
||
| 64 | */ |
||
| 65 | 1 | protected function setBuilder(callable $builder) |
|
| 69 | } |
||
| 70 |