File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace Illuminate \Support ;
4
4
5
+ use Closure ;
5
6
use Dotenv \Repository \Adapter \PutenvAdapter ;
6
7
use Dotenv \Repository \RepositoryBuilder ;
7
8
use PhpOption \Option ;
@@ -23,6 +24,13 @@ class Env
23
24
*/
24
25
protected static $ repository ;
25
26
27
+ /**
28
+ * The list of custom adapters for environment variables loading.
29
+ *
30
+ * @var array<Closure>
31
+ */
32
+ protected static $ customAdapters = [];
33
+
26
34
/**
27
35
* Enable the putenv adapter.
28
36
*
@@ -45,6 +53,16 @@ public static function disablePutenv()
45
53
static ::$ repository = null ;
46
54
}
47
55
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
+
48
66
/**
49
67
* Get the environment repository instance.
50
68
*
@@ -59,6 +77,10 @@ public static function getRepository()
59
77
$ builder = $ builder ->addAdapter (PutenvAdapter::class);
60
78
}
61
79
80
+ foreach (static ::$ customAdapters as $ adapter ) {
81
+ $ builder = $ builder ->addAdapter ($ adapter ());
82
+ }
83
+
62
84
static ::$ repository = $ builder ->immutable ()->make ();
63
85
}
64
86
You can’t perform that action at this time.
0 commit comments