-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathReboot.php
More file actions
80 lines (70 loc) · 2.28 KB
/
Reboot.php
File metadata and controls
80 lines (70 loc) · 2.28 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
<?php
/**
* Author and copyright: Stefan Haack (https://shaack.com)
* Repository: https://github.com/shaack/reboot-cms
* License: MIT, see file 'LICENSE'
*/
namespace Shaack\Reboot;
use Shaack\Logger;
use Symfony\Component\Yaml\Yaml;
class Reboot
{
private string $baseFsPath; // the base/root dir of this reboot-cms in the file system, full path
private string $baseWebPath; // the base url "https://" . [domain] . [baseWebPath}
private array $config; // Local configuration, defined in `/local/config.yml`
/**
* A path does NOT end with a "/". The root web path is ""
* @param string $baseDir
* @param string $sitePath
* @param string $siteWebPath
*/
public function __construct(string $baseDir, string $sitePath, string $siteWebPath = "")
{
$this->baseFsPath = $baseDir;
$this->config = Yaml::parseFile($this->baseFsPath . '/local/config.yml');
Logger::setLevel($this->config['logLevel']);
Logger::debug("Reboot CMS");
Logger::debug("you should set the loglevel to 2 (error) in production (/local/config.yml)");
Logger::info("--- " . $_SERVER["REQUEST_URI"]);
$this->baseWebPath = preg_replace('/(\/web)?(\/admin)?\/index\.php$/', '', $_SERVER['PHP_SELF']);
Logger::debug("reboot->baseFsPath: " . $this->baseFsPath);
Logger::debug("reboot->baseWebPath: " . $this->baseWebPath);
$site = new Site($this, $sitePath, $siteWebPath);
$request = new Request($site, $this->baseWebPath, $_SERVER["REQUEST_URI"], $_POST);
echo $site->render($request);
}
// Public API
/**
* @param $url
*/
public function redirect($url)
{
Logger::info("=> redirect: " . $url);
header("Location: " . $url);
exit;
}
/**
* The CMS root in file system
* @return string
*/
public function getBaseFsPath(): string
{
return $this->baseFsPath;
}
/**
* The base URL, requests got to `/web` and sub folders
* @return string
*/
public function getBaseWebPath(): string
{
return $this->baseWebPath;
}
/**
* Local configuration, defined in `/local/config.yml`
* @return array
*/
public function getConfig(): array
{
return $this->config;
}
}