echo 'File: ' . $fileObject->getPathname(); echo '<br/>'; echo '<br/>'; echo 'Iterate lines:<br/>'; // iterate foreach ($fileObject as $line) { echo $line . '<br/>'; } echo '<br/>'; echo '<br/>'; // while echo 'While:<br/>'; echo $fileObject->firstLine(); echo '<br/>'; while (!$fileObject->isLast()) { echo $fileObject->nextLine(); echo '<br/>'; } echo '<br/>'; echo '<br/>'; echo 'Navigate:<br/>'; echo $fileObject->firstLine(); echo '<br/>'; echo $fileObject->nextLine(); echo '<br/>'; echo $fileObject->nextLine(); echo '<br/>'; echo $fileObject->firstLine(); echo '<br/>'; echo $fileObject->readLine(3); echo '<br/>';
/** * @depends testInit * @return void */ public function testIsLast() { $filePath = __DIR__ . '/example_read.txt'; $fileObject = new FileReader($filePath, 'r', true); $this->assertEquals('Line08', $fileObject->readLine(7)); $this->assertFalse($fileObject->isLast()); $this->assertEquals('Line09', $fileObject->nextLine()); $this->assertEquals('', $fileObject->nextLine()); $this->assertTrue($fileObject->isLast()); $fileObject = new \SplFileObject($filePath, 'r'); $fileObject->setFlags(\SplFileObject::DROP_NEW_LINE | \SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY); $fileObject->seek(7); $this->assertEquals('Line08', $fileObject->current()); $this->assertFalse($fileObject->eof()); $fileObject->next(); $this->assertEquals('Line09', $fileObject->current()); $fileObject->next(); $this->assertEquals('', $fileObject->current()); $this->assertTrue($fileObject->eof()); }