PhiO: Object-oriented filesystem library for PHP
  • Namespace
  • Class
  • Tree
  • Todo

Namespaces

  • amekusa
    • phio
  • PHP

Classes

  • amekusa\phio\Directory
  • amekusa\phio\File
  • amekusa\phio\FilePool
  • amekusa\phio\Filter
  • amekusa\phio\Perms
  • amekusa\phio\RegexFilter
  • amekusa\phio\RegFile

Exceptions

  • amekusa\phio\ErrorException
  • amekusa\phio\IOException
 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;

/**
 * Regular file abstraction
 * @author amekusa <post@amekusa.com>
 */
class RegFile extends File {
    protected
        $mode;

    /**
     * @return string
     */
    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);
    }

    /**
     * @param string $Mode
     * @return RegFile The object itself
     */
    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;
    }
}
PhiO: Object-oriented filesystem library for PHP API documentation generated by ApiGen