Tiger_Media_Storage_Gcs
@api· implementsTiger_Media_Storage_Interface
Tiger_Media_Storage_Gcs — Google Cloud Storage media storage.
Mirrors the S3 adapter (see Tiger_Media_Storage_S3): one bucket, visibility selects a key
prefix (public_prefix/private_prefix) so a bucket IAM policy can expose only the public
prefix. PUBLIC objects → a direct CDN/storage.googleapis.com URL; PRIVATE objects → a
short-lived V4 signed URL (presign_ttl), or '' when signing is off/presign_ttl=0, in
which case the media layer streams through the ACL-checked /media/file/
Credentials: a service-account JSON via key_file (needed to sign private URLs), else
Application Default Credentials (GCE/GKE metadata, GOOGLE_APPLICATION_CREDENTIALS).
Requires google/cloud-storage (optional dependency — composer suggest / MEDIA.md); the
adapter throws a clear message if it's missing, and only loads when a gcs disk is used.
Methods
__construct()
__construct(array $config)
Configure the bucket, prefixes, CDN, and presign TTL from the disk config.
$configarray— themedia.disks.<name>.*settings
Throws RuntimeException — when the bucket is not configured
put()
put($key, $sourcePath, $visibility, $mime = null)
Store bytes from a source file path as a GCS object.
$keystring— the adapter-relative storage key$sourcePathstring— the source file on disk to read from$visibilitystring— public|private$mime?string— the content MIME type (may be null)
Throws RuntimeException — when the source can't be read or the upload fails
write()
write($key, $bytes, $visibility, $mime = null)
Store raw bytes as a GCS object.
$keystring— the adapter-relative storage key$bytesstring— the raw bytes to store$visibilitystring— public|private$mime?string— the content MIME type (may be null)
get()
get($key, $visibility)
Read all bytes of an object.
$keystring— the adapter-relative storage key$visibilitystring— public|private
Returns string — the object's bytes
Throws RuntimeException — when the object is not found
stream()
stream($key, $visibility)
Open a read stream for an object.
$keystring— the adapter-relative storage key$visibilitystring— public|private
Returns resource — a readable stream for the object
Throws RuntimeException — when the object is not found
delete()
delete($key, $visibility)
Remove an object (idempotent — a missing object is not an error).
$keystring— the adapter-relative storage key$visibilitystring— public|private
exists()
exists($key, $visibility)
Does the object exist?
$keystring— the adapter-relative storage key$visibilitystring— public|private
Returns bool — true when the object exists
size()
size($key, $visibility)
Size of an object in bytes (0 if missing).
$keystring— the adapter-relative storage key$visibilitystring— public|private
Returns int — the object size in bytes, or 0 if missing
url()
url($key, $visibility, $ttl = null)
A directly-usable URL for an object (CDN/public URL for public, a V4 signed URL for private).
$keystring— the adapter-relative storage key$visibilitystring— public|private$ttl?int— seconds for the private signed URL (adapter default when null)
Returns string — a usable URL, or '' when the app must stream the bytes itself