-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplication.php
152 lines (127 loc) · 3.13 KB
/
Application.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
namespace Steel;
use Steel\Injectors\Request;
use Steel\Injectors\Response;
use Steel\Injectors\Config;
use Steel\Injectors\Router;
use Steel\Container\Injector as Container;
use Steel\Request\Header\Accepts\HTML as AcceptHTML;
use Steel\Request\Header\Accepts\JSON as AcceptJSON;
/**
* Application
*/
class Application implements Interfaces\Application
{
use Request;
use Response;
use Config;
use Router;
use Container;
/**
* Response
*
* @var Response;
*/
protected $response;
/**
* Request
*
* @var Request;
*/
protected $request;
/**
* Request
*
* @var Request;
*/
protected $router;
/**
* Application Config
*
* @var array
*/
protected $applicationConfig;
protected $container;
/**
* @param null $config
*/
protected function __construct($config = null)
{
$this->container = $this->getContainer();
$this->applicationConfig = $config;
$this->config = $this->getConfig($this->getCoreConfigurationFile());
$this->response = $this->getResponse();
$this->request = $this->getRequest();
$contained = $this->getContainer()->whatsContained();
$this->router = $this->getRouter($this->config->get()->routes);
}
/**
* @static
* @param null $config
* @return Application
*/
public static function start($config = null)
{
static $self;
if (!isset( $self )) {
$self = new self( $config );
}
return $self;
}
/**
* Run the application
*/
public function run(Interfaces\Request $request = null)
{
$route = $this->router->getRoute($request ? $request : $this->request);
$route->follow();
}
/**
*/
public function runConfig()
{
$config = (array) $this->config->get();
echo '<pre>';
var_dump($_SERVER, $_ENV);
var_dump($this->request->accepts(new AcceptHTML()));
var_dump($this->request->accepts(new AcceptJSON()));
phpinfo();
}
/**
* Is the application in configuration mode
*
* @return boolean
*/
public function isApplicationInConfigMode()
{
return $this->applicationConfig['applicationConf'];
}
public function isApplicationInDebugMode()
{
return $this->applicationConfig['applicationDebug'];
}
public function applicationDirectory()
{
return $this->applicationConfig['applicationDir'];
}
public function applicationEnvironment()
{
return $this->applicationConfig['applicationEnv'];
}
public function getCoreConfigurationFile()
{
return
$this->getConfigurationDirectory()
. DIRECTORY_SEPARATOR
. $this->applicationConfig['configCore']
. $this->getConfigurationExtension();
}
public function getConfigurationDirectory()
{
return $this->applicationConfig['configDir'];
}
public function getConfigurationExtension()
{
return $this->applicationConfig['configExt'];
}
}