-
Notifications
You must be signed in to change notification settings - Fork 5
/
start.php
118 lines (108 loc) · 4.63 KB
/
start.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
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
108
109
110
111
112
113
114
115
116
117
118
<?php
use Opulence\Applications\Tasks\TaskTypes;
use Opulence\Environments\Environment;
use Opulence\Framework\Configuration\Config;
use Opulence\Framework\Http\Kernel;
use Opulence\Http\Requests\Request;
use Opulence\Ioc\Bootstrappers\Caching\FileCache;
use Opulence\Ioc\Bootstrappers\Dispatchers\BootstrapperDispatcher;
use Opulence\Ioc\Bootstrappers\Dispatchers\IBootstrapperDispatcher;
use Opulence\Ioc\Bootstrappers\Factories\BootstrapperRegistryFactory;
use Opulence\Ioc\Bootstrappers\Factories\CachedBootstrapperRegistryFactory;
use Opulence\Ioc\Bootstrappers\IBootstrapperRegistry;
use Opulence\Routing\Router;
/**
* ----------------------------------------------------------
* Create your paths
* ----------------------------------------------------------
*/
$paths = require_once __DIR__ . "/../../config/paths.php";
/**
* ----------------------------------------------------------
* Set up the environment
* ----------------------------------------------------------
*/
require __DIR__ . "/../../config/environment.php";
/**
* ----------------------------------------------------------
* Set up the exception and error handlers
* ----------------------------------------------------------
*/
$logger = require __DIR__ . "/../../config/http/logging.php";
$exceptionHandler = require_once __DIR__ . "/../../config/http/exceptions.php";
$errorHandler = require_once __DIR__ . "/../../config/http/errors.php";
$exceptionHandler->register();
$errorHandler->register();
/**
* ----------------------------------------------------------
* Initialize some application variables
* ----------------------------------------------------------
*/
$application = require_once __DIR__ . "/../../config/application.php";
/**
* ----------------------------------------------------------
* Load some HTTP-specific config settings
* ----------------------------------------------------------
*/
Config::setCategory("routing", require_once Config::get("paths", "config.http") . "/routing.php");
Config::setCategory("sessions", require_once Config::get("paths", "config.http") . "/sessions.php");
/**
* ----------------------------------------------------------
* Configure the bootstrappers for the HTTP kernel
* ----------------------------------------------------------
*/
$httpBootstrappers = require Config::get("paths", "config.http") . "/bootstrappers.php";
$allBootstrappers = array_merge($globalBootstrappers, $httpBootstrappers);
// If you should cache your bootstrapper registry
if (Environment::getVar("ENV_NAME") == Environment::PRODUCTION) {
$bootstrapperCache = new FileCache(
Config::get("paths", "tmp.framework.http") . "/cachedBootstrapperRegistry.json"
);
$bootstrapperFactory = new CachedBootstrapperRegistryFactory($bootstrapperResolver, $bootstrapperCache);
$bootstrapperRegistry = $bootstrapperFactory->createBootstrapperRegistry($allBootstrappers);
} else {
$bootstrapperFactory = new BootstrapperRegistryFactory($bootstrapperResolver);
$bootstrapperRegistry = $bootstrapperFactory->createBootstrapperRegistry($allBootstrappers);
}
$bootstrapperDispatcher = new BootstrapperDispatcher($container, $bootstrapperRegistry, $bootstrapperResolver);
$container->bindInstance(IBootstrapperRegistry::class, $bootstrapperRegistry);
$container->bindInstance(IBootstrapperDispatcher::class, $bootstrapperDispatcher);
$taskDispatcher->registerTask(
TaskTypes::PRE_START,
function () use ($bootstrapperDispatcher) {
$bootstrapperDispatcher->startBootstrappers(false);
}
);
$taskDispatcher->registerTask(
TaskTypes::PRE_SHUTDOWN,
function () use ($bootstrapperDispatcher) {
$bootstrapperDispatcher->shutDownBootstrappers();
}
);
/**
* ----------------------------------------------------------
* Let's get started
* ----------------------------------------------------------
*/
$application->start(function () use ($container, $exceptionHandler, $exceptionRenderer) {
/**
* ----------------------------------------------------------
* Handle the request
* ----------------------------------------------------------
*
* @var Router $router
* @var Request $request
*/
$router = $container->resolve(Router::class);
$request = $container->resolve(Request::class);
$kernel = new Kernel($container, $router, $exceptionHandler, $exceptionRenderer);
$kernel->addMiddleware(require_once Config::get("paths", "config.http") . "/middleware.php");
$response = $kernel->handle($request);
$response->send();
});
/**
* ----------------------------------------------------------
* Shut her down
* ----------------------------------------------------------
*/
$application->shutDown();