Source of file FileInfo.php
Size: 2,237 Bytes - Last Modified: 2014-05-08T01:19:22+02:00
/home/theseer/storage/php/phpdox/src/shared/FileInfo.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 | <?php namespace TheSeer\phpDox { class FileInfo extends \SplFileInfo { public function getRealPath() { $path = parent::getRealPath(); if (!$path) { throw new FileInfoException( sprintf("Path '%s' does not exist - call to realpath failed", $this->getPathname()), FileInfoException::InvalidPath ); } return $this->toUnix($path); } /** * @return bool */ public function exists() { return file_exists($this->getPathname()); } public function asFileUri() { $result = $this->getRealPath(); if ($result[0] != '/') { $result = '/' . $result; } return 'file://' . $result; } public function getPath() { return $this->toUnix(parent::getPath()); } public function getRelative(\SplFileInfo $relation, $inclusive = TRUE) { $relPath = $this->getRealPath(); $relationPath = $relation->getRealPath(); if ($inclusive) { $relationPath = dirname($relationPath); } $relPath = substr($relPath, strlen($relationPath)+1); return new FileInfo($relPath); } public function getPathname() { return $this->toUnix(parent::getPathname()); } public function getLinkTarget() { return $this->toUnix(parent::getLinkTarget()); } public function __toString() { return $this->getPathname(); } public function getFileInfo($class_name = NULL) { throw new FileInfoException("getFileInfo not implemented", FileInfoException::NotImplemented); } public function getPathInfo($class_name = NULL) { throw new FileInfoException("getPathInfo not implemented", FileInfoException::NotImplemented); } private function toUnix($str) { return str_replace('\\', '/', $str); } } class FileInfoException extends \Exception { const InvalidPath = 1; const NotImplemented = 2; } } |