class FilesystemAdapter implements Cloud mixin FilesystemOperator (View source)

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected FilesystemOperator $driver

The Flysystem filesystem implementation.

protected FilesystemAdapter $adapter

The Flysystem adapter implementation.

protected array $config

The filesystem configuration.

protected PathPrefixer $prefixer

The Flysystem PathPrefixer instance.

protected Closure|null $serveCallback

The file server callback.

protected Closure|null $temporaryUrlCallback

The temporary URL builder callback.

Methods

$this|TWhenReturnType
when($value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

$this|TUnlessReturnType
unless($value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

static void
macro(string $name, object|callable $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Checks if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Pass dynamic methods call onto Flysystem.

void
__construct(FilesystemOperator $driver, FilesystemAdapter $adapter, array $config = [])

Create a new filesystem adapter instance.

$this
assertExists(string|array $path, string|null $content = null)

Assert that the given file or directory exists.

$this
assertMissing(string|array $path)

Assert that the given file or directory does not exist.

$this
assertDirectoryEmpty(string $path)

Assert that the given directory is empty.

bool
exists(string $path)

Determine if a file or directory exists.

bool
missing(string $path)

Determine if a file or directory is missing.

bool
fileExists(string $path)

Determine if a file exists.

bool
fileMissing(string $path)

Determine if a file is missing.

bool
directoryExists(string $path)

Determine if a directory exists.

bool
directoryMissing(string $path)

Determine if a directory is missing.

string
path(string $path)

Get the full path to the file that exists at the given relative path.

string|null
get(string $path)

Get the contents of a file.

array|null
json(string $path, int $flags = 0)

Get the contents of a file as decoded JSON.

StreamedResponse
response(string $path, string|null $name = null, array $headers = [], string|null $disposition = 'inline')

Create a streamed response for a given file.

StreamedResponse
serve(Request $request, string $path, string|null $name = null, array $headers = [])

Create a streamed download response for a given file.

StreamedResponse
download(string $path, string|null $name = null, array $headers = [])

Create a streamed download response for a given file.

string
fallbackName(string $name)

Convert the string to ASCII characters that are equivalent to the given name.

bool
put(string $path, StreamInterface|File|UploadedFile|string|resource $contents, mixed $options = [])

Write the contents of a file.

string|false
putFile(File|UploadedFile|string $path, File|UploadedFile|string|array|null $file = null, mixed $options = [])

Store the uploaded file on the disk.

string|false
putFileAs(File|UploadedFile|string $path, File|UploadedFile|string|array|null $file, string|array|null $name = null, mixed $options = [])

Store the uploaded file on the disk with a given name.

string
getVisibility(string $path)

Get the visibility for the given path.

bool
setVisibility(string $path, string $visibility)

Set the visibility for the given path.

bool
prepend(string $path, string $data, string $separator = PHP_EOL)

Prepend to a file.

bool
append(string $path, string $data, string $separator = PHP_EOL)

Append to a file.

bool
delete(string|array $paths)

Delete the file at a given path.

bool
copy(string $from, string $to)

Copy a file to a new location.

bool
move(string $from, string $to)

Move a file to a new location.

int
size(string $path)

Get the file size of a given file.

string|false
checksum(string $path, array $options = [])

Get the checksum for a file.

string|false
mimeType(string $path)

Get the mime-type of a given file.

int
lastModified(string $path)

Get the file's last modification time.

resource|null
readStream(string $path)

Get a resource to read the file.

bool
writeStream(string $path, resource $resource, array $options = [])

Write a new file using a stream.

string
url(string $path)

Get the URL for the file at the given path.

string
getFtpUrl(string $path)

Get the URL for the file at the given path.

string
getLocalUrl(string $path)

Get the URL for the file at the given path.

bool
providesTemporaryUrls()

Determine if temporary URLs can be generated.

string
temporaryUrl(string $path, DateTimeInterface $expiration, array $options = [])

Get a temporary URL for the file at the given path.

array
temporaryUploadUrl(string $path, DateTimeInterface $expiration, array $options = [])

Get a temporary upload URL for the file at the given path.

string
concatPathToUrl(string $url, string $path)

Concatenate a path to a URL.

UriInterface
replaceBaseUrl(UriInterface $uri, string $url)

Replace the scheme, host and port of the given UriInterface with values from the given URL.

array
files(string|null $directory = null, bool $recursive = false)

Get an array of all files in a directory.

array
allFiles(string|null $directory = null)

Get all of the files from the given directory (recursive).

array
directories(string|null $directory = null, bool $recursive = false)

Get all of the directories within a given directory.

array
allDirectories(string|null $directory = null)

Get all the directories within a given directory (recursive).

bool
makeDirectory(string $path)

Create a directory.

bool
deleteDirectory(string $directory)

Recursively delete a directory.

FilesystemOperator
getDriver()

Get the Flysystem driver.

FilesystemAdapter
getAdapter()

Get the Flysystem adapter.

array
getConfig()

Get the configuration values.

string|null
parseVisibility(string|null $visibility)

Parse the given visibility value.

void
serveUsing(Closure $callback)

Define a custom callback that generates file download responses.

void
buildTemporaryUrlsUsing(Closure $callback)

Define a custom temporary URL builder callback.

bool
throwsExceptions()

Determine if Flysystem exceptions should be thrown.

Details

$this|TWhenReturnType when($value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

Parameters

$value
callable|null $callback
callable|null $default

Return Value

$this|TWhenReturnType

$this|TUnlessReturnType unless($value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

Parameters

$value
callable|null $callback
callable|null $default

Return Value

$this|TUnlessReturnType

static void macro(string $name, object|callable $macro)

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Pass dynamic methods call onto Flysystem.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

void __construct(FilesystemOperator $driver, FilesystemAdapter $adapter, array $config = [])

Create a new filesystem adapter instance.

Parameters

FilesystemOperator $driver
FilesystemAdapter $adapter
array $config

Return Value

void

$this assertExists(string|array $path, string|null $content = null)

Assert that the given file or directory exists.

Parameters

string|array $path
string|null $content

Return Value

$this

$this assertMissing(string|array $path)

Assert that the given file or directory does not exist.

Parameters

string|array $path

Return Value

$this

$this assertDirectoryEmpty(string $path)

Assert that the given directory is empty.

Parameters

string $path

Return Value

$this

bool exists(string $path)

Determine if a file or directory exists.

Parameters

string $path

Return Value

bool

bool missing(string $path)

Determine if a file or directory is missing.

Parameters

string $path

Return Value

bool

bool fileExists(string $path)

Determine if a file exists.

Parameters

string $path

Return Value

bool

bool fileMissing(string $path)

Determine if a file is missing.

Parameters

string $path

Return Value

bool

bool directoryExists(string $path)

Determine if a directory exists.

Parameters

string $path

Return Value

bool

bool directoryMissing(string $path)

Determine if a directory is missing.

Parameters

string $path

Return Value

bool

string path(string $path)

Get the full path to the file that exists at the given relative path.

Parameters

string $path

Return Value

string

string|null get(string $path)

Get the contents of a file.

Parameters

string $path

Return Value

string|null

array|null json(string $path, int $flags = 0)

Get the contents of a file as decoded JSON.

Parameters

string $path
int $flags

Return Value

array|null

StreamedResponse response(string $path, string|null $name = null, array $headers = [], string|null $disposition = 'inline')

Create a streamed response for a given file.

Parameters

string $path
string|null $name
array $headers
string|null $disposition

Return Value

StreamedResponse

StreamedResponse serve(Request $request, string $path, string|null $name = null, array $headers = [])

Create a streamed download response for a given file.

Parameters

Request $request
string $path
string|null $name
array $headers

Return Value

StreamedResponse

StreamedResponse download(string $path, string|null $name = null, array $headers = [])

Create a streamed download response for a given file.

Parameters

string $path
string|null $name
array $headers

Return Value

StreamedResponse

protected string fallbackName(string $name)

Convert the string to ASCII characters that are equivalent to the given name.

Parameters

string $name

Return Value

string

bool put(string $path, StreamInterface|File|UploadedFile|string|resource $contents, mixed $options = [])

Write the contents of a file.

Parameters

string $path
StreamInterface|File|UploadedFile|string|resource $contents
mixed $options

Return Value

bool

string|false putFile(File|UploadedFile|string $path, File|UploadedFile|string|array|null $file = null, mixed $options = [])

Store the uploaded file on the disk.

Parameters

File|UploadedFile|string $path
File|UploadedFile|string|array|null $file
mixed $options

Return Value

string|false

string|false putFileAs(File|UploadedFile|string $path, File|UploadedFile|string|array|null $file, string|array|null $name = null, mixed $options = [])

Store the uploaded file on the disk with a given name.

Parameters

File|UploadedFile|string $path
File|UploadedFile|string|array|null $file
string|array|null $name
mixed $options

Return Value

string|false

string getVisibility(string $path)

Get the visibility for the given path.

Parameters

string $path

Return Value

string

bool setVisibility(string $path, string $visibility)

Set the visibility for the given path.

Parameters

string $path
string $visibility

Return Value

bool

bool prepend(string $path, string $data, string $separator = PHP_EOL)

Prepend to a file.

Parameters

string $path
string $data
string $separator

Return Value

bool

bool append(string $path, string $data, string $separator = PHP_EOL)

Append to a file.

Parameters

string $path
string $data
string $separator

Return Value

bool

bool delete(string|array $paths)

Delete the file at a given path.

Parameters

string|array $paths

Return Value

bool

bool copy(string $from, string $to)

Copy a file to a new location.

Parameters

string $from
string $to

Return Value

bool

bool move(string $from, string $to)

Move a file to a new location.

Parameters

string $from
string $to

Return Value

bool

int size(string $path)

Get the file size of a given file.

Parameters

string $path

Return Value

int

string|false checksum(string $path, array $options = [])

Get the checksum for a file.

Parameters

string $path
array $options

Return Value

string|false

Exceptions

UnableToProvideChecksum

string|false mimeType(string $path)

Get the mime-type of a given file.

Parameters

string $path

Return Value

string|false

int lastModified(string $path)

Get the file's last modification time.

Parameters

string $path

Return Value

int

resource|null readStream(string $path)

Get a resource to read the file.

Parameters

string $path

Return Value

resource|null

The path resource or null on failure.

bool writeStream(string $path, resource $resource, array $options = [])

Write a new file using a stream.

Parameters

string $path
resource $resource
array $options

Return Value

bool

string url(string $path)

Get the URL for the file at the given path.

Parameters

string $path

Return Value

string

Exceptions

RuntimeException

protected string getFtpUrl(string $path)

Get the URL for the file at the given path.

Parameters

string $path

Return Value

string

protected string getLocalUrl(string $path)

Get the URL for the file at the given path.

Parameters

string $path

Return Value

string

bool providesTemporaryUrls()

Determine if temporary URLs can be generated.

Return Value

bool

string temporaryUrl(string $path, DateTimeInterface $expiration, array $options = [])

Get a temporary URL for the file at the given path.

Parameters

string $path
DateTimeInterface $expiration
array $options

Return Value

string

Exceptions

RuntimeException

array temporaryUploadUrl(string $path, DateTimeInterface $expiration, array $options = [])

Get a temporary upload URL for the file at the given path.

Parameters

string $path
DateTimeInterface $expiration
array $options

Return Value

array

Exceptions

RuntimeException

protected string concatPathToUrl(string $url, string $path)

Concatenate a path to a URL.

Parameters

string $url
string $path

Return Value

string

protected UriInterface replaceBaseUrl(UriInterface $uri, string $url)

Replace the scheme, host and port of the given UriInterface with values from the given URL.

Parameters

UriInterface $uri
string $url

Return Value

UriInterface

array files(string|null $directory = null, bool $recursive = false)

Get an array of all files in a directory.

Parameters

string|null $directory
bool $recursive

Return Value

array

array allFiles(string|null $directory = null)

Get all of the files from the given directory (recursive).

Parameters

string|null $directory

Return Value

array

array directories(string|null $directory = null, bool $recursive = false)

Get all of the directories within a given directory.

Parameters

string|null $directory
bool $recursive

Return Value

array

array allDirectories(string|null $directory = null)

Get all the directories within a given directory (recursive).

Parameters

string|null $directory

Return Value

array

bool makeDirectory(string $path)

Create a directory.

Parameters

string $path

Return Value

bool

bool deleteDirectory(string $directory)

Recursively delete a directory.

Parameters

string $directory

Return Value

bool

FilesystemOperator getDriver()

Get the Flysystem driver.

Return Value

FilesystemOperator

FilesystemAdapter getAdapter()

Get the Flysystem adapter.

Return Value

FilesystemAdapter

array getConfig()

Get the configuration values.

Return Value

array

protected string|null parseVisibility(string|null $visibility)

Parse the given visibility value.

Parameters

string|null $visibility

Return Value

string|null

Exceptions

InvalidArgumentException

void serveUsing(Closure $callback)

Define a custom callback that generates file download responses.

Parameters

Closure $callback

Return Value

void

void buildTemporaryUrlsUsing(Closure $callback)

Define a custom temporary URL builder callback.

Parameters

Closure $callback

Return Value

void

protected bool throwsExceptions()

Determine if Flysystem exceptions should be thrown.

Return Value

bool