\Omega\Filesystem FilesystemInterface

Interface FilesystemInterface.

The FilesystemInterface defines a contract for filesystem operations, providing a set of methods for interacting with files within a filesystem. This interface allows for the creation, reading, writing, deletion, and management of files, as well as querying their metadata. Implementing this interface enables different filesystem backends (e.g., local storage, cloud storage) to be used interchangeably, promoting a consistent API for file operations across various storage solutions.

Summary

Methods
Constants
has()
rename()
get()
write()
read()
delete()
keys()
listKeys()
mtime()
checksum()
size()
createStream()
createFile()
mimeType()
isDirectory()
No public constants found

Methods

has()

has(string  $key) : bool

Check if a file exists in the filesystem.

Parameters

string $key

The key (path) of the file.

Throws

\InvalidArgumentException

If $key is invalid.

Returns

bool —

TRUE if the file exists, FALSE otherwise.

rename()

rename(string  $sourceKey, string  $targetKey) : bool

Rename a file in the filesystem.

This method should not be directly used; prefer using the File::rename method to ensure filesystem consistency.

Parameters

string $sourceKey

The current key (path) of the file.

string $targetKey

The new key (path) for the file.

Throws

\Omega\Filesystem\Exception\FileNotFoundException

If the source file does not exist.

\Omega\Filesystem\Exception\UnexpectedFileExcption

If the target key already exists.

\RuntimeException

If the rename operation fails.

\InvalidArgumentException

If either $sourceKey or $targetKey is invalid.

Returns

bool —

TRUE if the rename was successful.

get()

get(string  $key, bool  $create = false) : \Omega\Filesystem\File

Retrieve a file from the filesystem.

Parameters

string $key

The key (path) of the file.

bool $create

Whether to create the file if it does not exist.

Throws

\InvalidArgumentException

If $key is invalid.

\Omega\Filesystem\Exception\FileNotFoundException

If the file does not exist and $create is false.

Returns

\Omega\Filesystem\File —

The requested file object.

write()

write(string  $key, string  $content, bool  $overwrite = false) : int

Write content to a file in the filesystem.

Parameters

string $key

The key (path) of the file.

string $content

The content to write to the file.

bool $overwrite

Whether to overwrite the file if it already exists.

Throws

\RuntimeException

If the content could not be written.

\InvalidArgumentException

If $key is invalid.

\Omega\Filesystem\Exception\FileAlreadyExistsException

If the file already exists and $overwrite is false.

Returns

int —

The number of bytes written to the file.

read()

read(string  $key) : string

Read content from a file in the filesystem.

Parameters

string $key

The key (path) of the file.

Throws

\RuntimeException

If the file could not be read.

\InvalidArgumentException

If $key is invalid.

\Omega\Filesystem\Exception\FileNotFoundException

If the file does not exist.

Returns

string —

The content of the file.

delete()

delete(string  $key) : bool

Delete a file from the filesystem.

Parameters

string $key

The key (path) of the file to delete.

Throws

\RuntimeException

If the file could not be deleted.

\InvalidArgumentException

If $key is invalid.

Returns

bool —

TRUE on success, FALSE otherwise.

keys()

keys() : array

Retrieve an array of all file keys in the filesystem.

Returns

array —

An array of file keys.

listKeys()

listKeys(string  $prefix = '') : array

List file keys that begin with a specified prefix.

If the adapter implements the ListKeysAware interface, its implementation will be used. Otherwise, all keys will be retrieved and filtered.

Parameters

string $prefix

The prefix to filter keys.

Returns

array —

An array of file keys matching the prefix.

mtime()

mtime(string  $key) : int

Retrieve the last modified time of a specified file.

Parameters

string $key

The key (path) of the file.

Throws

\InvalidArgumentException

If $key is invalid.

Returns

int —

The last modified time as a Unix timestamp.

checksum()

checksum(string  $key) : string

Calculate the checksum of a specified file's content.

Parameters

string $key

The key (path) of the file.

Throws

\InvalidArgumentException

If $key is invalid.

Returns

string —

An MD5 hash representing the file's content checksum.

size()

size(string  $key) : int

Retrieve the size of a specified file's content.

Parameters

string $key

The key (path) of the file.

Throws

\InvalidArgumentException

If $key is invalid.

Returns

int —

The size of the file in bytes.

createStream()

createStream(string  $key) : \Omega\Filesystem\Stream\StreamInterface|\Omega\Filesystem\Stream\InMemoryBuffer

Create a new stream instance for a specified file.

Parameters

string $key

The key (path) of the file.

Throws

\InvalidArgumentException

If $key is invalid.

Returns

\Omega\Filesystem\Stream\StreamInterface|\Omega\Filesystem\Stream\InMemoryBuffer —

A stream interface for the file.

createFile()

createFile(string  $key) : \Omega\Filesystem\File

Create a new file in the filesystem.

Parameters

string $key

The key (path) for the new file.

Throws

\InvalidArgumentException

If $key is invalid.

Returns

\Omega\Filesystem\File —

The newly created file object.

mimeType()

mimeType(string  $key) : string

Get the mime type of a specified file.

Parameters

string $key

The key (path) of the file.

Throws

\InvalidArgumentException

If $key is invalid.

Returns

string —

The MIME type of the file.

isDirectory()

isDirectory(string  $key) : bool

Check if the specified key represents a directory.

Parameters

string $key

The key (path) to check.

Returns

bool —

TRUE if the key represents a directory, FALSE otherwise.