Skip to content

nexphant/support ​

Foundational configuration utility loaders and runtime safety settings, completely isolated with zero external dependencies.

Install ​

bash
composer require nexphant/support

Config Loader ​

The Nexphant\Support\Config class manages application configuration parameters and .env environment loading:

php
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:

php
$driver = Config::get('db.driver', 'sqlite');

Runtime Safety Settings ​

The Nexphant\Support\RuntimeConfig class governs execution constraints, resource tracing, and diagnostics tracking policies:

php
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 ​

MethodReturn TypeDescription
loadEnv(string $path)voidParses the .env file and defines environment variables.
load(string $path)voidLoads a PHP config configuration file.
get(string $key, mixed $default = null)mixedRetrieves 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 ​

php
$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:

VariableEffect
NEXPHANT_RUNTIME_CONTEXTOverrides context propagation.
NEXPHANT_OWNERSHIPOverrides ownership tracking.
NEXPHANT_DRAIN_TRACKINGOverrides drain tracking.
NEXPHANT_METRICSOverrides metrics collection.

Extension Detection ​

Use ExtensionDetector to inspect optional runtime capabilities:

php
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.

Released under the MIT License.