Env
in package
Environment variable manager and .env file loader for the Neuron framework.
This singleton class provides secure and convenient access to environment variables and .env file configuration. It automatically loads environment variables from .env files and provides a clean API for accessing configuration values throughout the application with proper error handling.
Key features:
- Automatic .env file detection and loading
- Singleton pattern for consistent environment state
- Comment support in .env files (lines starting with #)
- Secure environment variable access with null safety
- Custom .env file path support
- Environment variable validation and type conversion
The class automatically looks for .env files in the document root unless a custom path is specified, making it ideal for configuration management across different deployment environments.
Tags
Table of Contents
Properties
- $fileName : string|null
- $fs : IFileSystem
- $instance : Env|null
Methods
- get() : array<string|int, mixed>|false|string
- getInstance() : Env|null
- loadEnvFile() : void
- put() : bool
- reset() : void
- __construct() : mixed
- Env constructor.
Properties
$fileName
private
string|null
$fileName
$fs
private
IFileSystem
$fs
$instance
private
static Env|null
$instance
= null
Methods
get()
public
get(mixed $key) : array<string|int, mixed>|false|string
Parameters
- $key : mixed
Return values
array<string|int, mixed>|false|stringgetInstance()
public
static getInstance([string|null $envFile = null ][, IFileSystem|null $fs = null ]) : Env|null
Parameters
- $envFile : string|null = null
- $fs : IFileSystem|null = null
-
File system implementation (null = use real file system)
Return values
Env|nullloadEnvFile()
public
loadEnvFile() : void
put()
public
put(mixed $config) : bool
Parameters
- $config : mixed
Return values
boolreset()
public
reset() : void
__construct()
Env constructor.
private
__construct([string|null $fileName = null ][, IFileSystem|null $fs = null ]) : mixed
Parameters
- $fileName : string|null = null
- $fs : IFileSystem|null = null
-
File system implementation (null = use real file system)