Filesystem

File helper

 class Winter\Storm\Filesystem\Filesystem
extends Illuminate\Filesystem\Filesystem

Properties

public $filePermissions : string | null

Default file permission mask as a string ("777").

public $folderPermissions : string | null

Default folder permission mask as a string ("777").

public $pathSymbols : array

Known path symbols and their prefixes.

protected $symlinks : array | null

Symlinks within base folder

Methods

public chmod (string $path, int | float | null $mask = null) : bool

Modify file/folder permissions.

Parameters
Property Description
$path
string
$mask
int | float | null
Returns
bool

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

Modify file/folder permissions recursively in a given path.

Parameters
Property Description
$path
string
$fileMask
mixed
$directoryMask
mixed
Returns
void

public copy (string $path, string $target) : bool

Copy a file to a new location.

This method will also set the permissions based on the given chmod() mask in use.

Returns true if successful, or false on failure.

Parameters
Property Description
$path
string
$target
string
Returns
bool

public existsInsensitive (string $path) : string | false

Determines if a file exists (ignoring the case for the filename only).

Parameters
Property Description
$path
string
Returns
string | false

public fileNameMatch (string $fileName, string $pattern) : bool

Match filename against a pattern.

Parameters
Property Description
$fileName
string
$pattern
string
Returns
bool

public fromClass (string | object $className) : string | false

Finds the path of a given class.

Returns false if the path cannot be determined.

Parameters
Property Description
$className
string | object

Class name or object

Returns
string | false

public getFilePermissions () : integer | float | null

Returns the default file permission mask to use.

Returns
integer | float | null

public getFolderPermissions () : integer | float | null

Returns the default folder permission mask to use.

Returns
integer | float | null

public isAbsolutePath (string $file) : bool

Returns whether the file path is an absolute path.

Parameters
Property Description
$file
string
Returns
bool

public isDirectoryEmpty (string $directory) : bool | null

Determine if the given path contains no files.

Returns a boolean regarding if the directory is empty or not. If the directory does not exist or is not readable, this method will return null.

Parameters
Property Description
$directory
string
Returns
bool | null

public isLocalDisk (Illuminate\Filesystem\FilesystemAdapter $disk) : bool

Determines if the given disk is using the "local" driver.

Parameters
Property Description
$disk
Illuminate\Filesystem\FilesystemAdapter
Returns
bool

public isLocalPath (string $path, boolean $realpath = true) : bool

Determines if the given path is a local path.

Returns true if the path is local, false otherwise.

Parameters
Property Description
$path
string

The path to check

$realpath
boolean

If true (default), the realpath() method will be used to resolve symlinks before checking if the path is local. Set to false if you are looking up non-existent paths.

Returns
bool

public isPathSymbol (string $path) : bool

Determines if the given path is using a path symbol.

Parameters
Property Description
$path
string
Returns
bool

public localToPublic (string $path) : string | null

Returns a public file path from an absolute path.

Eg: /home/mysite/public_html/welcome -> /welcome

Returns null if the path cannot be converted.

Parameters
Property Description
$path
string
Returns
string | null

public makeDirectory (string $path, integer $mode = 511, boolean $recursive = false, boolean $force = false) : bool

Create a directory.

Parameters
Property Description
$path
string
$mode
integer
$recursive
boolean
$force
boolean
Returns
bool

public normalizePath (string $path) : string

Normalizes the directory separator, often used by Windows systems.

Parameters
Property Description
$path
string
Returns
string

public put (string $path, string $contents, boolean $lock = false) : int | false

Write the contents of a file.

This method will also set the permissions based on the given chmod() mask in use.

Returns the number of bytes written to the file, or false on failure.

Parameters
Property Description
$path
string
$contents
string
$lock
boolean
Returns
int | false

public sizeToString (integer $bytes) : string

Converts a file size in bytes to a human readable format.

Parameters
Property Description
$bytes
integer
Returns
string

public symbolizePath (string $path, $default = null) : string

Converts a path using path symbol.

Returns the original path if no symbol is used, and no default is specified.

Parameters
Property Description
$path
string
$default
mixed
Returns
string

protected findSymlinks () : void

Finds symlinks within the base path and populates the local symlinks property with an array of source => target symlinks.

Returns
void
Copyright © 2024 Winter CMS