nexphant/support
Foundational configuration utility loaders and runtime safety settings, completely isolated with zero external dependencies.
Install
composer require nexphant/supportConfig Loader
The Nexphant\Support\Config class manages application configuration parameters and .env environment loading:
use Nexphant\Support\Config;
// Load environment variables from a .env file
Config::loadEnv(getcwd() . '/.env');
// Load settings from a PHP configuration array file
Config::load(getcwd() . '/config/app.php');
// Retrieve a setting value with a default fallback
$appName = Config::get('name', 'Nexphant Application');Nested config values can be read with dot notation:
$driver = Config::get('db.driver', 'sqlite');Runtime Safety Settings
The Nexphant\Support\RuntimeConfig class governs execution constraints, resource tracing, and diagnostics tracking policies:
use Nexphant\Support\RuntimeConfig;
// Apply config rules
RuntimeConfig::apply([
'runtime_safety' => true,
'leak_detection' => true,
'metrics' => [
'enabled' => true,
'sample_rate' => 1000,
]
]);
// Read policy settings
$metricsEnabled = RuntimeConfig::$metrics;
$leakDetectionEnabled = RuntimeConfig::$leakDetection;Config API
Config Loader
| Method | Return Type | Description |
|---|---|---|
loadEnv(string $path) | void | Parses the .env file and defines environment variables. |
load(string $path) | void | Loads a PHP config configuration file. |
get(string $key, mixed $default = null) | mixed | Retrieves a configuration value by key. |
RuntimeConfig Properties
bool $runtimeContext: Scoped context propagation active.bool $ownership: Resource ownership checks.bool $drainTracking: Drain shutdown state monitoring.bool $metrics: Telemetry logs active.int $sampleRate: Metrics sampling interval.bool $histogram: Histogram collection active.bool $routeLatency: Route latency collection active.bool $runtimeDiscipline: Lifecycle discipline active.bool $resourceTrace: Resource trace capture active.bool $leakDetection: Active memory leak reporting enabled.
Runtime Profiles
$defaults = RuntimeConfig::defaults();
$lean = RuntimeConfig::leanDefaults();
$perf = RuntimeConfig::performanceDefaults();runtime_safety: false, performance_mode: true, NEXPHANT_MODE=benchmark, or NEXPHANT_PERFORMANCE_MODE=1 switches to lean defaults unless explicit config overrides are provided.
Environment overrides:
| Variable | Effect |
|---|---|
NEXPHANT_RUNTIME_CONTEXT | Overrides context propagation. |
NEXPHANT_OWNERSHIP | Overrides ownership tracking. |
NEXPHANT_DRAIN_TRACKING | Overrides drain tracking. |
NEXPHANT_METRICS | Overrides metrics collection. |
Extension Detection
Use ExtensionDetector to inspect optional runtime capabilities:
use Nexphant\Support\Extension\ExtensionDetector;
if (ExtensionDetector::has('redis')) {
// Redis-backed queue/cache can be enabled.
}
$capabilities = ExtensionDetector::capabilities();
ExtensionDetector::reset();Capabilities include apcu, redis, sockets, pcntl, posix, fiber, native event loops, compression, and database extensions.
