-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.php
56 lines (51 loc) · 1.38 KB
/
function.php
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
<?php
try {
$dotenv = new Dotenv\Dotenv (__DIR__);
$dotenv->load();
} catch (\Exception $e) {}
function relativeURL () {
$dir = str_replace('\\', '/', __DIR__);
return substr($dir, strlen($_SERVER['DOCUMENT_ROOT']));
}
function startsWith($haystack, $needles) {
foreach ((array) $needles as $needle) {
if ($needle != '' && substr($haystack, 0, strlen($needle)) === (string) $needle) {
return true;
}
}
return false;
}
function endsWith($haystack, $needles) {
foreach ((array) $needles as $needle) {
if (substr($haystack, -strlen($needle)) === (string) $needle) {
return true;
}
}
return false;
}
if (! function_exists('env')) {
function env($key, $default = null) {
$value = getenv($key);
if ($value === false) {
return $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 && startsWith($value, '"') && endsWith($value, '"')) {
return substr($value, 1, -1);
}
return $value;
}
}