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 43 44 45 46 47 48 
	<?php namespace amekusa\phio; main::required;
class RegFile extends File {
    protected
        $mode;
    
    public function getContent() {
        if ($jit = !$this->isOpened()) $this->open();
        $r = fread($this->io, $this->getSize());
        if ($jit) $this->close();
        return $r;
    }
    public function getSize() {
        return filesize($this->path);
    }
    
    public function setMode($Mode) {
        $this->mode = $Mode;
        return $this;
    }
    protected function _open() {
        try {
            $this->io = fopen($this->path, $this->mode ?: 'r');
        } catch (ErrorException $E) {
            throw IOException::create("Couldn't open the file: $this")->setIOFile($this);
        }
    }
    protected function _close() {
        if (!fclose($this->io))
            throw IOException::create("Couldn't close the file: $this")->setIOFile($this);
        return true;
    }
}