class FilesystemManager implements Factory mixin Filesystem mixin FilesystemAdapter mixin ClientPooledFilesystem

Traits

Hosts must declare a protected array $poolableDrivers containing their default poolable drivers.

Constants

protected ON_DEMAND_DISK_NAME

The logical name used while resolving on-demand disks.

protected READ_THROUGH_CONTEXT_KEY_PREFIX

The coroutine-local construction stack prefix for each manager.

protected GCS_CLIENT_OPTIONS

Google Cloud Storage client constructor options supported by the installed SDK.

Properties

protected Closure> $releaseCallbacks from  HasPoolProxy
static protected null|list<string> $s3ArgumentNames
protected array $disks

The array of resolved filesystem drivers.

protected array $customCreators

The registered custom driver creators.

protected array $poolableDrivers

The array of drivers which will be wrapped as pool proxies.

Methods

mixed
createPoolProxy(string $driver, Closure $createCallback, PoolDefinition $definition, string $proxyClass)

Create a pool proxy for an immutable definition.

poolDefinition(string $resource, array $poolConfig, array $fingerprintSource)

Build a namespaced pool definition for a pooled resource.

poolFactory()

Get the shared object-pool factory.

setReleaseCallback(string $driver, Closure $callback)

Set the release callback for a pooled driver.

Closure|null
getReleaseCallback(string $driver)

Get the release callback for a pooled driver.

addPoolableDriver(string $driver)

Add a driver to the poolable-driver list.

removePoolableDriver(string $driver)

Remove a driver from the poolable-driver list.

array
getPoolableDrivers()

Get the poolable-driver list.

setPoolableDrivers(array $poolableDrivers)

Set the poolable-driver list.

Closure|null
bindCallbackToSelf(Closure $callback)

Bind the provided callback to the class instance.

__construct(Container $app)

Create a new filesystem manager instance.

drive(UnitEnum|string|null $name = null)

Get a filesystem instance.

disk(UnitEnum|string|null $name = null)

Get a filesystem instance.

build(array|string $config, string|null $name = null)

Build an on-demand disk.

get(string $name)

Attempt to get the disk from the local cache.

resolve(string $name, array|null $config = null)

Resolve the given disk.

callCustomCreator(array $config, string|null $name = null)

Call a custom driver creator.

createDriverPooledDisk(string $driver, array $config, string|null $name, string|null $servingRouteDisk, string $servingRoutePrefix, Closure $createCallback)

Create a whole-driver pooled disk for a resource the framework cannot split.

createClientPooledDisk(string $driver, array $config)

Create a client-pooled disk for a built-in cloud driver.

diskPoolDefinition(string $driver, array $config, string|null $name, string|null $servingRouteDisk, string $servingRoutePrefix)

Derive the immutable pool definition for a disk configuration.

createLocalDriver(array $config, string $name = 'local')

Create an instance of the local driver.

createFtpDriver(array $config)

Create an instance of the ftp driver.

createSftpDriver(array $config)

Create an instance of the sftp driver.

createS3Driver(array $config)

Create an instance of the Amazon S3 driver.

createReadThroughDriver(array $config, string $name = 'read-through')

Create an instance of the read-through driver.

FilesystemOperator
readThroughOperator(Cloud $disk)

Get a side operator without exposing borrowed clients or losing native cloud reads.

array
s3ClientConfig(array $config)

Derive the S3 client construction config from a disk config.

static array
s3ArgumentNames()

Get the S3 client constructor argument names.

S3Client
createS3Client(array $clientConfig)

Create an S3 client from normalized client config.

buildS3Disk(S3Client $client, array $config)

Build an S3 disk adapter stack around a client.

array
formatS3Config(array $config)

Format the given S3 configuration with the default options.

mixed
s3CredentialProvider(mixed $credentials)

Get the provider described by an S3 credentials value.

createGcsDriver(array $config)

Create an instance of the Google Cloud Storage driver.

array
gcsClientConfig(array $config)

Derive the Google Cloud Storage client construction config from a disk config.

StorageClient
createGcsClient(array $clientConfig)

Create a Google Cloud Storage client from normalized client config.

buildGcsDisk(StorageClient $client, array $config)

