function get_first_folder() { parent::get(); if (isset($this->folders[0])) { return $this->folders[0]; } else { return null; } }
/** * @desc Builds a Folder object. * @param string $path Path of the folder. */ public function __construct($path) { parent::__construct(rtrim($path, '/')); }
/** * @desc Builds a File object. * @param string $path Path of the file you want to work with. * @param int $mode If you want to open it only to read it, use the flag File::READ, if it's to write it use the File::WRITE flag, you also can use the File::READ_WRITE flag. * @param bool $whenopen If you want to open the file now, use the File::DIRECT_OPENING constant, if you want to open it only when you will need it, use the File::LAZY_OPENING constant. */ public function __construct($path) { parent::__construct($path); }
function write($data, $how = ERASE, $mode = CLOSEFILE) { if ($this->mode & WRITE) { if ($mode == NOTCLOSEFILE && !is_ressource($this->fd) || $mode == CLOSEFILE) { if (!($this->fd = @fopen($this->path, $how == ADD ? 'a' : 'w'))) { return false; } } $bytes_to_write = strlen($data); $bytes_written = 0; while ($bytes_written < $bytes_to_write) { $bytes = fwrite($this->fd, substr($data, $bytes_written, 4096)); if ($bytes === false || $bytes == 0) { break; } $bytes_written += $bytes; } parent::write(); return $bytes_written == $bytes_to_write; } else { user_error('File ' . $this->path . ' is open in the read only mode, it can\'t be written.'); } }