Пример #1
0
Файл: Node.php Проект: jasny/Q
 /**
  * Get file or extended attribute.
  * @see http://www.php.net/stat
  * 
  * @param string $att    Attribute name
  * @param int    $flags  FS::% and/or XATTR_% options as binary set
  * @return mixed
  */
 public function getAttribute($att, $flags = 0)
 {
     $stat = $flags & Fs::NO_DEREFERENCE ? @lstat($this->_path) : @stat($this->_path);
     if ($stat === false) {
         $err = error_get_last();
         if (!$this->exists()) {
             throw new Fs_Exception("Unable to get attribute '{$att}' of '{$this->_path}': " . (is_link($this->_path) ? "File is a broken link" : "File does not exist"));
         }
         throw new Fs_Exception("Unable to get attribute '{$att}' of '{$this->_path}'", $err);
     }
     if (isset($stat[$att])) {
         return $stat[$att];
     }
     if ($att == 'type') {
         return Fs::mode2type($stat['mode']);
     }
     if ($att == 'perms') {
         return Fs::mode2perms($stat['mode']);
     }
     if ($att == 'owner') {
         return extension_loaded('posix') && ($info = posix_getpwuid($stat['uid'])) ? $info['name'] : $stat['uid'];
     }
     if ($att == 'group') {
         return extension_loaded('posix') && ($info = posix_getgrgid($stat['gid'])) ? $info['name'] : $stat['gid'];
     }
     if (!extension_loaded('xattr') || !xattr_supported($this->_path, $flags)) {
         trigger_error("Unable to get attribute '{$att}' of '{$this->_path}': Extended attributes are not supported.", E_USER_NOTICE);
         return null;
     }
     $value = xattr_get($this->_path, $att);
     return $value !== false ? $value : null;
 }