FileInterface
extends
Serializable
in
Defines common interface for all file readers.
File readers allow you to read and optionally write files of various file formats, such as:
Tags
Table of Contents
Methods
- delete() : bool
- Delete file from filesystem.
- exists() : bool
- Check if the file exits in the filesystem.
- getBasename() : string
- Get basename of the file (filename without the associated file extension).
- getCreationTime() : int
- Get file creation time.
- getExtension() : string
- Get file extension of the file.
- getFilename() : string
- Get filename of the file.
- getFilePath() : string
- Get both path and filename of the file.
- getModificationTime() : int
- Get file modification time.
- getPath() : string
- Get path of the file.
- isLocked() : bool
- Returns true if file has been locked by you for writing.
- isReadable() : bool
- Check if file exists and can be read.
- isWritable() : bool
- Check if file can be written.
- load() : string|array<string|int, mixed>|object|false
- (Re)Load a file and return file contents.
- lock() : bool
- Lock file for writing. You need to manually call unlock().
- rename() : bool
- Rename file in the filesystem if it exists.
- save() : void
- Save file.
- unlock() : bool
- Unlock file after writing.
Methods
delete()
Delete file from filesystem.
public
delete() : bool
Return values
bool —Returns true if the file was successfully deleted, false otherwise.
exists()
Check if the file exits in the filesystem.
public
exists() : bool
Return values
bool —Returns true if the filename exists and is a regular file, false otherwise.
getBasename()
Get basename of the file (filename without the associated file extension).
public
getBasename() : string
Return values
string —Returns basename of the file.
getCreationTime()
Get file creation time.
public
getCreationTime() : int
Return values
int —Returns Unix timestamp. If file does not exist, method returns current time.
getExtension()
Get file extension of the file.
public
getExtension([bool $withDot = false ]) : string
Parameters
- $withDot : bool = false
-
If true, return file extension with beginning dot (.json).
Return values
string —Returns file extension of the file (can be empty).
getFilename()
Get filename of the file.
public
getFilename() : string
Return values
string —Returns name of the file.
getFilePath()
Get both path and filename of the file.
public
getFilePath() : string
Return values
string —Returns path and filename in the filesystem. Can also be URI.
getModificationTime()
Get file modification time.
public
getModificationTime() : int
Return values
int —Returns Unix timestamp. If file does not exist, method returns current time.
getPath()
Get path of the file.
public
getPath() : string
Return values
string —Returns path in the filesystem. Can also be URI.
isLocked()
Returns true if file has been locked by you for writing.
public
isLocked() : bool
Return values
bool —Returns true if the file is locked, false otherwise.
isReadable()
Check if file exists and can be read.
public
isReadable() : bool
Return values
bool —Returns true if the file can be read, false otherwise.
isWritable()
Check if file can be written.
public
isWritable() : bool
Return values
bool —Returns true if the file can be written, false otherwise.
load()
(Re)Load a file and return file contents.
public
load() : string|array<string|int, mixed>|object|false
Return values
string|array<string|int, mixed>|object|false —Returns file content or false if file couldn't be read.
lock()
Lock file for writing. You need to manually call unlock().
public
lock([bool $block = true ]) : bool
Parameters
- $block : bool = true
-
For non-blocking lock, set the parameter to
false.
Tags
Return values
bool —Returns true if the file was successfully locked, false otherwise.
rename()
Rename file in the filesystem if it exists.
public
rename(string $path) : bool
Target folder will be created if if did not exist.
Parameters
- $path : string
-
New path and filename for the file. Can also be URI.
Return values
bool —Returns true if the file was successfully renamed, false otherwise.
save()
Save file.
public
save(mixed $data) : void
See supported data format for each of the file format.
Parameters
- $data : mixed
-
Data to be saved.
Tags
unlock()
Unlock file after writing.
public
unlock() : bool
Return values
bool —Returns true if the file was successfully unlocked, false otherwise.