-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
55 lines (51 loc) · 1.78 KB
/
index.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
<?php
use Bnomei\DotEnv;
use Kirby\Toolkit\A;
@include_once __DIR__.'/vendor/autoload.php';
@include_once __DIR__.'/global.php';
Kirby::plugin('bnomei/dotenv', [
'options' => [
'dir' => function (): array {
return [
kirby()->roots()->index(), // default setup (like official starter-kit)
realpath(kirby()->roots()->index().'/../'), // public/storage folder setup
];
},
'file' => '.env',
'environment' => function (): string {
$hosts = [
A::get($_ENV, 'KIRBY_HOST'),
A::get($_SERVER, 'HTTP_HOST'), // insecure
A::get($_SERVER, 'SERVER_NAME'),
A::get($_SERVER, 'SERVER_ADDR'),
];
// first non-empty value get non-port part
return explode(':', strval(A::first(array_filter($hosts))))[0];
},
'required' => [],
'setup' => function ($dotenv) {
// overwrite this callback if you want to do additional tasks
// $dotenv->required('FOO');
return $dotenv;
},
],
'pageMethods' => [
'env' => function (string $env, mixed $default = null) {
return DotEnv::getenv($env, $default);
},
'getenv' => function (string $env, mixed $default = null) {
return DotEnv::getenv($env, $default);
},
],
'siteMethods' => [
'env' => function (string $env, mixed $default = null) {
return DotEnv::getenv($env, $default);
},
'getenv' => function (string $env, mixed $default = null) {
return DotEnv::getenv($env, $default);
},
'loadenv' => function (array $options = []): bool {
return DotEnv::load($options);
},
],
]);