| use_cases |
|
|---|
This feature introduces support for environment variables in the Pramnos Framework using a .env file, similar to modern frameworks like Laravel and Symfony.
It allows developers to:
- Store sensitive configuration outside the codebase
- Manage environment-specific settings (dev, staging, production)
- Access environment variables in a consistent and safe way
Previously, Pramnos relied on constants or manual configuration handling.
This approach had limitations:
- Hard to manage across environments
- Not secure for sensitive data (e.g. API keys, DB credentials)
- No standardized way to load configuration
With this feature:
- Configuration becomes centralized
- Sensitive data can be excluded from version control
- The framework becomes more flexible and modern
The feature uses Symfony’s Dotenv component.
Dependency added:
symfony/dotenv
No additional setup is required by the framework user beyond creating a .env file.
At the root of your project:
.env
Example:
APP_ENV=dev
APP_DEBUG=true
DEBUG_LEVEL=2
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=secret
TEST_FLOAT=3.14
TEST_EMPTY=
After loading the Composer autoloader, call:
require __DIR__ . '/../vendor/autoload.php';
loadDotenv(__DIR__);
⚠️ This should be done early in the application lifecycle (e.g. entry point likeindex.php).
Use the helper:
envvar('KEY');Examples:
var_dump(envvar('APP_ENV')); // "dev"
var_dump(envvar('APP_DEBUG')); // true
var_dump(envvar('DEBUG_LEVEL')); // 2
var_dump(envvar('TEST_FLOAT')); // "3.14"
var_dump(envvar('TEST_EMPTY')); // ""You can also provide a default value:
envvar('NOT_DEFINED', 'default_value');The envvar() helper automatically converts common string values:
| Value | Result |
|---|---|
true |
true (bool) |
false |
false (bool) |
null |
null |
empty |
"" (empty string) |
"text" |
text |
'text' |
text |
Numeric values are NOT automatically cast to boolean.
Example:
DEBUG_LEVEL=1
envvar('DEBUG_LEVEL'); // "1"This allows using values like:
0,1,2,3for debug levels- without breaking logic by converting them to
true/false
Add to .gitignore:
.env
For shared configuration, you can create:
.env.example
The function internally prevents reloading the same file.
The envvar() helper checks values in this order:
getenv()$_ENV$_SERVER
This feature does not break existing functionality.
- Existing
env()helper remains unchanged - Old projects continue to work without modification
- New projects can adopt
.envgradually
- Always call
loadDotenv()early - Use
envvar()instead ofenv()for new code - Keep secrets in
.env, not in source code - Use
.env.examplefor documentation
require __DIR__ . '/../vendor/autoload.php';
loadDotenv(__DIR__);
$env = envvar('APP_ENV', 'prod');
$debug = envvar('APP_DEBUG', false);
$debugLevel = envvar('DEBUG_LEVEL', 0);This feature brings modern configuration handling to Pramnos:
- Clean separation of config and code
- Safer handling of sensitive data
- Flexible multi-environment support
- Developer-friendly API
It is a foundational step toward more advanced features such as:
- configuration management
- validation systems
- environment-based behavior