Build a Google Cloud Storage disk adapter stack around a client.

array
formatGcsConfig(array $config)

Format the given GCS configuration with the default options.

array
clientConfigBlock(array $config, array $supportedKeys)

Validate and return an explicit SDK client-option block.

createScopedDriver(array $config, string|null $name = null)

Create a scoped driver.

FilesystemOperator
createFlysystem(FilesystemAdapter $adapter, array $config)

Create a Flysystem instance with the given adapter.

set(UnitEnum|string $name, mixed $disk)

Set the given disk instance.

array
getConfig(string $name)

Get the filesystem connection configuration.

string
getDefaultDriver()

Get the default driver name.

forgetDisk(UnitEnum|array|string $disk)

Unset the given disk instances.

void
purge(UnitEnum|string|null $name = null)

Disconnect the given disk, remove it from local cache, and close its pool.

extend(string $driver, Closure $callback, bool $poolable = false)

Register a custom driver creator Closure.

setApplication(Container $app)

Set the application instance used by the manager.

static void
flushState()

Flush all static state.

mixed
__call(string $method, array $parameters)

Dynamically call the default driver instance.

Filesystem|mixed
when(Closure|mixed $value = 'null', null|callable $callback = 'null', null|callable $default = 'null')

No description

Filesystem|mixed
unless(Closure|mixed $value = 'null', null|callable $callback = 'null', null|callable $default = 'null')

No description

Details

in HasPoolProxy at line 28
protected mixed createPoolProxy(string $driver, Closure $createCallback, PoolDefinition $definition, string $proxyClass)

Create a pool proxy for an immutable definition.

Parameters

string $driver
Closure $createCallback
PoolDefinition $definition
string $proxyClass

Return Value

mixed

in HasPoolProxy at line 49
protected PoolDefinition poolDefinition(string $resource, array $poolConfig, array $fingerprintSource)

Build a namespaced pool definition for a pooled resource.

Parameters

string $resource
array $poolConfig
array $fingerprintSource

Return Value

PoolDefinition

at line 1024
protected Factory poolFactory()

Get the shared object-pool factory.

Return Value

Factory

in HasPoolProxy at line 75
HasPoolProxy setReleaseCallback(string $driver, Closure $callback)

Set the release callback for a pooled driver.

The callback persists on the shared manager for the worker lifetime and is captured by every subsequently created proxy for the driver.

Parameters

string $driver
Closure $callback

Return Value

HasPoolProxy

in HasPoolProxy at line 86
Closure|null getReleaseCallback(string $driver)

Get the release callback for a pooled driver.

Parameters

string $driver

Return Value

Closure|null

in HasPoolProxy at line 98
HasPoolProxy addPoolableDriver(string $driver)

Add a driver to the poolable-driver list.

The list persists on the manager for the worker lifetime and is consulted on subsequent driver creation. Per-request use races across coroutines and does not affect already-cached drivers.

Parameters

string $driver

Return Value

HasPoolProxy

in HasPoolProxy at line 115
HasPoolProxy removePoolableDriver(string $driver)

Remove a driver from the poolable-driver list.

The list persists on the manager for the worker lifetime and is consulted on subsequent driver creation. Per-request use races across coroutines and does not affect already-cached drivers.

Parameters

string $driver

Return Value

HasPoolProxy

in HasPoolProxy at line 133
array getPoolableDrivers()

Get the poolable-driver list.

Return Value

array

in HasPoolProxy at line 145
HasPoolProxy setPoolableDrivers(array $poolableDrivers)

Set the poolable-driver list.

The list persists on the manager for the worker lifetime and is consulted on subsequent driver creation. Per-request use races across coroutines and does not affect already-cached drivers.

Parameters

array $poolableDrivers

Return Value

HasPoolProxy

protected Closure|null bindCallbackToSelf(Closure $callback)

Bind the provided callback to the class instance.

Parameters

Closure $callback

Return Value

Closure|null

Exceptions

ReflectionException

at line 119
__construct(Container $app)

Create a new filesystem manager instance.

Parameters

Container $app

at line 127
Filesystem drive(UnitEnum|string|null $name = null)

