File
extends AbstractFile
in package
Class File
Table of Contents
Methods
- __clone() : void
- __construct() : mixed
- __destruct() : mixed
- Unlock file when the object gets destroyed.
- __serialize() : array<string|int, mixed>
- __unserialize() : void
- 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.
- serialize() : string
- unlock() : bool
- Unlock file after writing.
- unserialize() : void
- doSerialize() : array<string|int, mixed>
- doUnserialize() : void
- getUnserializeAllowedClasses() : array<string|int, mixed>|bool
- setFilepath() : void
- setPathInfo() : void
- tempname() : string
Methods
__clone()
public
__clone() : void
Attributes
- #[ReturnTypeWillChange]
__construct()
public
__construct(string $filepath[, Filesystem|null $filesystem = null ]) : mixed
Parameters
- $filepath : string
- $filesystem : Filesystem|null = null
__destruct()
Unlock file when the object gets destroyed.
public
__destruct() : mixed
Attributes
- #[ReturnTypeWillChange]
__serialize()
public
final __serialize() : array<string|int, mixed>
Return values
array<string|int, mixed>__unserialize()
public
final __unserialize(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
delete()
Delete file from filesystem.
public
delete() : bool
Tags
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
Tags
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
Tags
Return values
string —Returns basename of the file.
getCreationTime()
Get file creation time.
public
getCreationTime() : int
Tags
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).
Tags
Return values
string —Returns file extension of the file (can be empty).
getFilename()
Get filename of the file.
public
getFilename() : string
Tags
Return values
string —Returns name of the file.
getFilePath()
Get both path and filename of the file.
public
getFilePath() : string
Tags
Return values
string —Returns path and filename in the filesystem. Can also be URI.
getModificationTime()
Get file modification time.
public
getModificationTime() : int
Tags
Return values
int —Returns Unix timestamp. If file does not exist, method returns current time.
getPath()
Get path of the file.
public
getPath() : string
Tags
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
Tags
Return values
bool —Returns true if the file is locked, false otherwise.
isReadable()
Check if file exists and can be read.
public
isReadable() : bool
Tags
Return values
bool —Returns true if the file can be read, false otherwise.
isWritable()
Check if file can be written.
public
isWritable() : bool
Tags
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
Tags
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
Parameters
- $path : string
-
New path and filename for the file. Can also be URI.
Tags
Return values
bool —Returns true if the file was successfully renamed, false otherwise.
save()
Save file.
public
save(mixed $data) : void
Parameters
- $data : mixed
-
Data to be saved.
Tags
serialize()
public
final serialize() : string
Return values
stringunlock()
Unlock file after writing.
public
unlock() : bool
Tags
Return values
bool —Returns true if the file was successfully unlocked, false otherwise.
unserialize()
public
final unserialize(string $serialized) : void
Parameters
- $serialized : string
doSerialize()
protected
doSerialize() : array<string|int, mixed>
Return values
array<string|int, mixed>doUnserialize()
protected
doUnserialize(array<string|int, mixed> $serialized) : void
Parameters
- $serialized : array<string|int, mixed>
getUnserializeAllowedClasses()
protected
getUnserializeAllowedClasses() : array<string|int, mixed>|bool
Return values
array<string|int, mixed>|boolsetFilepath()
protected
setFilepath(string $filepath) : void
Parameters
- $filepath : string
setPathInfo()
protected
setPathInfo() : void
tempname()
protected
tempname(string $filename[, int $length = 5 ]) : string
Parameters
- $filename : string
- $length : int = 5