Runtime
Runtime
Runtime filesystem context manager for application-scoped writable paths.
class RuntimeThis class maintains named singleton-like runtime instances, each bound to a validated base directory on disk. It is used to centralize access to runtime paths for temporary files, caches, logs, and other writable artifacts required while the application runs.
Behavioral guarantees:
- Instances are created explicitly via {@see self::createInstance()} and are immutable with respect to their base path after creation.
- The base path is validated to exist and to be both readable and writable.
- Instances are retrieved by name via {@see self::getInstance()}.
- Child paths can be resolved with {@see self::getPath()}, optionally creating missing directories when requested.
Typical usage:
- Bootstrap creates one runtime instance for the application (default name:
hazaar). - Other components request paths relative to that runtime root instead of hard-coding filesystem locations.
Properties
instances
private array $instancespath
Canonical absolute path for this runtime instance.
private string $pathThe value is resolved through realpath() during construction and used as the base directory for all subsequent path resolution.
Methods
__construct
Creates a runtime instance bound to a validated filesystem path.
private __construct(string $path): voidParameters
| Parameter | Type | Description |
|---|---|---|
$path | string | the runtime base directory |
getInstance
Returns an existing named runtime instance.
public getInstance(string $name = 'hazaar'): selfParameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the runtime instance name |
hasInstance
Checks if a named runtime instance exists.
public hasInstance(string $name = 'hazaar'): boolParameters
| Parameter | Type | Description |
|---|---|---|
$name | string | The runtime instance name |
createInstance
Creates and registers a new named runtime instance.
public createInstance(string $path, string $name = 'hazaar'): selfParameters
| Parameter | Type | Description |
|---|---|---|
$path | string | the runtime base directory |
$name | string | the unique name used to register the instance |
getPath
Resolves a path within the runtime directory.
public getPath(?string $pathSuffix, bool $createDir): stringWhen $pathSuffix is provided, it is appended to the runtime base path. Optionally, the resolved path is created as a directory when it does not already exist.
Parameters
| Parameter | Type | Description |
|---|---|---|
$pathSuffix | string | relative directory suffix to append to the runtime base path |
$createDir | bool | whether to create the resolved directory if it does not exist |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:25 +0000