Documentation

FileInterface extends Serializable

Defines common interface for all file readers.

File readers allow you to read and optionally write files of various file formats, such as:

Tags
used-by

\Grav\Framework\File\CsvFile CVS

used-by

\Grav\Framework\File\JsonFile JSON

used-by

\Grav\Framework\File\MarkdownFile Markdown

used-by

\Grav\Framework\File\SerializeFile Serialized PHP

used-by

\Grav\Framework\File\YamlFile YAML

since
1.6

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
APIYes
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
APIYes
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
APIYes
Return values
string

Returns basename of the file.

getCreationTime()

Get file creation time.

public getCreationTime() : int
APIYes
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
APIYes
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
APIYes
Return values
string

Returns name of the file.

getFilePath()

Get both path and filename of the file.

public getFilePath() : string
APIYes
Return values
string

Returns path and filename in the filesystem. Can also be URI.

getModificationTime()

Get file modification time.

public getModificationTime() : int
APIYes
Return values
int

Returns Unix timestamp. If file does not exist, method returns current time.

getPath()

Get path of the file.

public getPath() : string
APIYes
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
APIYes
Return values
bool

Returns true if the file is locked, false otherwise.

isReadable()

Check if file exists and can be read.

public isReadable() : bool
APIYes
Return values
bool

Returns true if the file can be read, false otherwise.

isWritable()

Check if file can be written.

public isWritable() : bool
APIYes
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
APIYes
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
APIYes
Parameters
$block : bool = true

For non-blocking lock, set the parameter to false.

Tags
throws
RuntimeException
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
APIYes

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
APIYes

See supported data format for each of the file format.

Parameters
$data : mixed

Data to be saved.

Tags
throws
RuntimeException

unlock()

Unlock file after writing.

public unlock() : bool
APIYes
Return values
bool

Returns true if the file was successfully unlocked, false otherwise.


        
On this page

Search results