class Filesystem extends Filesystem

File helper

Properties

string $filePermissions
string $folderPermissions
array $pathSymbols

Methods

bool
isDirectoryEmpty(string $directory)

Determine if the given path contains no files.

string
sizeToString(int $bytes)

Converts a file size in bytes to human readable format.

string
localToPublic(string $path)

Returns a public file path from an absolute one eg: /home/mysite/public_html/welcome -> /welcome

bool
isLocalPath(string $path)

Returns true if the specified path is an absolute/local path to the application.

string
fromClass(mixed $className)

Finds the path to a class

mixed
existsInsensitive(string $path)

Determine if a file exists with case insensitivity supported for the file only.

string
normalizePath(string $path)

Normalizes the directory separator, often used by Win systems.

string
symbolizePath(string $path, mixed $default = false)

Converts a path using path symbol. Returns the original path if no symbol is used and no default is specified.

bool
isPathSymbol(string $path)

Returns true if the path uses a symbol.

int
put(string $path, string $contents, bool $lock = false)

Write the contents of a file.

bool
copy(string $path, string $target)

Copy a file to a new location.

bool
makeDirectory(string $path, int $mode = 0777, bool $recursive = false, bool $force = false)

Create a directory.

void
chmod(string $path, int|null $mask = null)

Modify file/folder permissions

void
chmodRecursive(string $path, string|null $fileMask = null, string|null $directoryMask = null)

Modify file/folder permissions recursively

string
getFilePermissions()

Returns the default file permission mask to use.

string
getFolderPermissions()

Returns the default folder permission mask to use.

bool
fileNameMatch(string|array $fileName, string $pattern)

Match filename against a pattern.

Details

at line 36
bool isDirectoryEmpty(string $directory)

Determine if the given path contains no files.

Parameters

string $directory directory

Return Value

bool

at line 60
string sizeToString(int $bytes)

Converts a file size in bytes to human readable format.

Parameters

int $bytes bytes

Return Value

string

at line 91
string localToPublic(string $path)

Returns a public file path from an absolute one eg: /home/mysite/public_html/welcome -> /welcome

Parameters

string $path

Absolute path

Return Value

string

at line 109
bool isLocalPath(string $path)

Returns true if the specified path is an absolute/local path to the application.

Parameters

string $path path

Return Value

bool

at line 120
string fromClass(mixed $className)

Finds the path to a class

Parameters

mixed $className

Class name or object

Return Value

string

The file path

Exceptions

ReflectionException

at line 133
mixed existsInsensitive(string $path)

Determine if a file exists with case insensitivity supported for the file only.

Parameters

string $path path

Return Value

mixed

Sensitive path or false

at line 160
string normalizePath(string $path)

Normalizes the directory separator, often used by Win systems.

Parameters

string $path

Path name

Return Value

string

Normalized path

at line 172
string symbolizePath(string $path, mixed $default = false)

Converts a path using path symbol. Returns the original path if no symbol is used and no default is specified.

Parameters

string $path path
mixed $default default

Return Value

string

at line 188
bool isPathSymbol(string $path)

Returns true if the path uses a symbol.

Parameters

string $path path

Return Value

bool

at line 205
int put(string $path, string $contents, bool $lock = false)

Write the contents of a file.

Parameters

string $path path
string $contents contents
bool $lock lock

Return Value

int

at line 219
bool copy(string $path, string $target)

Copy a file to a new location.

Parameters

string $path path
string $target contents

Return Value

bool

at line 235
bool makeDirectory(string $path, int $mode = 0777, bool $recursive = false, bool $force = false)

Create a directory.

Parameters

string $path path
int $mode mode
bool $recursive recursive
bool $force force

Return Value

bool

at line 281
void chmod(string $path, int|null $mask = null)

Modify file/folder permissions

Parameters

string $path path
int|null $mask mask

Return Value

void

at line 303
void chmodRecursive(string $path, string|null $fileMask = null, string|null $directoryMask = null)

Modify file/folder permissions recursively

Parameters

string $path path
string|null $fileMask fileMask
string|null $directoryMask directoryMask

Return Value

void

at line 339
string getFilePermissions()

Returns the default file permission mask to use.

Return Value

string

Permission mask as octal (0777) or null

at line 350
string getFolderPermissions()

Returns the default folder permission mask to use.

Return Value

string

Permission mask as octal (0777) or null

at line 363
bool fileNameMatch(string|array $fileName, string $pattern)

Match filename against a pattern.

Parameters

string|array $fileName fileName
string $pattern pattern

Return Value

bool