Get a filesystem instance.

Parameters

UnitEnum|string|null $name

Return Value

Filesystem

at line 135
Filesystem disk(UnitEnum|string|null $name = null)

Get a filesystem instance.

Parameters

UnitEnum|string|null $name

Return Value

Filesystem

at line 151
Filesystem build(array|string $config, string|null $name = null)

Build an on-demand disk.

Parameters

array|string $config
string|null $name

Return Value

Filesystem

at line 172
protected Filesystem get(string $name)

Attempt to get the disk from the local cache.

Parameters

string $name

Return Value

Filesystem

at line 182
protected Filesystem resolve(string $name, array|null $config = null)

Resolve the given disk.

Parameters

string $name
array|null $config

Return Value

Filesystem

Exceptions

InvalidArgumentException

at line 284
protected Filesystem callCustomCreator(array $config, string|null $name = null)

Call a custom driver creator.

Parameters

array $config
string|null $name

Return Value

Filesystem

at line 300
protected FilesystemPoolProxy createDriverPooledDisk(string $driver, array $config, string|null $name, string|null $servingRouteDisk, string $servingRoutePrefix, Closure $createCallback)

Create a whole-driver pooled disk for a resource the framework cannot split.

Parameters

string $driver
array $config
string|null $name
string|null $servingRouteDisk
string $servingRoutePrefix
Closure $createCallback

Return Value

FilesystemPoolProxy

at line 320
protected ClientPooledFilesystem createClientPooledDisk(string $driver, array $config)

Create a client-pooled disk for a built-in cloud driver.

Parameters

string $driver
array $config

Return Value

ClientPooledFilesystem

at line 356
protected PoolDefinition diskPoolDefinition(string $driver, array $config, string|null $name, string|null $servingRouteDisk, string $servingRoutePrefix)

Derive the immutable pool definition for a disk configuration.

Parameters

string $driver
array $config
string|null $name
string|null $servingRouteDisk
string $servingRoutePrefix

Return Value

PoolDefinition

at line 380
Filesystem createLocalDriver(array $config, string $name = 'local')

Create an instance of the local driver.

Parameters

array $config
string $name

Return Value

Filesystem

at line 416
Filesystem createFtpDriver(array $config)

Create an instance of the ftp driver.

Parameters

array $config

Return Value

Filesystem

at line 435
Filesystem createSftpDriver(array $config)

Create an instance of the sftp driver.

Parameters

array $config

Return Value

Filesystem

at line 460
Cloud createS3Driver(array $config)

Create an instance of the Amazon S3 driver.

Parameters

array $config

Return Value

Cloud

at line 473
Filesystem createReadThroughDriver(array $config, string $name = 'read-through')

Create an instance of the read-through driver.

Parameters

array $config
string $name

Return Value

Filesystem

at line 546
protected FilesystemOperator readThroughOperator(Cloud $disk)

Get a side operator without exposing borrowed clients or losing native cloud reads.

Parameters

Cloud $disk

Return Value

FilesystemOperator

at line 562
protected array s3ClientConfig(array $config)

Derive the S3 client construction config from a disk config.

Parameters

array $config

Return Value

array

at line 580
static protected array s3ArgumentNames()

Get the S3 client constructor argument names.

The SDK argument set is immutable for the worker's installed version.

Return Value

array

at line 590
protected S3Client createS3Client(array $clientConfig)

Create an S3 client from normalized client config.

Parameters

array $clientConfig

Return Value

S3Client

Exceptions

InvalidArgumentException

at line 625
protected AwsS3V3Adapter buildS3Disk(S3Client $client, array $config)

Build an S3 disk adapter stack around a client.

Parameters

S3Client $client
array $config

Return Value

AwsS3V3Adapter

at line 650
protected array formatS3Config(array $config)

Format the given S3 configuration with the default options.

Parameters

array $config

Return Value

array

at line 676
protected mixed s3CredentialProvider(mixed $credentials)

Get the provider described by an S3 credentials value.

Parameters

mixed $credentials

Return Value

mixed

at line 688
Cloud createGcsDriver(array $config)

Create an instance of the Google Cloud Storage driver.

Parameters

array $config

