Filesystem
extends Filesystem
in package
File helper
Tags
Table of Contents
- $filePermissions : string
- $folderPermissions : string
- $pathSymbols : array<string|int, mixed>
- $macros : array<string|int, mixed>
- The registered string macros.
- __call() : mixed
- Dynamically handle calls to the class.
- __callStatic() : mixed
- Dynamically handle calls to the class.
- allFiles() : array<string|int, SplFileInfo>
- Get all of the files from the given directory (recursive).
- append() : int
- Append to a file.
- basename() : string
- Extract the trailing name component from a file path.
- chmod() : void
- Modify file/folder permissions
- chmodRecursive() : void
- Modify file/folder permissions recursively
- cleanDirectory() : bool
- Empty the specified directory of all files and folders.
- copy() : bool
- Copy a file to a new location.
- copyDirectory() : bool
- Copy a directory from one location to another.
- delete() : bool
- Delete the file at a given path.
- deleteDirectory() : bool
- Recursively delete a directory.
- directories() : array<string|int, mixed>
- Get all of the directories within a given directory.
- dirname() : string
- Extract the parent directory from a file path.
- exists() : bool
- Determine if a file or directory exists.
- existsInsensitive() : mixed
- Determine if a file exists with case insensitivity supported for the file only.
- extension() : string
- Extract the file extension from a file path.
- fileNameMatch() : bool
- Match filename against a pattern.
- files() : array<string|int, SplFileInfo>
- Get an array of all files in a directory.
- fromClass() : string
- Finds the path to a class
- get() : string
- Get the contents of a file.
- getFilePermissions() : string
- Returns the default file permission mask to use.
- getFolderPermissions() : string
- Returns the default folder permission mask to use.
- getRequire() : mixed
- Get the returned value of a file.
- glob() : array<string|int, mixed>
- Find path names matching a given pattern.
- hash() : string
- Get the MD5 hash of the file at the given path.
- hasMacro() : bool
- Checks if macro is registered.
- isDirectory() : bool
- Determine if the given path is a directory.
- isDirectoryEmpty() : bool
- Determine if the given path contains no files.
- isFile() : bool
- Determine if the given path is a file.
- isLocalPath() : bool
- Returns true if the specified path is within the path of the application
- isPathSymbol() : bool
- Returns true if the path uses a symbol.
- isReadable() : bool
- Determine if the given path is readable.
- isWritable() : bool
- Determine if the given path is writable.
- lastModified() : int
- Get the file's last modification time.
- link() : void
- Create a hard link to the target file or directory.
- localToPublic() : string
- Returns a public file path from an absolute one eg: /home/mysite/public_html/welcome -> /welcome
- macro() : void
- Register a custom macro.
- makeDirectory() : bool
- Create a directory.
- mimeType() : string|false
- Get the mime-type of a given file.
- mixin() : void
- Mix another object into the class.
- move() : bool
- Move a file to a new location.
- moveDirectory() : bool
- Move a directory.
- name() : string
- Extract the file name from a file path.
- normalizePath() : string
- Normalizes the directory separator, often used by Win systems.
- prepend() : int
- Prepend to a file.
- put() : int
- Write the contents of a file.
- requireOnce() : mixed
- Require the given file once.
- sharedGet() : string
- Get contents of a file with shared access.
- size() : int
- Get the file size of a given file.
- sizeToString() : string
- Converts a file size in bytes to human readable format.
- symbolizePath() : string
- Converts a path using path symbol. Returns the original path if no symbol is used and no default is specified.
- type() : string
- Get the file type of a given file.
Properties
$filePermissions
public
string
$filePermissions
= null
Default file permission mask as a string ("777").
$folderPermissions
public
string
$folderPermissions
= null
Default folder permission mask as a string ("777").
$pathSymbols
public
array<string|int, mixed>
$pathSymbols
= []
Known path symbols and their prefixes.
$macros
The registered string macros.
protected
static array<string|int, mixed>
$macros
= []
Methods
__call()
Dynamically handle calls to the class.
public
__call(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
- $method : string
- $parameters : array<string|int, mixed>
Tags
Return values
mixed —__callStatic()
Dynamically handle calls to the class.
public
static __callStatic(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
- $method : string
- $parameters : array<string|int, mixed>
Tags
Return values
mixed —allFiles()
Get all of the files from the given directory (recursive).
public
allFiles(string $directory[, bool $hidden = false ]) : array<string|int, SplFileInfo>
Parameters
- $directory : string
- $hidden : bool = false
Return values
array<string|int, SplFileInfo> —append()
Append to a file.
public
append(string $path, string $data) : int
Parameters
- $path : string
- $data : string
Return values
int —basename()
Extract the trailing name component from a file path.
public
basename(string $path) : string
Parameters
- $path : string
Return values
string —chmod()
Modify file/folder permissions
public
chmod(string $path[, octal $mask = null ]) : void
Parameters
- $path : string
- $mask : octal = null
Return values
void —chmodRecursive()
Modify file/folder permissions recursively
public
chmodRecursive(string $path[, octal $fileMask = null ][, octal $directoryMask = null ]) : void
Parameters
- $path : string
- $fileMask : octal = null
- $directoryMask : octal = null
Return values
void —cleanDirectory()
Empty the specified directory of all files and folders.
public
cleanDirectory(string $directory) : bool
Parameters
- $directory : string
Return values
bool —copy()
Copy a file to a new location.
public
copy(string $path, string $target) : bool
Parameters
- $path : string
- $target : string
Return values
bool —copyDirectory()
Copy a directory from one location to another.
public
copyDirectory(string $directory, string $destination[, int $options = null ]) : bool
Parameters
- $directory : string
- $destination : string
- $options : int = null
Return values
bool —delete()
Delete the file at a given path.
public
delete(string|array<string|int, mixed> $paths) : bool
Parameters
- $paths : string|array<string|int, mixed>
Return values
bool —deleteDirectory()
Recursively delete a directory.
public
deleteDirectory(string $directory[, bool $preserve = false ]) : bool
The directory itself may be optionally preserved.
Parameters
- $directory : string
- $preserve : bool = false
Return values
bool —directories()
Get all of the directories within a given directory.
public
directories(string $directory) : array<string|int, mixed>
Parameters
- $directory : string
Return values
array<string|int, mixed> —dirname()
Extract the parent directory from a file path.
public
dirname(string $path) : string
Parameters
- $path : string
Return values
string —exists()
Determine if a file or directory exists.
public
exists(string $path) : bool
Parameters
- $path : string
Return values
bool —existsInsensitive()
Determine if a file exists with case insensitivity supported for the file only.
public
existsInsensitive(string $path) : mixed
Parameters
- $path : string
Return values
mixed —Sensitive path or false
extension()
Extract the file extension from a file path.
public
extension(string $path) : string
Parameters
- $path : string
Return values
string —fileNameMatch()
Match filename against a pattern.
public
fileNameMatch(string|array<string|int, mixed> $fileName, string $pattern) : bool
Parameters
- $fileName : string|array<string|int, mixed>
- $pattern : string
Return values
bool —files()
Get an array of all files in a directory.
public
files(string $directory[, bool $hidden = false ]) : array<string|int, SplFileInfo>
Parameters
- $directory : string
- $hidden : bool = false
Return values
array<string|int, SplFileInfo> —fromClass()
Finds the path to a class
public
fromClass(mixed $className) : string
Parameters
- $className : mixed
-
Class name or object
Return values
string —The file path
get()
Get the contents of a file.
public
get(string $path[, bool $lock = false ]) : string
Parameters
- $path : string
- $lock : bool = false
Tags
Return values
string —getFilePermissions()
Returns the default file permission mask to use.
public
getFilePermissions() : string
Return values
string —Permission mask as octal (0777) or null
getFolderPermissions()
Returns the default folder permission mask to use.
public
getFolderPermissions() : string
Return values
string —Permission mask as octal (0777) or null
getRequire()
Get the returned value of a file.
public
getRequire(string $path) : mixed
Parameters
- $path : string
Tags
Return values
mixed —glob()
Find path names matching a given pattern.
public
glob(string $pattern, int $flags) : array<string|int, mixed>
Parameters
- $pattern : string
- $flags : int
Return values
array<string|int, mixed> —hash()
Get the MD5 hash of the file at the given path.
public
hash(string $path) : string
Parameters
- $path : string
Return values
string —hasMacro()
Checks if macro is registered.
public
static hasMacro(string $name) : bool
Parameters
- $name : string
Return values
bool —isDirectory()
Determine if the given path is a directory.
public
isDirectory(string $directory) : bool
Parameters
- $directory : string
Return values
bool —isDirectoryEmpty()
Determine if the given path contains no files.
public
isDirectoryEmpty(string $directory) : bool
Parameters
- $directory : string
Return values
bool —isFile()
Determine if the given path is a file.
public
isFile(string $file) : bool
Parameters
- $file : string
Return values
bool —isLocalPath()
Returns true if the specified path is within the path of the application
public
isLocalPath(string $path[, bool $realpath = true ]) : bool
Parameters
- $path : string
-
The path to
- $realpath : bool = true
-
Default true, uses realpath() to resolve the provided path before checking location. Set to false if you need to check if a potentially non-existent path would be within the application path
Return values
bool —isPathSymbol()
Returns true if the path uses a symbol.
public
isPathSymbol(string $path) : bool
Parameters
- $path : string
Return values
bool —isReadable()
Determine if the given path is readable.
public
isReadable(string $path) : bool
Parameters
- $path : string
Return values
bool —isWritable()
Determine if the given path is writable.
public
isWritable(string $path) : bool
Parameters
- $path : string
Return values
bool —lastModified()
Get the file's last modification time.
public
lastModified(string $path) : int
Parameters
- $path : string
Return values
int —link()
Create a hard link to the target file or directory.
public
link(string $target, string $link) : void
Parameters
- $target : string
- $link : string
Return values
void —localToPublic()
Returns a public file path from an absolute one eg: /home/mysite/public_html/welcome -> /welcome
public
localToPublic(string $path) : string
Parameters
- $path : string
-
Absolute path
Return values
string —macro()
Register a custom macro.
public
static macro(string $name, object|callable $macro) : void
Parameters
- $name : string
- $macro : object|callable
Return values
void —makeDirectory()
Create a directory.
public
makeDirectory(string $path[, int $mode = 0777 ][, bool $recursive = false ][, bool $force = false ]) : bool
Parameters
- $path : string
- $mode : int = 0777
- $recursive : bool = false
- $force : bool = false
Return values
bool —mimeType()
Get the mime-type of a given file.
public
mimeType(string $path) : string|false
Parameters
- $path : string
Return values
string|false —mixin()
Mix another object into the class.
public
static mixin(object $mixin) : void
Parameters
- $mixin : object
Return values
void —move()
Move a file to a new location.
public
move(string $path, string $target) : bool
Parameters
- $path : string
- $target : string
Return values
bool —moveDirectory()
Move a directory.
public
moveDirectory(string $from, string $to[, bool $overwrite = false ]) : bool
Parameters
- $from : string
- $to : string
- $overwrite : bool = false
Return values
bool —name()
Extract the file name from a file path.
public
name(string $path) : string
Parameters
- $path : string
Return values
string —normalizePath()
Normalizes the directory separator, often used by Win systems.
public
normalizePath(string $path) : string
Parameters
- $path : string
-
Path name
Return values
string —Normalized path
prepend()
Prepend to a file.
public
prepend(string $path, string $data) : int
Parameters
- $path : string
- $data : string
Return values
int —put()
Write the contents of a file.
public
put(string $path, string $contents[, mixed $lock = false ]) : int
Parameters
- $path : string
- $contents : string
- $lock : mixed = false
Return values
int —requireOnce()
Require the given file once.
public
requireOnce(string $file) : mixed
Parameters
- $file : string
Return values
mixed —sharedGet()
Get contents of a file with shared access.
public
sharedGet(string $path) : string
Parameters
- $path : string
Return values
string —size()
Get the file size of a given file.
public
size(string $path) : int
Parameters
- $path : string
Return values
int —sizeToString()
Converts a file size in bytes to human readable format.
public
sizeToString(int $bytes) : string
Parameters
- $bytes : int
Return values
string —symbolizePath()
Converts a path using path symbol. Returns the original path if no symbol is used and no default is specified.
public
symbolizePath(string $path[, mixed $default = false ]) : string
Parameters
- $path : string
- $default : mixed = false
Return values
string —type()
Get the file type of a given file.
public
type(string $path) : string
Parameters
- $path : string