-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.php
More file actions
131 lines (95 loc) · 2.53 KB
/
Copy pathenv.php
File metadata and controls
131 lines (95 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
if ( ! function_exists( 'load_env' ) ) {
/**
* Load the environment file if it exists
*
* @param string $path
* @return boolean Always returns true.
*/
function load_env( $path ) {
$path = rtrim( $path, '/' );
if( file_exists( $path . '/.env' ) ) {
$dotenv = new Dotenv\Dotenv( $path );
$dotenv->load();
}
return true;
}
}
if ( ! function_exists( 'env' ) ) {
/**
* Gets the value of an environment variable. Supports boolean, empty and null.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
function env( $key, $default = null ) {
$value = getenv( $key );
if ( $value === false ) {
return value( $default );
}
switch ( strtolower( $value ) ) {
case 'true' :
case '(true)' :
return true;
case 'false' :
case '(false)' :
return false;
case 'empty' :
case '(empty)' :
return '';
case 'null' :
case '(null)' :
return;
}
if ( strlen( $value ) > 1 && str_starts_with( $value, '"' ) && str_ends_with( $value, '"' ) ) {
return substr( $value, 1, -1 );
}
return $value;
}
}
if ( ! function_exists( 'value' ) ) {
/**
* Return the default value of the given value.
*
* @param mixed $value
* @return mixed
*/
function value( $value ) {
return $value instanceof Closure ? $value() : $value;
}
}
if( ! function_exists( 'str_starts_with' ) ) {
/**
* Check if a string starts with a list of characters.
*
* @param string $haystack
* @param string|array $needles
* @return boolean
*/
function str_starts_with( $haystack, $needles ) {
foreach( (array)$needles as $needle ) {
if( $needle != '' && strpos( $haystack, $needle ) === 0 ) {
return true;
}
}
return false;
}
}
if( ! function_exists( 'str_ends_with' ) ) {
/**
* Check if a string starts with a list of characters.
*
* @param string $haystack
* @param string|array $needles
* @return boolean
*/
function str_ends_with( $haystack, $needles ) {
foreach ( (array) $needles as $needle ) {
if ( (string)$needle === substr( $haystack, -strlen( $needle ) ) ) {
return true;
}
}
return false;
}
}