Return Value

Cloud

at line 699
protected array gcsClientConfig(array $config)

Derive the Google Cloud Storage client construction config from a disk config.

Parameters

array $config

Return Value

array

at line 712
protected StorageClient createGcsClient(array $clientConfig)

Create a Google Cloud Storage client from normalized client config.

Parameters

array $clientConfig

Return Value

StorageClient

at line 720
protected GoogleCloudStorageAdapter buildGcsDisk(StorageClient $client, array $config)

Build a Google Cloud Storage disk adapter stack around a client.

Parameters

StorageClient $client
array $config

Return Value

GoogleCloudStorageAdapter

at line 754
protected array formatGcsConfig(array $config)

Format the given GCS configuration with the default options.

Parameters

array $config

Return Value

array

at line 773
protected array clientConfigBlock(array $config, array $supportedKeys)

Validate and return an explicit SDK client-option block.

Parameters

array $config
array $supportedKeys

Return Value

array

at line 798
Filesystem createScopedDriver(array $config, string|null $name = null)

Create a scoped driver.

Parameters

array $config
string|null $name

Return Value

Filesystem

Exceptions

InvalidArgumentException

at line 965
protected FilesystemOperator createFlysystem(FilesystemAdapter $adapter, array $config)

Create a Flysystem instance with the given adapter.

Parameters

FilesystemAdapter $adapter
array $config

Return Value

FilesystemOperator

at line 999
FilesystemManager set(UnitEnum|string $name, mixed $disk)

Set the given disk instance.

Mutates the singleton's disk cache; concurrent coroutines may already hold a reference to the prior disk and next resolution will return the replacement. Any shared pool remains available until its idle TTL expires or purge() invalidates it.

Parameters

UnitEnum|string $name
mixed $disk

Return Value

FilesystemManager

at line 1010
protected array getConfig(string $name)

Get the filesystem connection configuration.

Parameters

string $name

Return Value

array

at line 1032
string getDefaultDriver()

Get the default driver name.

Return Value

string

at line 1048
FilesystemManager forgetDisk(UnitEnum|array|string $disk)

Unset the given disk instances.

Mutates the singleton's disk cache; concurrent coroutines may already hold a reference to the disk and next resolution will rebuild a wrapper. Shared pools remain available until their idle TTL expires or purge() deliberately invalidates them.

Parameters

UnitEnum|array|string $disk

Return Value

FilesystemManager

at line 1065
void purge(UnitEnum|string|null $name = null)

Disconnect the given disk, remove it from local cache, and close its pool.

Use this to recover broken pooled resources. Closing deliberately invalidates a shared pool; other converged disks acquire a fresh pool on their next operation.

Parameters

UnitEnum|string|null $name

Return Value

void

at line 1097
FilesystemManager extend(string $driver, Closure $callback, bool $poolable = false)

Register a custom driver creator Closure.

Anonymous closures run in this manager's class scope; non-static closures also receive the manager as $this.

The callback persists in the singleton's customCreators array (and the poolable list if $poolable is true) for the worker lifetime and applies to every subsequent disk resolution.

Parameters

string $driver
Closure $callback
bool $poolable

Return Value

FilesystemManager

at line 1124
FilesystemManager setApplication(Container $app)

Set the application instance used by the manager.

Swaps the singleton's container reference; per-request use races across coroutines and breaks every concurrent filesystem operation.

Parameters

Container $app

Return Value

FilesystemManager

at line 1135
static void flushState()

Flush all static state.

Return Value

void

at line 1143
mixed __call(string $method, array $parameters)

Dynamically call the default driver instance.

Parameters

string $method
array $parameters

Return Value

mixed

at line 59
Filesystem|mixed when(Closure|mixed $value = 'null', null|callable $callback = 'null', null|callable $default = 'null')

No description

Parameters

Closure|mixed $value
null|callable $callback
null|callable $default

Return Value

Filesystem|mixed

at line 59
Filesystem|mixed unless(Closure|mixed $value = 'null', null|callable $callback = 'null', null|callable $default = 'null')

No description

Parameters

Closure|mixed $value
null|callable $callback
null|callable $default

Return Value

Filesystem|mixed