/** * Get request logs for the given request log ids and optionally include the * application logs addded during each request. Request log ids that are not * found are ignored so the returned array may have fewer items than * <code>$request_ids</code>. * * @param mixed $request_ids A string request id or an array of string request * ids obtained from <code>RequestLog::getRequestId()</code>. * @param boolean $include_app_logs Should applicaiton logs be included in the * fetched request logs. Defaults to true - application logs are included. * * @return RequestLog[] The request logs for ids that were found. */ public static function fetchById($request_ids, $include_app_logs = true) { $request = new LogReadRequest(); $request->setAppId(getenv('APPLICATION_ID')); if (!is_bool($include_app_logs)) { throw new \InvalidArgumentException('Parameter $include_app_logs must be boolean but was ' . typeOrClass($include_app_logs)); } $request->setIncludeAppLogs($include_app_logs); self::setDefaultModuleVersion($request); if (is_string($request_ids)) { if (!preg_match(self::$REQUEST_ID_REGEX, $request_ids)) { throw new \InvalidArgumentException("Invalid request id " . htmlspecialchars($request_ids)); } $request->addRequestId($request_ids); } else { if (is_array($request_ids)) { foreach ($request_ids as $id) { if (!is_string($id)) { throw new \InvalidArgumentException('Request id must be a string but was ' . self::typeOrClass($id)); } if (!preg_match(self::$REQUEST_ID_REGEX, $id)) { throw new \InvalidArgumentException("Invalid request id " . htmlspecialchars($id)); } $request->addRequestId($id); } } else { throw new \InvalidArgumentException('Expected a string or an array of strings but was ' . self::typeOrClass($value)); } } $response = self::readLogs($request); $result = []; foreach ($response->getLogList() as $log) { $result[] = new RequestLog($log); } return $result; }
/** * Get the public URL for a Google Cloud Storage filename. * * @param string $gs_filename The Google Cloud Storage filename, in the * format gs://bucket_name/object_name. * @param boolean $use_https If True then return a HTTPS URL. Note that the * development server ignores this argument and returns only HTTP URLs. * * @return string The public URL. * * @throws \InvalidArgumentException if the filename is not in the correct * format or $use_https is not a boolean. */ public static function getPublicUrl($gs_filename, $use_https) { if (!is_bool($use_https)) { throw new \InvalidArgumentException('Parameter $use_https must be boolean but was ' . typeOrClass($use_https)); } if (!self::parseFilename($gs_filename, $bucket, $object)) { throw new \InvalidArgumentException(sprintf('Invalid Google Cloud Storage filename: %s', htmlspecialchars($gs_filename))); } if (self::isDevelServer()) { $scheme = 'http'; $host = getenv('HTTP_HOST'); $path = sprintf('%s/%s%s', self::LOCAL_ENDPOINT, $bucket, $object); } else { // Use path format for HTTPS URL when the bucket name contains "." to // avoid SSL certificate validation issue. if ($use_https && strpos($bucket, '.') !== false) { $host = self::PRODUCTION_HOST_PATH_FORMAT; $path = sprintf('/%s%s', $bucket, $object); } else { $host = sprintf(self::PRODUCTION_HOST_SUBDOMAIN_FORMAT, $bucket); $path = strlen($object) > 0 ? $object : '/'; } $scheme = $use_https ? 'https' : 'http'; } return sprintf('%s://%s%s', $scheme, $host, strtr($path, self::$url_path_translation_map)); }