\Omega\Filesystem\Adapter\Memory InMemory

InMemory Adapter for Filesystem.

This class provides an in-memory file storage system, allowing for the temporary storage and management of files. It is primarily used for testing purposes where persistence is not required. All files are stored in memory, making it a lightweight and fast alternative to file-based storage solutions.

Summary

Methods
Properties
Constants
__construct
setFiles
setFile
read
rename
write
exists
keys
mtime
delete
isDirectory
mimeType
No public properties found
No public constants found
No protected methods found
files
No protected constants found
No private methods found
No private properties found
No private constants found

Properties

$files

$files : array

Type

array<string|int, mixed>

Methods

__construct()

__construct(array  $files = []) : void

Constructor for the InMemory adapter.

Initializes the in-memory filesystem adapter with an optional array of files. The provided files can be in the form of strings or associative arrays containing 'content' and optional 'mtime' (last modified time). If no files are provided, the adapter will start with an empty file storage.

Parameters

array $files

An optional array of files to initialize the adapter with. Each file can be represented as a string or an associative array with 'content' and optional 'mtime'.

Returns

void —

setFiles()

setFiles(array  $files) : void

Defines the files stored in memory.

Parameters

array $files

An array of files to store in memory. Each file can be represented as a string or an associative array with 'content' and optional 'mtime' (modification time).

Returns

void —

setFile()

setFile(string  $key, string|null  $content = null, int|null  $mtime = null) : void

Defines a single file in memory.

Parameters

string $key

The unique key for the file.

string|null $content

The content of the file.

int|null $mtime

The last modified time (automatically set to now if NULL).

Returns

void —

read()

read(string  $key) : string|bool

Reads the content of the file.

Parameters

string $key

The key or path of the file to read.

Returns

string|bool —

The content of the file or false if it cannot be read.

rename()

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

Renames a file.

Parameters

string $sourceKey

The current key or path of the file.

string $targetKey

The new key or path for the file.

Returns

bool —

True on success, false on failure.

write()

write(string  $key, string  $content, array  $metadata = null) : int|bool

Writes the given content into the file.

Parameters

string $key

The key or path of the file to write.

string $content

The content to write into the file.

array $metadata

Returns

int|bool —

The number of bytes written or false on failure.

exists()

exists(string  $key) : bool

Indicates whether the file exists.

Parameters

string $key

The key or path of the file to check.

Returns

bool —

True if the file exists, false otherwise.

keys()

keys() : array

Returns an array of all keys (files and directories).

Returns

array —

The list of keys.

mtime()

mtime(string  $key) : int|bool

Returns the last modified time.

Parameters

string $key

The key or path of the file.

Returns

int|bool —

The last modified time as a UNIX timestamp, or false on failure.

delete()

delete(string  $key) : bool

Deletes the file.

Parameters

string $key

The key or path of the file to delete.

Returns

bool —

True on success, false on failure.

isDirectory()

isDirectory(string  $key) : bool

Check if the key represents a directory.

Parameters

string $key

The key or path to check.

Returns

bool —

True if the key is a directory, false otherwise.

mimeType()

mimeType(string  $key) : string|false

Retrieves the MIME type of the specified file (key).

Parameters

string $key

The file key for which the MIME type is being retrieved.

Returns

string|false —

The MIME type of the file, or false if it cannot be determined.