/** * Create a URL for a target bucket and optional object. * * @visibleForTesting */ public static function createObjectUrl($bucket, $object = null) { // Strip leading "/" for $object if (isset($object) && $object[0] == "/") { $object_name = substr($object, 1); } else { $object_name = ""; } $gs_filename = CloudStorageTools::getFilename($bucket, $object_name); return CloudStorageTools::getPublicUrl($gs_filename, true); }
public function testGetFilenameFromInvalidObjecNames() { $invalid_object_names = ["WithCarriageReturn\r", "WithLineFeed\n"]; foreach ($invalid_object_names as $object) { $this->setExpectedException("\\InvalidArgumentException", sprintf("Invalid cloud storage object name '%s'", $object)); CloudStorageTools::getFilename('foo', $object); } }
/** * @dataProvider invalidObjectNames */ public function testGetFilenameFromInvalidObjecNames($object) { $this->setExpectedException("\\InvalidArgumentException", sprintf("Invalid cloud storage object name '%s'", $object)); CloudStorageTools::getFilename('foo', $object); }
/** * Create a GCS filename for a target bucket and optional object. * * @param string $bucket The bucket name. * @param string $object Optional object name. * * @returns string The GCS filename for the bucket and object names. */ protected static function createGcsFilename($bucket, $object = null) { if (!isset($object)) { $object = ""; } // Strip leading "/" for $object. if (StringUtil::startsWith($object, "/")) { $object = substr($object, 1); } return CloudStorageTools::getFilename($bucket, $object); }
/** * Create a URL for a target bucket and optional object. * * @visibleForTesting */ public static function createObjectUrl($bucket, $object = null) { if (!isset($object)) { $object = ""; } // Strip leading "/" for $object. if (StringUtil::startsWith($object, "/")) { $object = substr($object, 1); } $gs_filename = CloudStorageTools::getFilename($bucket, $object); return CloudStorageTools::getPublicUrl($gs_filename, true); }