VOOZH about

URL: https://deepwiki.com/hypervel/filesystem/3.3-cloud-storage-drivers

⇱ Cloud Storage Drivers | hypervel/filesystem | DeepWiki


Loading...
Menu

Cloud Storage Drivers

Purpose and Scope

This page provides an overview of cloud storage driver support in the hypervel/filesystem package, covering features and capabilities shared across all cloud storage implementations. Cloud storage drivers enable applications to interact with remote object storage services through a unified interface.

For driver-specific configuration and features, see:

For details on the base driver architecture that all drivers inherit from, see Driver Architecture and FilesystemAdapter.

For information on connection pooling optimization specific to cloud drivers, see Object Pooling for Cloud Drivers.


Supported Cloud Storage Providers

The hypervel/filesystem package supports two major cloud storage providers:

ProviderDriver NameFlysystem PackageCloud SDK
Amazon S3s3league/flysystem-aws-s3-v3aws/aws-sdk-php
Google Cloud Storagegcsleague/flysystem-google-cloud-storagegoogle/cloud-storage

Both drivers are optional dependencies listed in the suggest section of composer.json46-47 Applications only need to install the specific cloud storage packages they intend to use.

Sources: composer.json1-63


Cloud vs Local Drivers: Key Differences

Cloud storage drivers differ from local and network filesystem drivers in several important ways:

1. Cloud Interface Implementation

All cloud storage drivers implement the Cloud interface src/Contracts/Cloud.php7-13 which extends the base Filesystem interface with URL generation capabilities:


Diagram: Cloud Interface Hierarchy

The url() method enables cloud drivers to generate publicly accessible URLs for stored files, a capability not available to local filesystem drivers.

Sources: src/Contracts/Cloud.php1-14

2. Connection Pooling

Cloud storage drivers utilize connection pooling via FilesystemPoolProxy to optimize performance. Cloud SDK clients (AWS S3Client, Google StorageClient) are expensive to instantiate, making connection reuse critical for high-throughput applications.

Local and network protocol drivers (FTP, SFTP) bypass pooling as their connection overhead is minimal.

Sources: High-level architecture diagrams (Diagram 3)

3. External Service Dependencies

Cloud drivers require network connectivity to external services and appropriate credentials (API keys, service accounts). Configuration includes:

  • Authentication credentials (access keys, service account JSON)
  • Service endpoints and regions
  • Bucket/container names
  • Network timeout settings

Local drivers have no external dependencies beyond filesystem permissions.


CloudStorageFactory

The CloudStorageFactory class provides a convenience mechanism for resolving cloud storage instances from the dependency injection container.

Factory Implementation

src/CloudStorageFactory.php11-18

class CloudStorageFactory
{
 public function __invoke(ContainerInterface $container): CloudContract
 {
 return $container->get(FactoryContract::class)
 ->cloud(CloudContract::class);
 }
}

The factory:

  1. Resolves the Factory contract (implemented by FilesystemManager)
  2. Calls the cloud() method to retrieve the cloud disk instance
  3. Returns an object implementing the Cloud interface

Usage Pattern


Diagram: CloudStorageFactory Resolution Flow

The cloud() method on FilesystemManager resolves to the disk specified in the Cloud::class configuration key, typically pointing to the default cloud disk.

Sources: src/CloudStorageFactory.php1-19


Shared Cloud Features

URL Generation

All cloud drivers implement URL generation methods for accessing stored files:

MethodPurposeAvailability
url($path)Public permanent URLS3, GCS
temporaryUrl($path, $expiration)Time-limited signed URLS3, GCS
temporaryUploadUrl($path, $expiration)Pre-signed upload URLS3 only

For comprehensive documentation on URL generation, including configuration options and security considerations, see URL Generation.

Streaming Support

Cloud drivers support efficient streaming operations:

  • Stream Reading: readStream($path) returns a PSR-7 compatible stream
  • Stream Writing: writeStream($path, $stream) uploads from a stream resource
  • HTTP Responses: Integration with HTTP response streaming for large file delivery

For detailed streaming documentation, see Streaming and Content Handling.

Content Type Handling

