1
|
|
|
<?php |
2
|
|
|
namespace samsonphp\core; |
3
|
|
|
|
4
|
|
|
use samsonframework\core\SystemInterface; |
5
|
|
|
use samsonframework\resource\ResourceMap; |
6
|
|
|
use samsonphp\config\Scheme; |
7
|
|
|
use samsonphp\event\Event; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Core |
11
|
|
|
* |
12
|
|
|
* @package samsonphp/core |
13
|
|
|
* @author Vitaly Iegorov <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class Core implements SystemInterface |
16
|
|
|
{ |
17
|
|
|
/** @var string Current system environment */ |
18
|
|
|
protected $environment; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Core constructor |
22
|
|
|
*/ |
23
|
|
|
public function __construct() |
24
|
|
|
{ |
25
|
|
|
// TODO: Remove as hard dependency - create bridge/etc |
26
|
|
|
$whoops = new \Whoops\Run; |
27
|
|
|
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler); |
|
|
|
|
28
|
|
|
$whoops->register(); |
29
|
|
|
|
30
|
|
|
// Fire core creation event |
31
|
|
|
Event::fire('core.created', array(&$this)); |
32
|
|
|
|
33
|
|
|
// Signal core configure event |
34
|
|
|
Event::signal('core.configure', array($this->system_path . __SAMSON_CONFIG_PATH)); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Change current system working environment or receive |
39
|
|
|
* current system enviroment if no arguments are passed. |
40
|
|
|
* |
41
|
|
|
* @param string $environment Environment identifier |
42
|
|
|
* |
43
|
|
|
* TODO: Function has two different logics - needs to be changed! |
44
|
|
|
* @return $this|string Chaining or current system environment |
45
|
|
|
*/ |
46
|
|
|
public function environment($environment = Scheme::BASE) |
47
|
|
|
{ |
48
|
|
|
if (func_num_args() !== 0) { |
49
|
|
|
$this->environment = $environment; |
50
|
|
|
|
51
|
|
|
// Signal core environment change |
52
|
|
|
Event::signal('core.environment.change', array($environment, &$this)); |
53
|
|
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $this->environment; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Start SamsonPHP framework. |
61
|
|
|
* |
62
|
|
|
* @param string $default Default module identifier |
63
|
|
|
* |
64
|
|
|
* @throws ViewPathNotFound |
65
|
|
|
*/ |
66
|
|
|
public function start($default) |
67
|
|
|
{ |
68
|
|
|
// Fire core started event |
69
|
|
|
Event::fire('core.started'); |
70
|
|
|
|
71
|
|
|
// Security layer |
72
|
|
|
$securityResult = true; |
73
|
|
|
// Fire core security event |
74
|
|
|
Event::fire('core.security', array(&$this, &$securityResult)); |
75
|
|
|
|
76
|
|
|
/** @var mixed $result External route controller action result */ |
77
|
|
|
$result = false; |
78
|
|
|
|
79
|
|
|
// If we have passed security application layer |
80
|
|
|
if ($securityResult) { |
81
|
|
|
// Fire core routing event - go to routing application layer |
82
|
|
|
Event::signal('core.routing', array(&$this, &$result, $default)); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
// If no one has passed back routing callback |
86
|
|
|
if (!isset($result) || $result === false) { |
87
|
|
|
// Fire core e404 - routing failed event |
88
|
|
|
$result = Event::signal('core.e404', array(url()->module, url()->method)); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
// Response |
92
|
|
|
$output = ''; |
93
|
|
|
|
94
|
|
|
// If this is not asynchronous response and controller has been executed |
95
|
|
|
if ($result !== false) { |
96
|
|
|
// Fire after render event |
97
|
|
|
Event::fire('core.rendered', array(&$output)); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
// Output results to client |
101
|
|
|
echo $output; |
102
|
|
|
|
103
|
|
|
// Fire ended event |
104
|
|
|
Event::fire('core.ended', array(&$output)); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: