Tiger_Media_Storage_Gcs

@api Β· implements Tiger_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/ route.

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.

  • $config array β€” the media.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.

  • $key string β€” the adapter-relative storage key
  • $sourcePath string β€” the source file on disk to read from
  • $visibility string β€” 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.

  • $key string β€” the adapter-relative storage key
  • $bytes string β€” the raw bytes to store
  • $visibility string β€” public|private
  • $mime ?string β€” the content MIME type (may be null)

get()

get($key, $visibility)

Read all bytes of an object.

  • $key string β€” the adapter-relative storage key
  • $visibility string β€” 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.

  • $key string β€” the adapter-relative storage key
  • $visibility string β€” 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).

  • $key string β€” the adapter-relative storage key
  • $visibility string β€” public|private

exists()

exists($key, $visibility)

Does the object exist?

  • $key string β€” the adapter-relative storage key
  • $visibility string β€” public|private

Returns bool β€” true when the object exists

size()

size($key, $visibility)

Size of an object in bytes (0 if missing).

  • $key string β€” the adapter-relative storage key
  • $visibility string β€” 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).

  • $key string β€” the adapter-relative storage key
  • $visibility string β€” 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