1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the O2System Framework package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @author Steeve Andrian Salim |
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
// ------------------------------------------------------------------------ |
13
|
|
|
|
14
|
|
|
namespace O2System; |
15
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------ |
17
|
|
|
|
18
|
|
|
/* |
19
|
|
|
*--------------------------------------------------------------- |
20
|
|
|
* KERNEL PATH |
21
|
|
|
*--------------------------------------------------------------- |
22
|
|
|
* |
23
|
|
|
* RealPath to application folder. |
24
|
|
|
* |
25
|
|
|
* WITH TRAILING SLASH! |
26
|
|
|
*/ |
27
|
|
|
if ( ! defined('PATH_KERNEL')) { |
28
|
|
|
define('PATH_KERNEL', __DIR__ . DIRECTORY_SEPARATOR); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
require_once 'Helpers/Kernel.php'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Class Kernel |
35
|
|
|
* |
36
|
|
|
* @package O2System |
37
|
|
|
*/ |
38
|
|
|
class Kernel extends Spl\Patterns\Creational\Singleton\AbstractSingleton |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* Kernel Services |
42
|
|
|
* |
43
|
|
|
* @var Kernel\Containers\Services |
44
|
|
|
*/ |
45
|
|
|
public $services; |
46
|
|
|
|
47
|
|
|
// ------------------------------------------------------------------------ |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Kernel::__construct |
51
|
|
|
*/ |
52
|
|
|
protected function __construct() |
53
|
|
|
{ |
54
|
|
|
parent::__construct(); |
55
|
|
|
|
56
|
|
|
$this->services = new Kernel\Containers\Services(); |
57
|
|
|
|
58
|
|
|
if (isset($_ENV[ 'DEBUG_STAGE' ]) and $_ENV[ 'DEBUG_STAGE' ] === 'DEVELOPER') { |
59
|
|
|
if(class_exists('\O2System\Gear\Profiler')) { |
60
|
|
|
$this->services->load(Gear\Profiler::class); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
if (profiler() !== false) { |
64
|
|
|
profiler()->watch('Starting Kernel Services'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$services = [ |
69
|
|
|
'Services\Language' => 'language' |
70
|
|
|
]; |
71
|
|
|
|
72
|
|
|
foreach ($services as $className => $classOffset) { |
73
|
|
|
$this->services->load($className, $classOffset); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
if (class_exists('O2System\Framework', false) or class_exists( |
77
|
|
|
'O2System\Reactor', false)) { |
78
|
|
|
if (profiler() !== false) { |
79
|
|
|
profiler()->watch('Starting Kernel I/O Service'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
if (is_cli()) { |
83
|
|
|
$this->cliIO(); |
84
|
|
|
} else { |
85
|
|
|
$this->httpIO(); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
// ------------------------------------------------------------------------ |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Kernel::cliIO |
94
|
|
|
* |
95
|
|
|
* Runs command line input/output services. |
96
|
|
|
*/ |
97
|
|
|
private function cliIO() |
98
|
|
|
{ |
99
|
|
|
$services = [ |
100
|
|
|
'Cli\Input' => 'input', |
101
|
|
|
'Cli\Output' => 'output', |
102
|
|
|
]; |
103
|
|
|
|
104
|
|
|
foreach ($services as $className => $classOffset) { |
105
|
|
|
$this->services->load($className, $classOffset); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
// ------------------------------------------------------------------------ |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Kernel::httpIO |
113
|
|
|
* |
114
|
|
|
* Runs http input/output services. |
115
|
|
|
*/ |
116
|
|
|
private function httpIO() |
117
|
|
|
{ |
118
|
|
|
$services = [ |
119
|
|
|
'Http\Message\ServerRequest' => 'serverRequest', |
120
|
|
|
'Http\Input' => 'input', |
121
|
|
|
'Http\Output' => 'output', |
122
|
|
|
]; |
123
|
|
|
|
124
|
|
|
foreach ($services as $className => $classOffset) { |
125
|
|
|
$this->services->load($className, $classOffset); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
// ------------------------------------------------------------------------ |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Kernel::__isset |
133
|
|
|
* |
134
|
|
|
* @param string $property |
135
|
|
|
* |
136
|
|
|
* @return bool |
137
|
|
|
*/ |
138
|
|
|
public function __isset($property) |
139
|
|
|
{ |
140
|
|
|
return (bool)isset($this->{$property}); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
// ------------------------------------------------------------------------ |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Kernel::__get |
147
|
|
|
* |
148
|
|
|
* @param string $property |
149
|
|
|
* |
150
|
|
|
* @return mixed |
151
|
|
|
*/ |
152
|
|
|
public function &__get($property) |
153
|
|
|
{ |
154
|
|
|
$get[ $property ] = null; |
|
|
|
|
155
|
|
|
|
156
|
|
|
if (isset($this->{$property})) { |
157
|
|
|
$get[ $property ] =& $this->{$property}; |
158
|
|
|
} elseif ($this->services->has($property)) { |
159
|
|
|
$get[ $property ] = $this->services->get($property); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
return $get[ $property ]; |
163
|
|
|
} |
164
|
|
|
} |