You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `NAL\Dotenv` class is a lightweight PHP package for managing environment variables.
12
-
It allows you to load environment variables from files, group variables, and access them in your PHP application.
13
-
The class supports loading variables from multiple files.
11
+
`NAL\Dotenv` is a flexible and lightweight PHP environment loader designed for modern applications.
12
+
It supports loading environment variables from `.env` and `.json` files by default, with the ability to register custom loaders (e.g., YAML, XML) effortlessly.
13
+
14
+
**This package provides:**
15
+
16
+
- Grouped access to related environment keys
17
+
- Support for multiple environment files
18
+
- Static or instance-based access
19
+
- Optional caching for performance
20
+
- Convention-based parser resolution
21
+
- Seamless integration with custom loaders and parsers
22
+
23
+
It's ideal for both small-scale projects and larger applications where managing structured and multi-source environment data is essential.
14
24
15
25
## Contributing
16
26
- This is an open-source library, and contributions are welcome.
17
27
- If you have any suggestions, bug reports, or feature requests, please open an issue or submit a pull request on the project repository.
You can also use static calls without manually creating an instance:
105
100
```php
106
-
// Get a specific variable
107
-
$dotenv->load();
101
+
<?php
102
+
103
+
use NAL\Dotenv\Env;
108
104
109
-
$host = $dotenv->get('DB_HOST'); // Get a variable
110
-
$debug = $dotenv->get('DEBUG', false); // With fallback
111
-
$all = $dotenv->get(); // Get all loaded variables
105
+
$value = Env::get('APP_ENV');
106
+
$group = Env::group('APP');
112
107
```
108
+
> If no instance was created yet, Env::get() and Env::group() will auto-initialize using default behavior `(.env, no cache)`. If an instance was previously created via Env::create(), the static calls will reuse that instance instead.
113
109
114
-
###Check Existence
110
+
#### Safe Load (No Exceptions)
115
111
```php
116
-
if ($dotenv->has('APP_SECRET')) {
117
-
// APP_SECRET is defined
118
-
}
119
-
```
112
+
<?php
120
113
121
-
### Grouping Environment Variables
122
-
- You can access grouped environment variables with the group() method.
123
-
- This can be useful if you have variables structured by prefix (e.g., APP_NAME, APP_ENV).
- You can reload environment variables by calling the `reload()` method. This method clears the previously loaded variables and reloads them from the specified files.
128
+
#### Load Multiple Files
132
129
```php
133
-
$dotenv->reload(); // Clear and reload loaded files
0 commit comments