-
-
Notifications
You must be signed in to change notification settings - Fork 999
Expand file tree
/
Copy pathBootloader.php
More file actions
99 lines (75 loc) · 2.17 KB
/
Copy pathBootloader.php
File metadata and controls
99 lines (75 loc) · 2.17 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
<?php
namespace Leantime\Core;
use Illuminate\Contracts\Container\BindingResolutionException;
use Leantime\Core\Console\ConsoleKernel;
use Leantime\Core\Events\DispatchesEvents;
use Leantime\Core\Http\HttpKernel;
use Leantime\Core\Http\IncomingRequest;
/**
* Bootloader
*/
class Bootloader
{
use DispatchesEvents;
/**
* Bootloader instance
*/
protected static ?Bootloader $instance = null;
protected Application $app;
/**
* Get the Bootloader instance
*/
public static function getInstance(): self
{
if (is_null(static::$instance)) {
static::$instance = new self;
}
return static::$instance;
}
/**
* Constructor
*/
private function __construct() {}
/**
* Execute the Application lifecycle.
*
* @return void
*
* @throws BindingResolutionException
*/
public function boot(Application $app)
{
// Start Application
// Load the bindings and service providers
$this->app = $app;
// Capture the request and instantiate the correct type
$request = IncomingRequest::capture();
// Use the right kernel for the job and handle the request.
$this->handleRequest($request);
self::dispatchEvent('end', ['bootloader' => $this]);
}
/**
* Handle the request
*
* @throws BindingResolutionException
*/
private function handleRequest($request): void
{
if (! $this->app->runningInConsole()) {
/** @var HttpKernel $kernel */
$kernel = $this->app->make(HttpKernel::class);
$kernelHandler = $kernel->handle($request);
$response = $kernelHandler->send();
$kernel->terminate($request, $response);
} else {
/** @var ConsoleKernel $kernel */
$kernel = $this->app->make(ConsoleKernel::class);
$status = $kernel->handle(
$input = new \Symfony\Component\Console\Input\ArgvInput,
new \Symfony\Component\Console\Output\ConsoleOutput
);
$kernel->terminate($input, $status);
exit($status);
}
}
}