PHP Luminova: Local Files Directories Operations
Read, write, and stream files, work with directories, and manage filesystem permissions and locks.
Use the Filesystem class for local files and directories. Create an instance to inspect one path through PHP’s SplFileInfo. Call the static methods to read or write data, copy and move files, create directories, or resolve paths. To send a file as an HTTP attachment, use File Downloader.
Examples
Creating a Filesystem Instance
use Luminova\Storage\Filesystem;
// Using constructor
$fs = new Filesystem('/path/to/file.txt');
// Using static info method
$fs = Filesystem::info('/path/to/file.txt');
// Using Factory Helper
$fs = Luminova\Foundation\Module\Factory::filesystem('/path/to/file.txt');
// Using Helper Function
$fs = Luminova\Funcs\factory('filesystem', false, '/path/to/file.txt');Access Application Paths
Read an application directory as an instance property or look it up with Filesystem::path(). The result is an absolute path based on your application root.
echo $fs->views;
echo Filesystem::path('views');Setting or Updating the File
$fs->setFilename('/new/path/to/file.txt');After setting the path, use the instance to check the file and read its metadata.
Check Whether a File or Directory Exists
if ($fs->exists()) {
echo "File exists!";
} else {
echo "File does not exist!";
}Read File Metadata
echo $fs->size; // File size in bytes
echo $fs->extension; // File extension
echo $fs->pathname; // Full path
echo $fs->filename; // file.txt
echo $fs->realPath; // /full/path/to/file.txt
echo $fs->owner; // UID of ownerCalls to methods such as getFilename() are forwarded to the underlying SplFileInfo object.
echo $fs->getFilename(); // Same as $fs->filenameReading File Contents
$content = Filesystem::contents('/path/to/file.txt');
if ($content !== false) {
echo $content;
}Read only a portion of the file:
$content = Filesystem::contents('/path/to/file.txt', 100, 50);
// Reads 100 bytes starting at offset 50Write a String
Filesystem::write('/path/to/file.txt', 'Hello World!');Append to a File
Filesystem::write('/path/to/file.txt', "\nNew line", FILE_APPEND | LOCK_EX);Write from a Stream
$stream = fopen('php://memory', 'rb+');
fwrite($stream, 'Stream content');
rewind($stream);
try {
Filesystem::write('/path/to/file.txt', $stream, FILE_APPEND | LOCK_EX);
} finally {
fclose($stream);
}Streaming Large Files
$bytesSent = Filesystem::read('/path/to/largefile.zip', length: 1024 * 1024);- Reads in chunks up to the requested total length.
- Returns the number of bytes sent, or
falseon failure.
Creating Directories
Filesystem::mkdir('writeable/storages/images', 0755);- Automatically creates parent directories if they don’t exist.
Copying Files or Directories
$copied = 0;
Filesystem::copy('source/folder', 'dest/folder', skipIfExists: true, copied: $copied);
echo "Copied $copied files.";Moving Files or Directories
$moved = 0;
Filesystem::move('source/folder', 'dest/folder', skipIfExists: true, moved: $moved);
echo "Moved $moved files.";Deleting Files or Directories
$deleted = Filesystem::delete('writeable/storages/temp', deleteBase: true);
echo "Deleted $deleted items.";Creating a Symbolic Link
Filesystem::symbolic('/path/to/target', '/path/to/symlink');- Use a link path where you want the symbolic link created.
Measure a File or Directory
echo Filesystem::size('/path/to/file.txt'); // Returns bytes
echo Filesystem::size('folder'); // Returns total folder sizeWorking with Permissions
Convert Permissions to a Symbolic String
echo Filesystem::permissions(0755); // Output: rwxr-xr-xConvert Symbolic Permissions to Octal Digits
echo Filesystem::toUnixPermission('rw-r--r--'); // Output: 0644Set File or Directory Permissions
Filesystem::setPermission('/path/to/file.txt', 0644);Class Definition
- Full namespace:
Luminova\Storage\Filesystem - This class implements PHP’s built-in
Stringableinterface.
Constants
| Constant | Value | Description |
|---|---|---|
FILE_BINARY | 2691 | Flag value recognized by write() when choosing binary mode. |
Read-Only Path Properties
Read these paths on a Filesystem instance, or pass the property name to Filesystem::path(). The framework resolves paths relative to the application root.
app
Path to the application directory.
Type: string
modules
Path to the application modules.
Type: string
system
Path to the framework source directory.
Type: string
plugins
Path to the system third-party plugins.
Type: string
library
Path to the libraries and third-party modules.
Type: string
services
Path to the serialized shared services.
Type: string
controllers
Path to the application controllers.
Type: string
writeable
Path to the application’s writable runtime directory.
Type: string
logs
Path to the error logs.
Type: string
caches
Path to the application caches.
Type: string
public
Path to the public document root.
Type: string
assets
Path to the public assets directory.
Type: string
views
Path to the view templates.
Type: string
routes
Path to the application routes.
Type: string
languages
Path to the translation files.
Type: string
Methods
__construct
Create a filesystem helper, optionally associated with a file path for instance methods and file properties.
public function __construct(?string $filename = null)Parameters:
| Parameter | Type | Description |
|---|---|---|
$filename | ?string | File path for instance operations (default null). |
setPermission
Set permissions for a file or directory.
public static function setPermission(string $location, int $permission): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$location | string | The path to the file or directory. |
$permission | int | The permission to set (Unix file permissions e.g, 0777). |
Return:
bool - Returns true on success, false on failure.
permissions
Converts Unix file permission code to its string representation.
public static function permissions(int $permission): stringParameters:
| Parameter | Type | Description |
|---|---|---|
$permission | int | The unix file permission (e.g, 0777). |
Return:
string - Return permission string representation.
write
Write or append data to a file.
Write a string, stream resource, or SplFileObject. The default mode opens the file for replacement before trying to acquire a lock, so the existing contents can be truncated even if locking fails. Use atomicWrite() when replacing a file must preserve the previous contents if the write fails.
public static function write(
string $filename,
mixed $content,
int $flags = 0,
int $retryLock = 1,
float|int $delay = 0,
mixed $context = null,
int &$bytes = 0
): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$filename | string | Path to the file to write. |
$content | mixed | The data to write as a string, stream resource, or SplFileObject. Seekable inputs are rewound when needed. |
$flags | int | Optional file flags (e.g., FILE_APPEND, FILE_USE_INCLUDE_PATH, LOCK_EX) (default 0). |
$retryLock | int | Maximum lock attempts when both LOCK_EX and LOCK_NB are set (default: 1). |
$delay | float|int | Delay in seconds between data chunks (default: 0). The non-blocking lock retry uses the separate waitForLock() delay. |
$context | mixed | Optional stream context created via stream_context_create() (default null). |
$bytes | int | The number of bytes written, or 0 if writing fails (default 0). |
Return:
bool - Whether at least one byte was written. An empty write can return false.
Throws:
- Luminova\Exceptions\FileException if opening, locking, or writing the file fails.
- Luminova\Exceptions\InvalidArgumentException if the content or stream context is invalid.
Examples:
Write string:
Filesystem::write('/path/to/file.txt', 'Hello World', FILE_APPEND | LOCK_EX);Write from stream:
$stream = fopen('php://memory', 'rb+');
fwrite($stream, 'Hello Stream');
rewind($stream);
try {
Filesystem::write('/path/to/file.txt', $stream, FILE_APPEND | LOCK_EX);
} finally {
fclose($stream);
}mkdir
Create a directory if it does not exist.
This method attempts to create the directory with the specified permissions.Supports recursive creation of nested directories.
public static function mkdir(
string $path,
int $permissions = 0775,
bool $recursive = true
): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | The directory path to create. |
$permissions | int | Unix permission bits (default: 0775), subject to the process umask. |
$recursive | bool | Whether to create nested directories recursively (default: true). |
Return:
bool - Returns true if the directory already exists or was successfully created, false otherwise.
Throws:
Luminova\Exceptions\FileException - If unable to create the directory due to filesystem errors.
Examples:
Filesystem::mkdir('writeable/storages/images', 0755);copy
Recursively copy files and directories from a source to a destination.
Optionally skip files or directories that already exist in the destination.
public static function copy(
string $origin,
string $dest,
bool $skipIfExists = false,
int &$copied = 0
): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$origin | string | The source directory or file path to copy. |
$dest | string | The destination directory path. |
$skipIfExists | bool | Whether to skip already existing files or directories (default: false). |
$copied | int | Reference to store the number of successfully copied items (default 0). |
Return:
bool - Whether at least one file or symbolic link was copied. An empty directory can be created even when the method returns false.
Throws:
- Luminova\Exceptions\RuntimeException - If source directory does not exist or is not readable.
- Luminova\Exceptions\FileException - If unable to create destination directory due to filesystem errors.
move
Recursively move files and directories from a source to a destination.
Optionally skip files or directories that already exist in the destination.
public static function move(
string $origin,
string $dest,
bool $skipIfExists = false,
int &$moved = 0
): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$origin | string | The source directory or file path to move. |
$dest | string | The destination directory path. |
$skipIfExists | bool | Whether to skip already existing files or directories (default: false). |
$moved | int | Reference to store the number of successfully moved items (default 0). |
Return:
bool - Whether at least one file or symbolic link was moved. An empty directory can be created at the destination even when the method returns false.
Throws:
- Luminova\Exceptions\RuntimeException - If the source does not exist or is not readable.
- Luminova\Exceptions\FileException - If unable to create destination directory due to filesystem errors.
size
Determine the size in bytes of a file, directory, or stream. String inputs are treated as filesystem paths.
Supported sources:
- File path: returns file size.
- Directory path: returns cumulative size of all files recursively.
- Stream resource: returns size using
fstat()(if available). - Luminova stream object or stream interface: uses the object’s size method. A stream interface with an unknown size returns zero.
public static function size(mixed $source): ?intParameters:
| Parameter | Type | Description |
|---|---|---|
$source | mixed | File or directory path, stream resource, or stream object. |
Return:
int|null - Returns the size in bytes, or null if the stream size cannot be determined.
Throws:
Luminova\Exceptions\FileException - If the source is invalid or does not exist.
read
Streams a file resource to output in chunks.
Reads text or binary files in chunks to limit memory use. The method closes streams it opens from file paths. The caller closes any resource it supplies.
public static function read(
mixed $source,
int $offset = 0,
int $length = (1 << 21),
float|int $delay = 0,
float|int $timeout = 30,
bool $blocking = true,
?int $filesize = null
): int|falseParameters:
| Parameter | Type | Description |
|---|---|---|
$source | mixed | File stream or file path. |
$offset | int | Starting byte offset (default 0). |
$length | int | Maximum total bytes to read (default 2 MiB). Use zero to read through EOF or until the timeout. |
$delay | float|int | Delay in seconds between chunks (default 0). |
$timeout | float|int | Read timeout in seconds (default 30). Zero disables the timeout. |
$blocking | bool | Whether stream reads should use blocking mode (default true). |
$filesize | ?int | Optional known file size in bytes, auto-detected if null (default: null). |
Return:
int|false - The number of bytes read, or false if reading cannot start.
Example
Read from resource.
$filename = 'large-file.pdf';
$handler = fopen($filename, 'rb');
if ($handler !== false) {
try {
Filesystem::read($handler, blocking: false);
} finally {
fclose($handler);
}
}Read directly from a file path.
Filesystem::read('/path/to/file.pdf', blocking: false);delete
Deletes files and folders recursively.
public static function delete(
string $location,
bool $deleteBase = false
): intParameters:
| Parameter | Type | Description |
|---|---|---|
$location | string | Directory or file to delete. |
$deleteBase | bool | Whether to delete the target directory itself (default false). |
Return:
int - Number of files, symbolic links, and directories removed.
symbolic
Create a symlink to a target file or directory.
public static function symbolic(
string $target,
string $link,
int $permissions = 0755
): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$target | string | The target file or directory. |
$link | string | The location of the link. |
$permissions | int | The permissions for a newly created destination directory (default: 0755). |
Return:
bool - Return true if the link was successfully created false otherwise.
isResource
Checks if a variable is a valid resource of the specified type.
public static function isResource(mixed $resource, ?string $type = null): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$resource | mixed | The resource to check. |
$type | ?string | The expected resource type. Possible values are: 'stream-context', 'stream', etc. |
Return:
bool - Returns true if the variable is a resource and matches the expected resource type, otherwise returns false.
isAccessible
Validate if the provided file path is safe, exists, and is readable.This method checks if the file path is valid, whether it is accessible, and ensures it's readable unless it's a UNC path.
public static function isAccessible(string $path): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | The file path to validate (relative or absolute). |
Return:
bool - Returns true if the file is accessible and readable.
isPathPermitted
Check whether a path begins with a URI scheme such as phar://. Use resolvePath() when you also need to resolve the path or check a base directory boundary.
public static function isPathPermitted(string $path): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | The file path to check (relative or absolute). |
Return:
bool - Whether the path lacks a leading URI scheme.
toUnixPermission
Convert permission string to Unix integer permission.
public static function toUnixPermission(string $permission, bool $decimal = false): string|int|nullParameters:
| Parameter | Type | Description |
|---|---|---|
$permission | string | A nine-character string made of r, w, x, and -, such as rw-r--r--. |
$decimal | bool | Whether to return an integer instead of the formatted octal string (default: false). |
Return:
string|int|null - A four-digit octal string by default, the equivalent integer when $decimal is true, or null when the input length is not nine.
info
Create a Filesystem instance for the specified file or directory.
public static function info(string $filename): staticParameters:
| Parameter | Type | Description |
|---|---|---|
$filename | string | The file or directory path. |
Return:
static - A new Filesystem instance.
Throws:
- Luminova\Exceptions\FileException if the filename is empty.
setFilename
Set or update the file for this Filesystem instance.
public function setFilename(string $filename): selfParameters:
| Parameter | Type | Description |
|---|---|---|
$filename | string | The path to the file. |
Return:
self - Returns the instance of Filesystem.
Throws:
- Luminova\Exceptions\FileException if the filename is empty.
exists
Check if the file exists.
public function exists(): boolReturn:
bool - True if the path exists as a file, directory, or symbolic link, otherwise false.
chmod
Set the permissions of a file or directory.
public static function chmod(string $location, int $permission): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$location | string | The file or directory path. |
$permission | int | The permissions to apply. |
Return:
bool - True if the permissions were changed successfully, otherwise false.
Throws:
- Luminova\Exceptions\FileException when permission changes fail and the framework raises the error.
contents
Read file content with optional length, offset, and stream context.
public static function contents(
string $filename,
int $length = 0,
int $offset = 0,
bool $useInclude = false,
mixed $context = null,
float|int $delay = 0
): string|boolParameters:
| Parameter | Type | Description |
|---|---|---|
$filename | string | The path to the file. |
$length | int | The maximum number of bytes to read, or 0 to read until EOF (default 0). |
$offset | int | The byte offset at which reading begins (default 0). |
$useInclude | bool | Whether to search for the file in the include path (default false). |
$context | mixed | An optional stream context created with stream_context_create() (default null). |
$delay | float|int | Delay in seconds between chunks (default: 0). |
Return:
string|bool - Returns the file content, or false on failure.
Throws:
- Luminova\Exceptions\FileException if the framework raises an error while opening or reading the file.
sink
Writes all data from a source to a destination stream.
public static function sink(
mixed $destination,
mixed $source,
int $chunkSize = 16_384,
float|int $delay = 0,
?string $filename = null
): intParameters:
| Parameter | Type | Description |
|---|---|---|
$destination | mixed | Writable file handler. |
$source | mixed | Data source, either a SplFileObject, stream resource, or string. |
$chunkSize | int | Maximum number of bytes to read per iteration (default 16_384). |
$delay | float|int | Delay in seconds between chunks (default: 0). |
$filename | ?string | Optional destination filename used in exception messages (default null). |
Return:
int - Returns the total number of bytes written.
Throws:
- Luminova\Exceptions\InvalidArgumentException if the chunk size is below one.
- Luminova\Exceptions\FileException if reading or writing fails, the target handle is invalid, or the source type is unsupported.
atomicWrite
Write to a temporary file in the target directory, then rename it over the destination. The directory must already exist and be writable.
public static function atomicWrite(
string $filename,
mixed $content,
?int $mode = null,
bool $acquireLock = false,
bool $deleteLockFile = false
): intParameters:
| Parameter | Type | Description |
|---|---|---|
$filename | string | Target file path. |
$content | mixed | String data or a readable stream resource. |
$mode | ?int | File permissions. Null preserves the target file permissions (default null). |
$acquireLock | bool | Whether to acquire an exclusive lock (default false). |
$deleteLockFile | bool | Whether to delete lock file once done (default false). |
Return:
int - Number of bytes written, including zero for an empty replacement. Failures throw.
Throws:
- Luminova\Exceptions\InvalidArgumentException if the filename is empty.
- Luminova\Exceptions\FileException if the target directory is unavailable or the replacement operation fails.
Examples:
use Luminova\Storage\Filesystem;
$path = Filesystem::path('writeable') . 'report.txt';
$bytes = Filesystem::atomicWrite($path, "Report ready\n");
echo $bytes; // 13waitForLock
Waits until an exclusive lock can be acquired.
public static function waitForLock(
mixed $file,
int $retries = 10,
float|int $delay = 100_000
): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$file | mixed | The file path, stream resource, or open SplFileObject. |
$retries | int | Maximum number of retry attempts (default 10). |
$delay | float|int | Delay in seconds between failed attempts (signature default: 100_000). Pass an explicit short delay such as 0.1 when retrying. |
Return:
mixed - Returns the locked file handler.
Throws:
- Luminova\Exceptions\InvalidArgumentException if the retry count is below one or the input type is invalid.
- Luminova\Exceptions\FileException if no lock can be acquired after the configured attempts.
lock
Acquires an exclusive lock on a file.
public static function lock(
mixed $file,
bool $blocking = true,
?int $lockWouldBlock = null
): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$file | mixed | A filename or open file handler. |
$blocking | bool | Whether to wait for the lock to become available (default true). |
$lockWouldBlock | ?int | Passed by value. The caller cannot use it to read the lock result (default: null). |
Return:
mixed - Returns the locked file handler.
Throws:
- Luminova\Exceptions\InvalidArgumentException if the file argument is unsupported.
- Luminova\Exceptions\FileException if the file cannot be opened or locked.
fileLock
Acquire an exclusive lock on a lock file under the application’s writable directory.
public static function fileLock(
?string $basename = null,
int $dirPermissions = 02770,
?string &$lockFilepath = null
): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$basename | ?string | Optional identifier for the lock (default null). |
$dirPermissions | int | Permissions for the lock directory (default 02770). |
$lockFilepath | ?string | Returns the generated lock file path (default null). |
Return:
resource - Open stream holding the exclusive lock. Release the lock and close the stream after use.
Throws:
- Luminova\Exceptions\InvalidArgumentException if directory permissions are invalid.
- Luminova\Exceptions\RuntimeException if creating the lock directory returns a failure.
- Luminova\Exceptions\FileException if creating the directory, opening the file, or acquiring the lock fails and raises a file exception.
unlock
Release an acquired lock. The method leaves the resource open.
public static function unlock(mixed $handler): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$handler | mixed | An open file handler with an active lock. |
Return:
bool - Returns true if the lock was released successfully, otherwise false.
tryLock
Attempts to acquire an exclusive lock on a file.
public static function tryLock(
mixed $file,
bool $blocking = true,
?int $lockWouldBlock = null
): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$file | mixed | The file path, stream resource, or open SplFileObject. |
$blocking | bool | Whether to wait until the lock becomes available (default true). |
$lockWouldBlock | ?int | Passed by value. The caller cannot use it to read the lock result (default: null). |
Return:
mixed - Returns the locked file handler, or false if the lock cannot be acquired.
isLocked
Determine whether a file is currently locked by another process.
public static function isLocked(mixed $file): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$file | mixed | A filename, stream resource or SplFileObject instance. |
Return:
bool - Returns true if another process holds the lock, false otherwise.
createTempDir
Create a unique writable temporary directory.
public static function createTempDir(
?string $prefix = null,
bool $localOnly = false
): ?stringParameters:
| Parameter | Type | Description |
|---|---|---|
$prefix | ?string | Optional directory name prefix (default null). |
$localOnly | bool | Whether to use application-local storage only (default false). |
Return:
string|null - The created directory path with a trailing directory separator, or null if creation fails.
createTempFile
Creates a writable temporary file.
public static function createTempFile(
?string $filename = null,
?string $extension = null,
bool $localOnly = false
): ?stringParameters:
| Parameter | Type | Description |
|---|---|---|
$filename | ?string | Optional filename prefix (default null). |
$extension | ?string | Optional file extension without a leading dot (default null). |
$localOnly | bool | Whether to use only the application writable temp directory instead of the system temporary directory (default false). |
Return:
string|null - Returns the created temporary file path, or null if the temporary directory or file cannot be created.
touch
Create a file or update its access and modification timestamps.
public static function touch(
string $file,
?int $mtime = null,
?int $atime = null
): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$file | string | The file path. |
$mtime | ?int | Optional modification timestamp (default null). |
$atime | ?int | Optional access timestamp (default null). |
Return:
bool - Returns true if the operation succeeds, otherwise false.
createTempName
Create a unique temporary file name in the specified directory.
public static function createTempName(
?string $directory = null,
string $prefix = 'tmp_'
): ?stringParameters:
| Parameter | Type | Description |
|---|---|---|
$directory | ?string | Directory where the temporary file should be created (default: /writeable/tmp/). |
$prefix | string | Prefix to prepend to the generated filename (default 'tmp_'). |
Return:
string|null - The path to the created temporary file, or null if the directory is not writable or the file cannot be created.
symlink
Create a symbolic link (symlink) to a target file or directory.
public static function symlink(
string $target,
string $link,
int $permissions = 0755
): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$target | string | The target file or directory to link from. |
$link | string | The path where the symbolic link will be created. |
$permissions | int | The permissions to set for the destination directory if it needs to be created (default: 0755). |
Return:
bool - Returns true if symbolic link was successfully created, false otherwise.
lastModified
Get the last-modified Unix timestamp of a file source.
public static function lastModified(mixed $source): ?intParameters:
| Parameter | Type | Description |
|---|---|---|
$source | mixed | The file source. |
Return:
int|null - Returns the last-modified Unix timestamp, or null if unavailable.
isLikelyFile
Determine whether a string likely represents a filesystem path.
public static function isLikelyFile(string $value, bool $forFile = false): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$value | string | The string to evaluate. |
$forFile | bool | If true, enforces that the path looks like a file (with extension). |
Return:
bool - Returns true if the string appears to be a filesystem path.
isWritable
Check if a local filesystem path is writable.
public static function isWritable(string $path): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | Absolute or relative filesystem path. |
Return:
bool - Returns true if the path exists, is permitted, and writable.
isReadable
Check if a local filesystem path is readable.
public static function isReadable(string $path): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | Absolute or relative filesystem path. |
Return:
bool - Returns true if the path exists, is permitted, and readable.
isPath
Determines whether a string looks like a directory path.
public static function isPath(string $path): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | Path string to inspect. |
Return:
bool - Return true if the value appears to represent a directory path.
isAbsolutePath
Determine whether a path is absolute.
public static function isAbsolutePath(string $path): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | The filesystem path to evaluate. |
Return:
bool - Returns true if the path is absolute, false otherwise.
path
Resolve and normalize application paths.
public static function path(string $name): stringParameters:
| Parameter | Type | Description |
|---|---|---|
$name | string | Path key name (e.g. "app", "public"). |
Return:
string - Returns an absolute normalized path, or an empty string if the key is undefined.
toSeparator
Normalize directory separators to the specified format.
public static function toSeparator(string $path, string $separator = '/'): stringParameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | File path to normalize. |
$separator | string | The directory separator to use. |
Return:
string - Returns the path with normalized directory separators.
toOsSeparator
Normalize directory separators to the current operating system.
public static function toOsSeparator(string $path): stringParameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | File path to normalize. |
Return:
string - Returns the path with normalized directory separators.
normalize
Normalize path separators and remove redundant trailing separators.
public static function normalize(
string $path,
string $separator = DIRECTORY_SEPARATOR,
bool $trimEnd = true
): stringParameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | The path to normalize. |
$separator | string | The separator to use in the normalized path (default DIRECTORY_SEPARATOR). |
$trimEnd | bool | Whether to remove trailing separators (default true). |
Return:
string - Returns the normalized path.
resolvePath
Resolve and validate a filesystem path with security controls.
public static function resolvePath(
string $path,
?string $baseDir = null,
bool $mustExist = false,
bool $mustReadable = false,
bool $blockSymlinks = true
): stringParameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | Local path. Relative paths are resolved from the current working directory. |
$baseDir | ?string | Optional base directory boundary (default: null). Relative base directories are resolved from the current working directory. |
$mustExist | bool | Whether to require the path to exist (default: false). |
$mustReadable | bool | Whether to require the path to be readable (default: false). |
$blockSymlinks | bool | Whether to reject symbolic link traversal (default: true). |
Return:
string - Returns the resolved absolute path.
Throws:
- Luminova\Exceptions\FileException if the path is invalid, leaves the configured base directory, crosses a symlink when blocked, or fails a requested existence or readability check.
__get
Resolve application path names first. Otherwise, forward a property such as filename to the corresponding SplFileInfo getter.
public function __get(string $property): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$property | string | Application path key or file metadata property. |
Return:
mixed - Absolute application path, the getter result, or null if file information has not been initialized.
Throws:
OutOfBoundsExceptionwhen file information is initialized but no getter matches.
__call
Forward a method call to the underlying SplFileInfo object.
public function __call(string $method, array $args): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$method | string | Method to call on SplFileInfo. |
$args | array<int|string,mixed> | Positional or named arguments to forward. |
Return:
mixed - Return value of the delegated method.
Throws:
BadMethodCallExceptionwhen file information has not been initialized or the method is unknown.
__isset
Check whether a name is a registered application path or a recognized metadata key on an initialized instance.
public function __isset(string $name): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$name | string | Path or metadata key to check. |
Return:
bool - Whether the key is recognized. This check does not access the file.
__toString
Return the path represented by the current file information object.
public function __toString(): stringReturn:
string - File pathname or an empty string when no file information has been initialized.