-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLineToReaderIterator.php
42 lines (37 loc) · 1.01 KB
/
LineToReaderIterator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
* Created by PhpStorm.
* User: jderay
* Date: 9/22/14
* Time: 9:57 PM
*/
namespace Giftcards\FixedWidth;
use Giftcards\FixedWidth\Spec\FileSpec;
use Giftcards\FixedWidth\Spec\Recognizer\RecordSpecRecognizerInterface;
use Giftcards\FixedWidth\Spec\ValueFormatter\ValueFormatterInterface;
class LineToReaderIterator extends \IteratorIterator
{
protected $spec;
protected $recognizer;
protected $formatter;
public function __construct(
FileInterface $file,
FileSpec $spec,
RecordSpecRecognizerInterface $recognizer,
ValueFormatterInterface $formatter
) {
parent::__construct($file);
$this->spec = $spec;
$this->recognizer = $recognizer;
$this->formatter = $formatter;
}
public function current()
{
$line = parent::current();
return new LineReader(
$line,
$this->spec->getRecordSpec($this->recognizer->recognize($line, $this->spec)),
$this->formatter
);
}
}