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