Repository navigation
Expand file tree
/
Copy pathBootstrap.php
More file actions
executable file
·107 lines (94 loc) · 2.38 KB
/
Copy pathBootstrap.php
File metadata and controls
executable file
·107 lines (94 loc) · 2.38 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
<?php
/**
* Webiny Framework (http://www.webiny.com/framework)
*
* @copyright Copyright Webiny LTD
*/
namespace Webiny\Component\Bootstrap;
use Webiny\Component\StdLib\SingletonTrait;
/**
* Bootstrap base class.
*
* @package Webiny\Component\Bootstrap
*/
class Bootstrap
{
use SingletonTrait;
/**
* @var string Application absolute root path.
*/
private $absolutePath;
/**
* @var Environment
*/
private $environment;
/**
* @var Router
*/
private $router;
/**
* Initializes the environment and the router.
* Router takes the process from there.
*
* @param string $appPath Path to the application root.
*
* @throws BootstrapException
* @throws \Exception
*/
public function runApplication($appPath = '')
{
if ($appPath != '') {
$rootPath = $appPath;
} else {
$rootPath = realpath(dirname(debug_backtrace()[0]['file']) . '/../');
}
// save the root path
$this->absolutePath = realpath($rootPath) . DIRECTORY_SEPARATOR;
$this->initializeEnvironment($this->absolutePath);
$this->initializeRouter();
}
/**
* Initializes the application environment.
*
* @param string $appPath Path to the application root.
*
* @throws BootstrapException
* @throws \Exception
*/
public function initializeEnvironment($appPath)
{
try {
// initialize the environment and its configurations
$this->environment = Environment::getInstance();
$this->environment->initializeEnvironment($appPath);
} catch (BootstrapException $e) {
throw $e;
}
}
/**
* Initializes the router.
*
* @throws BootstrapException
* @throws \Exception
*/
public function initializeRouter()
{
try {
// initialize router
$this->router = Router::getInstance();
// if a route is matched, a dispatcher instance is returned, and the callback is issued
$this->router->initializeRouter()->issueCallback();
} catch (BootstrapException $e) {
throw $e;
}
}
/**
* Returns current environment instance.
*
* @return Environment
*/
public function getEnvironment()
{
return $this->environment;
}
}