/** * Return this user's nickname. * * The nickname will be a unique, human readable identifier for this user * with respect to this application. It will be an email address for some * users, part of the email address for some users, and the federated identity * for federated users who have not asserted an email address. * * @return string The user's nickname. */ public function getNickname() { if ($this->email != null && $this->auth_domain != null && util\endsWith($this->email, $this->auth_domain)) { $suffixLen = strlen($this->auth_domain) + 1; return substr($this->email, 0, -$suffixLen); } elseif ($this->federated_identity) { return $this->federated_identity; } else { return $this->email; } }
/** * The stat function uses GET requests to the bucket to try and determine if * the object is a 'file' or a 'directory', by listing the contents of the * bucket and then matching the results against the supplied object name. * * If a file ends with "_$folder$" then Google Cloud Storage Manager will * show it as a 'folder' in the UI tool, so we consider an object that ends * in "_$folder$" as a directory as well. */ public function stat() { $prefix = $this->prefix; if (util\endsWith($prefix, parent::DELIMITER)) { $prefix = substr($prefix, 0, strlen($prefix) - 1); } if (isset($prefix)) { while (!isset($mode)) { $results = $this->makeRequest($prefix); if (false === $results) { return false; } // If there are no results then we're done if (empty($results)) { return false; } // If there is an entry in $results that contains the object_name // exactly then we have a matching file - If there is an entry that // contains object_name_$folder$ or object_name/ then we have a // 'directory' $object_name_folder = $prefix . parent::FOLDER_SUFFIX; $object_name_delimiter = $prefix . parent::DELIMITER; foreach ($results as $result) { if ($result['name'] === $prefix) { $mode = parent::S_IFREG; $mtime = $result['mtime']; $size = $result['size']; break; } else { if ($result['name'] === $object_name_folder || strncmp($result['name'], $object_name_delimiter, strlen($object_name_delimiter)) == 0) { $mode = parent::S_IFDIR; break; } } } } } else { // We are now just checking that the bucket exists, as there was no // object prefix supplied $results = $this->makeRequest(); if ($results !== false) { $mode = parent::S_IFDIR; } else { return false; } } // If mode is not set, then there was no object that matched the criteria. if (!isset($mode)) { return false; } // If the app could stat the file, then it must be readable. As different // PHP internal APIs check the access mode, we'll set them all to readable. $mode |= parent::S_IRUSR | parent::S_IRGRP | parent::S_IROTH; $stat_args["mode"] = $mode; if (isset($mtime)) { $unix_time = strtotime($mtime); if ($unix_time !== false) { $stat_args["mtime"] = $unix_time; } } if (isset($size)) { $stat_args["size"] = intval($size); } return $this->createStatArray($stat_args); }
private function getCorrectPathForDirectoryName() { // Replace the trailing MARKER from the prefix and replace it with the // FOLDER_SUFFIX. if (util\endsWith($this->object_name, parent::DELIMITER)) { return substr_replace($this->object_name, parent::FOLDER_SUFFIX, -strlen(parent::DELIMITER)); } else { return $this->object_name . parent::FOLDER_SUFFIX; } }