class Wrapper

internal  
 

Provides isolation for thread safe file manipulation using stream nette.safe://

file_put_contents('nette.safe://myfile.txt', $content);

$content = file_get_contents('nette.safe://myfile.txt');

unlink('nette.safe://myfile.txt');

Constants

Protocol

Name of stream protocol - nette.safe://

PROTOCOL

Properties

?resource $context

Methods

static bool
register()

Registers protocol 'nette.safe://'.

bool
stream_open(string $path, string $mode, int $options)

Opens the file and acquires the appropriate lock (LOCK_SH for reading, LOCK_EX for writing).

void
stream_close()

Releases the lock and closes the file. Truncates back to $startPos if a write error occurred.

string|false
stream_read(int $length)

No description

int|false
stream_write(string $data)

Writes data to the file. Sets the write-error flag if fewer bytes than expected were written.

bool
stream_truncate(int $size)

Truncates a file to a given length.

int
stream_tell()

Returns the position of the file.

bool
stream_eof()

Returns true if the file pointer is at end-of-file.

bool
stream_seek(int $offset, int $whence = SEEK_SET)

Sets the file position indicator for the file.

array|false
stream_stat()

Gets information about a file referenced by $this->handle.

array|false
url_stat(string $path, int $flags)

Returns file information for the given path. Not thread-safe.

bool
unlink(string $path)

Deletes a file. On Windows, fails if the file is currently open.

bool
stream_set_option(int $option, int $arg1, int $arg2)

Required since PHP 7.4 when the wrapper is used for includes; always returns false.

Details

at line 47
static bool register()

Registers protocol 'nette.safe://'.

Return Value

bool

at line 62
bool stream_open(string $path, string $mode, int $options)

Opens the file and acquires the appropriate lock (LOCK_SH for reading, LOCK_EX for writing).

Converts 'w' mode to 'c' to avoid truncation before the lock is held, then truncates manually. For reads, retries up to 100 times if the file is empty (another thread may be writing).

Parameters

string $path
string $mode
int $options

Return Value

bool

at line 100
void stream_close()

Releases the lock and closes the file. Truncates back to $startPos if a write error occurred.

Return Value

void

at line 112
string|false stream_read(int $length)

No description

Parameters

int $length

Return Value

string|false

at line 121
int|false stream_write(string $data)

Writes data to the file. Sets the write-error flag if fewer bytes than expected were written.

Parameters

string $data

Return Value

int|false

at line 138
bool stream_truncate(int $size)

Truncates a file to a given length.

Parameters

int $size

Return Value

bool

at line 147
int stream_tell()

Returns the position of the file.

Return Value

int

at line 156
bool stream_eof()

Returns true if the file pointer is at end-of-file.

Return Value

bool

at line 165
bool stream_seek(int $offset, int $whence = SEEK_SET)

Sets the file position indicator for the file.

Parameters

int $offset
int $whence

Return Value

bool

at line 175
array|false stream_stat()

Gets information about a file referenced by $this->handle.

Return Value

array|false

at line 185
array|false url_stat(string $path, int $flags)

Returns file information for the given path. Not thread-safe.

Parameters

string $path
int $flags

Return Value

array|false

Deletes a file. On Windows, fails if the file is currently open.

Parameters

string $path

Return Value

bool

at line 206
bool stream_set_option(int $option, int $arg1, int $arg2)

Required since PHP 7.4 when the wrapper is used for includes; always returns false.

Parameters

int $option
int $arg1
int $arg2

Return Value

bool