Pop\File\File::read PHP Method

read() public method

Read data from a file.
public read ( integer | string $off = null, integer | string $len = null ) : string
$off integer | string
$len integer | string
return string
    public function read($off = null, $len = null)
    {
        $data = null;
        // Read from the output buffer
        if (null !== $this->output) {
            if (null !== $off) {
                $data = null !== $len ? substr($this->output, $off, $len) : substr($this->output, $off);
            } else {
                $data = $this->output;
            }
            // Else, if the file exists, then read the data from the actual file
        } else {
            if (file_exists($this->fullpath)) {
                if (null !== $off) {
                    $data = null !== $len ? file_get_contents($this->fullpath, null, null, $off, $len) : ($this->output = file_get_contents($this->fullpath, null, null, $off));
                } else {
                    $data = file_get_contents($this->fullpath);
                }
            }
        }
        return $data;
    }

Usage Example

Example #1
0
 public function testDecode()
 {
     $f = new File(__DIR__ . '/../tmp/test.sql');
     $s = Sql::decode($f->read());
     $keys = array('id', 'username', 'password', 'email', 'access');
     $this->assertEquals(9, count($s));
     $this->assertEquals($keys, array_keys($s['row_1']));
 }
All Usage Examples Of Pop\File\File::read