Cloud drivers automatically detect and set appropriate Content-Type headers:

  • Automatic MIME type detection from file extensions
  • Manual override via configuration options
  • Proper handling for common file types (images, videos, documents)

Visibility Control

Both S3 and GCS drivers support file visibility management:

  • Public: Files accessible via public URL without authentication
  • Private: Files require signed/temporary URLs for access

Visibility is configured per-file or set as default for the disk.

Sources: High-level architecture diagrams, src/Contracts/Cloud.php1-14


Cloud Driver Instantiation Flow


Diagram: Cloud Driver Creation Process

The instantiation flow highlights the layering:

  1. FilesystemManager reads disk configuration
  2. Cloud SDK client (S3Client/StorageClient) is initialized
  3. Flysystem adapter wraps the SDK client
  4. Driver-specific adapter (AwsS3V3Adapter/GoogleCloudStorageAdapter) wraps Flysystem
  5. FilesystemPoolProxy wraps the adapter for connection pooling
  6. Final instance returned to application code

Sources: High-level architecture diagrams (Diagram 3)


Configuration Patterns

Cloud storage drivers share common configuration structure:

Required Configuration Keys

KeyPurposeExample
driverDriver identifier's3' or 'gcs'
keyAccess key/credentialsAWS access key or GCS project ID
secretSecret key/credentialsAWS secret key or GCS service account
regionStorage region'us-east-1' (S3) or 'us-central1' (GCS)
bucketBucket/container name'my-app-files'

Optional Configuration Keys

KeyPurposeDefault
urlCustom base URLGenerated from region/bucket
endpointCustom service endpointAWS/Google default endpoints
visibilityDefault file visibility'private'
throwThrow exceptions on errorsfalse
rootPath prefix for all operations'' (root)

For comprehensive configuration reference, see Configuration Reference.

Sources: High-level architecture diagrams (Diagram 3)


Pool Configuration

Cloud drivers support connection pool configuration to optimize resource utilization:

'disks' => [
 's3' => [
 'driver' => 's3',
 // ... S3 configuration
 'pool' => [
 'min_connections' => 1,
 'max_connections' => 10,
 'wait_timeout' => 3.0,
 'max_idle_time' => 60.0,
 ],
 ],
],

Pool configuration keys:

KeyPurposeDefault
min_connectionsMinimum connections maintained1
max_connectionsMaximum concurrent connections10
wait_timeoutSeconds to wait for available connection3.0
max_idle_timeSeconds before idle connection is closed60.0

For detailed pooling documentation, see Object Pooling for Cloud Drivers.

Sources: High-level architecture diagrams


Selecting a Cloud Storage Provider

Amazon S3

Choose S3 when:

  • Already using AWS infrastructure
  • Need multi-region replication
  • Require fine-grained IAM permissions
  • Want lifecycle management policies
  • Need cross-region transfer acceleration

S3 Advantages:

  • Mature ecosystem and tooling
  • Extensive AWS service integrations
  • Comprehensive access control options
  • Pre-signed upload URL support

Google Cloud Storage

Choose GCS when:

  • Already using Google Cloud Platform
  • Need unified storage classes
  • Want seamless BigQuery integration
  • Prefer simpler pricing structure
  • Require strong consistency guarantees

GCS Advantages:

  • Competitive pricing
  • Strong consistency by default
  • Integrated with Google services
  • Simplified storage class management

For provider-specific features and configuration, see:

Sources: composer.json46-47


Installation

S3 Driver Installation


GCS Driver Installation


Both packages automatically install their respective cloud SDKs as dependencies.

Sources: composer.json46-47


Summary

Cloud storage drivers in hypervel/filesystem provide:

  1. Unified Interface: The Cloud contract extends Filesystem with URL generation
  2. Connection Pooling: Automatic pooling via FilesystemPoolProxy for performance optimization
  3. URL Generation: Public and temporary signed URLs for file access
  4. Streaming Support: Efficient handling of large files via stream operations
  5. Flexible Configuration: Consistent configuration patterns across providers

The CloudStorageFactory provides dependency injection integration, while individual driver implementations (AwsS3V3Adapter, GoogleCloudStorageAdapter) add provider-specific functionality.

Sources: src/CloudStorageFactory.php1-19 src/Contracts/Cloud.php1-14 composer.json1-63