Skip to content

Commit 703e7fb

Browse files
Add Env::addExtraAdapter to support extra adapters when loading environment variables
1 parent 17b8f6d commit 703e7fb

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/Illuminate/Support/Env.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Support;
44

5+
use Closure;
56
use Dotenv\Repository\Adapter\PutenvAdapter;
67
use Dotenv\Repository\RepositoryBuilder;
78
use PhpOption\Option;
@@ -23,6 +24,13 @@ class Env
2324
*/
2425
protected static $repository;
2526

27+
/**
28+
* The list of custom adapters for environment variables loading.
29+
*
30+
* @var array<Closure>
31+
*/
32+
protected static $customAdapters = [];
33+
2634
/**
2735
* Enable the putenv adapter.
2836
*
@@ -45,6 +53,16 @@ public static function disablePutenv()
4553
static::$repository = null;
4654
}
4755

56+
/**
57+
* Register a custom adapter creator Closure.
58+
*
59+
* @return void
60+
*/
61+
public static function extend($name, Closure $callback)
62+
{
63+
static::$customAdapters[$name] = $callback;
64+
}
65+
4866
/**
4967
* Get the environment repository instance.
5068
*
@@ -59,6 +77,10 @@ public static function getRepository()
5977
$builder = $builder->addAdapter(PutenvAdapter::class);
6078
}
6179

80+
foreach (static::$customAdapters as $adapter) {
81+
$builder = $builder->addAdapter($adapter());
82+
}
83+
6284
static::$repository = $builder->immutable()->make();
6385
}
6486

0 commit comments

Comments
 (0)