class FileHandler

User as file handle by streamWrapper implementation.

This class is responsible mainly for managing the pointer position during reading and writing.

Constants

READ_MODE

WRITE_MODE

Methods

setFile(File $file)

Sets file in context.

int
write(string $data)

Writes data to file. Will return the number of bytes written. Will advance pointer by number of bytes written.

string
read(int $bytes)

Will read and return $bytes bytes from file. Will advance pointer by $bytes bytes.

int
position(integer|null $position = null)

Returns current pointer position.

int
seekToEnd()

Moves pointer to the end of file (for append modes).

offsetPosition(int $offset)

Offsets position by $offset

bool
atEof()

Tells whether pointer is at the end of file.

void
truncate(int $newSize)

Removed all data from file and sets pointer to 0

setReadOnlyMode()

Sets handler to read only

setReadWriteMode()

Sets handler into read/write mode

setWriteOnlyMode()

No description

bool
isOpenedForWriting()

Checks if pointer allows writing

bool
isOpenedForReading()

Checks if pointer allows reading

lock($resource, $operation)

No description

Details

at line 42
setFile(File $file)

Sets file in context.

Parameters

File $file

at line 54
int write(string $data)

Writes data to file. Will return the number of bytes written. Will advance pointer by number of bytes written.

Parameters

string $data

Return Value

int

at line 75
string read(int $bytes)

Will read and return $bytes bytes from file. Will advance pointer by $bytes bytes.

Parameters

int $bytes

Return Value

string

at line 98
int position(integer|null $position = null)

Returns current pointer position.

Parameters

integer|null $position

Return Value

int

at line 108
int seekToEnd()

Moves pointer to the end of file (for append modes).

Return Value

int

at line 118
offsetPosition(int $offset)

Offsets position by $offset

Parameters

int $offset

at line 128
bool atEof()

Tells whether pointer is at the end of file.

Return Value

bool

at line 140
void truncate(int $newSize)

Removed all data from file and sets pointer to 0

Parameters

int $newSize

Return Value

void

at line 155
setReadOnlyMode()

Sets handler to read only

at line 163
setReadWriteMode()

Sets handler into read/write mode

at line 168
setWriteOnlyMode()

at line 178
bool isOpenedForWriting()

Checks if pointer allows writing

Return Value

bool

at line 188
bool isOpenedForReading()

Checks if pointer allows reading

Return Value

bool

at line 196
lock($resource, $operation)

Parameters

$resource
$operation