class LockableFile

Properties

protected resource $handle

The file resource.

protected string $path

The file path.

protected bool $isLocked

Indicates if the file is locked.

Methods

__construct(string $path, string $mode)

Create a new File instance.

void
ensureDirectoryExists(string $path)

Create the file's directory if necessary.

void
createResource(string $path, string $mode)

Create the file resource.

string
read(int|null $length = null)

Read the file contents.

int
size()

Get the file size.

bool
wasDeleted()

Determine whether the open file has been unlinked.

write(string $contents)

Write to the file.

truncate()

Truncate the file.

getSharedLock(bool $block = false)

Get a shared lock on the file.

getExclusiveLock(bool $block = false)

Get an exclusive lock on the file.

releaseLock()

Release the lock on the file.

bool
close()

Close the file.

Details

at line 34
__construct(string $path, string $mode)

Create a new File instance.

Parameters

string $path
string $mode

at line 45
protected void ensureDirectoryExists(string $path)

Create the file's directory if necessary.

Parameters

string $path

Return Value

void

at line 59
protected void createResource(string $path, string $mode)

Create the file resource.

Parameters

string $path
string $mode

Return Value

void

Exceptions

RuntimeException

at line 73
string read(int|null $length = null)

Read the file contents.

Parameters

int|null $length

Return Value

string

at line 87
int size()

Get the file size.

Return Value

int

at line 101
bool wasDeleted()

Determine whether the open file has been unlinked.

Return Value

bool

at line 117
LockableFile write(string $contents)

Write to the file.

Parameters

string $contents

Return Value

LockableFile

at line 141
LockableFile truncate()

Truncate the file.

Return Value

LockableFile

at line 161
LockableFile getSharedLock(bool $block = false)

Get a shared lock on the file.

Parameters

bool $block

Return Value

LockableFile

Exceptions

LockTimeoutException

at line 179
LockableFile getExclusiveLock(bool $block = false)

Get an exclusive lock on the file.

Parameters

bool $block

Return Value

LockableFile

Exceptions

LockTimeoutException

at line 195
LockableFile releaseLock()

Release the lock on the file.

Return Value

LockableFile

at line 209
bool close()

Close the file.

Return Value

bool