Skip to content

Commit 63bc969

Browse files
committed
feat: add env loader
1 parent f2f1169 commit 63bc969

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/Core.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,32 @@ public static function loadConsole($externalCommands = [])
451451
}
452452
}
453453

454+
/**
455+
* Load and force-load application env into app context
456+
* @param string $directory Application root directory
457+
* @return void
458+
*/
459+
public static function loadApplicationEnv(string $directory)
460+
{
461+
\Dotenv\Dotenv::createUnsafeImmutable($directory)->safeLoad();
462+
463+
if ($_ENV['APP_ENV'] !== 'production') {
464+
foreach ($_ENV as $key => $value) {
465+
putenv(assignment: $key);
466+
unset($_ENV[$key], $_SERVER[$key]);
467+
}
468+
469+
\Dotenv\Dotenv::createUnsafeImmutable($directory)->load();
470+
}
471+
}
472+
454473
/**
455474
* Load all application routes and run the application
475+
* @return void
456476
*/
457477
public static function runApplication()
458478
{
459-
// trick process into setting Leaf up
479+
// trick process into setting Leaf up for errors, sessions, etc
460480
app();
461481

462482
try {

0 commit comments

Comments
 (0)