/** * Factory to build FileInfo from existing file or directory * * @param string $path path to a file on the local file system * @param string $as optional path to use inside the archive * @throws FileInfoException * @return FileInfo */ public static function fromPath($path, $as = '') { clearstatcache(false, $path); if (!file_exists($path)) { throw new FileInfoException("{$path} does not exist"); } $stat = stat($path); $file = new FileInfo(); $file->setPath($path); $file->setIsdir(is_dir($path)); $file->setMode(fileperms($path)); $file->setOwner(fileowner($path)); $file->setGroup(filegroup($path)); $file->setUid($stat['uid']); $file->setGid($stat['gid']); $file->setMtime($stat['mtime']); if ($as) { $file->setPath($as); } return $file; }
/** * Creates a FileInfo object from the given parsed header * * @param $header * @return FileInfo */ protected function header2fileinfo($header) { $fileinfo = new FileInfo(); $fileinfo->setPath($header['filename']); $fileinfo->setMode($header['perm']); $fileinfo->setUid($header['uid']); $fileinfo->setGid($header['gid']); $fileinfo->setSize($header['size']); $fileinfo->setMtime($header['mtime']); $fileinfo->setOwner($header['uname']); $fileinfo->setGroup($header['gname']); $fileinfo->setIsdir((bool) $header['typeflag']); return $fileinfo; }