Exemplo n.º 1
0
Arquivo: Broken.php Projeto: jasny/Q
 /**
  * Returns Fs_Node of canonicalized absolute pathname, resolving symlinks.
  * Unlike the realpath() PHP function, this returns a best-effort for non-existent files.
  * 
  * Use Fs::NO_DEREFERENCE to not dereference.
  * 
  * @param int $flags  Fs::% options
  * @return Fs_Node
  * @throws Fs_Exception if Fs::ALWAYS_FOLLOW is not set
  */
 public function realpath($flags = 0)
 {
     if ($flags & Fs::NO_DEREFERENCE) {
         $target = Fs::canonicalize($this->target(), dirname($this->_path));
         if (is_link($target)) {
             return new static($target);
         }
         if (~$flags & Fs::ALWAYS_FOLLOW) {
             throw new Fs_Exception("Unable to resolve realpath of '{$this->_path}': File is a broken symlink.");
         }
         return Fs::unknown($target);
     } else {
         $file = $this->realpathBestEffort($flags);
         if (!$file) {
             throw new Fs_Exception("Unable to resolve realpath of '{$this->_path}': Too many levels of symbolic links.");
         }
         return $file;
     }
 }
Exemplo n.º 2
0
Arquivo: Node.php Projeto: jasny/Q
 /**
  * Return path using $dir as root
  *
  * @param Fs_Dir|string $dir  Alternative root path
  * @return string
  */
 public function withRootAs($dir)
 {
     $dir = Fs::canonicalize($dir);
     if ($dir == '/') {
         return $this->_path;
     }
     if (!$this->isIn($dir)) {
         throw new Exception("File '{$this->_path}' is not in directory '{$dir}'.");
     }
     return substr($this->_path, strlen($dir));
 }