@@ -48,6 +48,13 @@ Env::load(__DIR__ . '/.env');
4848echo Env::get('APP_NAME'); // "MyApp"
4949```
5050
51+ Optional casting:
52+
53+ ``` php
54+ Env::getCast('FEATURE_ENABLED', false, true); // true
55+ Env::getCast('OPTIONAL_VALUE', 'default', true); // null
56+ ```
57+
5158Common options:
5259
5360``` php
@@ -104,14 +111,14 @@ $loader->loadFiles([__DIR__ . '/.env', __DIR__ . '/.env.local']);
104111
105112Notes:
106113
107- - When encoding is null, no conversion is performed, even if mbstring is available.
108- - UTF-8 BOM is stripped automatically.
114+ - When encoding is null, no conversion is performed, even if mbstring is available.
115+ - UTF-8 BOM is stripped automatically.
109116
110117## Features
111118
112119- Loading ` .env ` files into ` $_ENV ` , ` $_SERVER ` , and via ` putenv() ` .
113120- Does not override variables already present in ` $_ENV ` , ` $_SERVER ` , or ` getenv() ` .
114- - Values are returned as strings; no automatic casting is applied .
121+ - Values are returned as strings by default; ` Env::getCast() ` enables optional casting .
115122- Quoted strings with escaped quotes and ` \n ` , ` \r ` , ` \t ` , ` \v ` , ` \f ` in double quotes (single quotes are literal).
116123- Inline comments start with ` # ` in unquoted values (use quotes to keep a literal ` # ` ).
117124- Unquoted values cannot contain whitespace.
@@ -128,31 +135,31 @@ Notes:
128135
129136## Parse Formats
130137
131- | Method | Return format |
132- | --- | --- |
133- | ` Env::parse() ` | Raw entries: ` [[name, value, vars], ...] ` |
134- | ` Env::parseToArray() ` | Associative map: ` ['NAME' => 'value', ...] ` |
135- | ` EnvParser::parseStringRaw() ` | Raw entries: ` [[name, value, vars], ...] ` |
138+ | Method | Return format |
139+ | ----------------------------- | ---------------------------------------- --- |
140+ | ` Env::parse() ` | Raw entries: ` [[name, value, vars], ...] ` |
141+ | ` Env::parseToArray() ` | Associative map: ` ['NAME' => 'value', ...] ` |
142+ | ` EnvParser::parseStringRaw() ` | Raw entries: ` [[name, value, vars], ...] ` |
136143
137144Strict mode throws ` InvalidFileException ` on duplicate names for ` parse() ` and ` parseToArray() ` .
138145
139146## Load Files Order
140147
141- - ` loadFiles() ` processes paths in the order provided.
142- - Glob patterns are expanded using ` glob() ` with ` GLOB_BRACE ` by default.
143- - Glob matches are sorted to keep load order stable.
144- - Use the optional ` globFlags ` parameter to change ` glob() ` behavior.
145- - If ` strictResolve ` is true, unresolved ` ${VAR} ` or ` $VAR ` references in any loaded file will throw ` InvalidFileException ` .
146- - If ` shortCircuit ` is true, the first successfully loaded file stops further processing.
147- - If ` shortCircuit ` is false, missing files raise ` InvalidPathException ` .
148+ - ` loadFiles() ` processes paths in the order provided.
149+ - Glob patterns are expanded using ` glob() ` with ` GLOB_BRACE ` by default.
150+ - Glob matches are sorted to keep load order stable.
151+ - Use the optional ` globFlags ` parameter to change ` glob() ` behavior.
152+ - If ` strictResolve ` is true, unresolved ` ${VAR} ` or ` $VAR ` references in any loaded file will throw ` InvalidFileException ` .
153+ - If ` shortCircuit ` is true, the first successfully loaded file stops further processing.
154+ - If ` shortCircuit ` is false, missing files raise ` InvalidPathException ` .
148155
149156## Exceptions
150157
151- | Scenario | Exception |
152- | --- | --- |
153- | Invalid syntax, invalid name, bad escapes | ` Codemonster\Env\Exception\InvalidFileException ` |
154- | Invalid or unsupported encoding | ` Codemonster\Env\Exception\InvalidEncodingException ` |
155- | Missing or unreadable file | ` Codemonster\Env\Exception\InvalidPathException ` |
158+ | Scenario | Exception |
159+ | ----------------------------------------- | ------------------------------------------------- --- |
160+ | Invalid syntax, invalid name, bad escapes | ` Codemonster\Env\Exception\InvalidFileException ` |
161+ | Invalid or unsupported encoding | ` Codemonster\Env\Exception\InvalidEncodingException ` |
162+ | Missing or unreadable file | ` Codemonster\Env\Exception\InvalidPathException ` |
156163
157164## Loader Interface
158165
0 commit comments