1 | <?php |
||
13 | class Content implements \Iterator |
||
14 | { |
||
15 | const UTF8_BOM = "\xEF\xBB\xBF"; |
||
16 | |||
17 | /** |
||
18 | * Robots.txt file content |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $content; |
||
22 | |||
23 | /** |
||
24 | * Reader separator |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $separator; |
||
28 | |||
29 | /** |
||
30 | * Current line |
||
31 | * @var string |
||
32 | */ |
||
33 | private $line; |
||
34 | |||
35 | /** |
||
36 | * Current iterator key |
||
37 | * @var integer |
||
38 | */ |
||
39 | private $read = 0; |
||
40 | |||
41 | /** |
||
42 | * @param string $content |
||
43 | */ |
||
44 | public function __construct($content, $separator = "\r\n") |
||
50 | |||
51 | /** |
||
52 | * Retrieve current line |
||
53 | * @return string |
||
54 | */ |
||
55 | public function current() |
||
59 | |||
60 | /** |
||
61 | * Number of chars read |
||
62 | * @return integer |
||
63 | */ |
||
64 | public function key() |
||
68 | |||
69 | /** |
||
70 | * Get the next line in content |
||
71 | */ |
||
72 | public function next() |
||
73 | { |
||
74 | 1 | if ($this->line !== null) { |
|
75 | 1 | $this->line = strtok($this->separator); |
|
76 | } else { |
||
77 | 1 | $this->line = strtok($this->content, $this->separator); |
|
78 | } |
||
79 | 1 | $this->read += strlen($this->line); |
|
80 | 1 | } |
|
81 | |||
82 | /** |
||
83 | * Rewind at beginning |
||
84 | */ |
||
85 | public function rewind() |
||
90 | |||
91 | /** |
||
92 | * Check if current item is valid or not |
||
93 | * @return boolean |
||
94 | */ |
||
95 | public function valid() |
||
99 | } |
||
100 |