-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
bootstrap.php
66 lines (54 loc) · 1.24 KB
/
bootstrap.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
57
58
59
60
61
62
63
64
65
66
<?php
namespace Kirby\CLI;
/**
* Tries to load the kirby index.php
*/
function bootstrap(): string|null
{
if ($index = index()) {
// switch off the renderer to
// avoid any output in the CLI
$_ENV['KIRBY_RENDER'] = false;
if (empty($_ENV['KIRBY_HOST']) === false) {
$_SERVER['SERVER_NAME'] = $_ENV['KIRBY_HOST'];
$_SERVER['HTTP_HOST'] = $_ENV['KIRBY_HOST'];
}
ob_start();
require $index;
ob_end_clean();
// rendering could be useful in commands
// again. That's why we switch it back on
$_ENV['KIRBY_RENDER'] = true;
}
return $index;
}
/**
* Returns the absolute path
* to the Kirby index.php if it
* can be found
*
* @return string|null
*/
function index(): string|null
{
$locations = [
'./',
'./www',
'./public',
'./public_html'
];
foreach ($locations as $location) {
// try to find the index.php in current working directory
$index = realpath(getcwd() . '/' . $location . '/index.php');
if ($index !== false) {
return $index;
}
// try to find the index.php from the (possible) root of the project
// in the __ROOT__ <- /vendor/getkirby/cli directory
$index = realpath(dirname(__DIR__, 3) . '/' . $location . '/index.php');
if ($index !== false) {
return $index;
}
}
return null;
}