1 | <?php |
||
22 | class TextFile |
||
23 | { |
||
24 | /** @var \SplFileObject */ |
||
25 | protected $splFileObject; |
||
26 | |||
27 | /** @var string */ |
||
28 | protected $fileName; |
||
29 | |||
30 | /** @var Filesystem */ |
||
31 | protected $fileSystem; |
||
32 | |||
33 | /** @var int */ |
||
34 | protected $currentLine = 0; |
||
35 | |||
36 | /** @var WriterFactory */ |
||
37 | protected $writerFactory; |
||
38 | |||
39 | /** @var WalkerFactory */ |
||
40 | protected $walkerFactory; |
||
41 | |||
42 | /** @var ReaderFactory */ |
||
43 | protected $readerFactory; |
||
44 | |||
45 | /** |
||
46 | * TextFile constructor. |
||
47 | * |
||
48 | * @param string $fileName |
||
49 | */ |
||
50 | 2 | public function __construct($fileName) |
|
60 | |||
61 | /** |
||
62 | * @param string $fileName |
||
63 | */ |
||
64 | 2 | public function open($fileName) |
|
72 | |||
73 | /** |
||
74 | * @return \SplFileObject |
||
75 | */ |
||
76 | 2 | public function getSplFileObject() |
|
80 | |||
81 | /** |
||
82 | * @param int $from |
||
83 | * @param int $to |
||
84 | * @param string $readerClass |
||
85 | * @param string $walkerClass |
||
86 | * |
||
87 | * @return \LimitIterator |
||
88 | * @throws InvalidReaderException |
||
89 | * @throws InvalidWalkerException |
||
90 | * @throws OutOfBoundsException |
||
91 | */ |
||
92 | public function getLinesRange($from, $to, $readerClass = SimpleReader::class, $walkerClass = SimpleWalker::class) |
||
98 | |||
99 | /** |
||
100 | * @param string $walkerClass |
||
101 | * |
||
102 | * @return int |
||
103 | * @throws InvalidWalkerException |
||
104 | */ |
||
105 | public function countLines($walkerClass = SimpleWalker::class) |
||
109 | |||
110 | /** |
||
111 | * @param int $lineNumber |
||
112 | * @param string $walkerClass |
||
113 | * |
||
114 | * @throws OutOfBoundsException |
||
115 | * @throws InvalidWalkerException |
||
116 | */ |
||
117 | public function goToLine($lineNumber, $walkerClass = SimpleWalker::class) |
||
121 | |||
122 | /** |
||
123 | * @param int $characterNumber |
||
124 | * @param string $walkerClass |
||
125 | * |
||
126 | * @return string |
||
127 | * @throws OutOfBoundsException |
||
128 | */ |
||
129 | public function goBeforeCharacter($characterNumber, $walkerClass = SimpleWalker::class) |
||
133 | |||
134 | /** |
||
135 | * @param string $readerClass |
||
136 | * @param string $walkerClass |
||
137 | * |
||
138 | * @return string |
||
139 | * @throws InvalidReaderException |
||
140 | * @throws OutOfBoundsException |
||
141 | */ |
||
142 | public function getNextLineContent($readerClass = SimpleReader::class, $walkerClass = SimpleWalker::class) |
||
148 | |||
149 | /** |
||
150 | * @param string $readerClass |
||
151 | * @param string $walkerClass |
||
152 | * |
||
153 | * @return string |
||
154 | * @throws InvalidReaderException |
||
155 | * @throws OutOfBoundsException |
||
156 | */ |
||
157 | public function getPreviousLineContent($readerClass = SimpleReader::class, $walkerClass = SimpleWalker::class) |
||
163 | |||
164 | /** |
||
165 | * @param string $readerClass |
||
166 | * @param string $walkerClass |
||
167 | * |
||
168 | * @return string |
||
169 | * @throws InvalidReaderException |
||
170 | * @throws OutOfBoundsException |
||
171 | */ |
||
172 | public function getCurrentLineContent($readerClass = SimpleReader::class, $walkerClass = SimpleWalker::class) |
||
178 | |||
179 | /** |
||
180 | * @param int $lineNumber |
||
181 | * @param string $readerClass |
||
182 | * @param string $walkerClass |
||
183 | * |
||
184 | * @return string |
||
185 | * @throws InvalidReaderException |
||
186 | * @throws OutOfBoundsException |
||
187 | */ |
||
188 | public function getLineContent($lineNumber, $readerClass = SimpleReader::class, $walkerClass = SimpleWalker::class) |
||
194 | |||
195 | /** |
||
196 | * @param string $readerClass |
||
197 | * @param string $walkerClass |
||
198 | * |
||
199 | * @return string |
||
200 | * @throws InvalidReaderException |
||
201 | * @throws OutOfBoundsException |
||
202 | */ |
||
203 | public function getNextCharacterContent($readerClass = SimpleReader::class, $walkerClass = SimpleWalker::class) |
||
209 | |||
210 | /** |
||
211 | * @param string $readerClass |
||
212 | * @param string $walkerClass |
||
213 | * |
||
214 | * @return string |
||
215 | * @throws InvalidReaderException |
||
216 | * @throws OutOfBoundsException |
||
217 | */ |
||
218 | public function getPreviousCharacterContent($readerClass = SimpleReader::class, $walkerClass = SimpleWalker::class) |
||
224 | |||
225 | /** |
||
226 | * @param int $characterNumber |
||
227 | * @param string $readerClass |
||
228 | * @param string $walkerClass |
||
229 | * |
||
230 | * @return string |
||
231 | * @throws InvalidReaderException |
||
232 | * @throws OutOfBoundsException |
||
233 | */ |
||
234 | public function getCharacterContent($characterNumber, $readerClass = SimpleReader::class, $walkerClass = SimpleWalker::class) |
||
240 | |||
241 | /** |
||
242 | * @param string $content |
||
243 | * @param bool $newLine |
||
244 | * @param string $writerClass |
||
245 | * |
||
246 | * @throws InvalidWriterException |
||
247 | */ |
||
248 | public function writeToLine($content, $newLine = false, $writerClass = PrependingWriter::class) |
||
252 | |||
253 | /** |
||
254 | * @param string $fileName |
||
255 | */ |
||
256 | protected function createEmpty($fileName) |
||
260 | } |
||
261 |