|
1
|
|
|
<?php
|
|
2
|
|
|
|
|
3
|
|
|
namespace Nip;
|
|
4
|
|
|
|
|
5
|
|
|
use Nip\Application\ApplicationInterface;
|
|
6
|
|
|
use Nip\Application\Bootstrap\CoreBootstrapersTrait;
|
|
7
|
|
|
use Nip\Application\Traits\BindPathsTrait;
|
|
8
|
|
|
use Nip\Application\Traits\EnviromentConfiguration;
|
|
9
|
|
|
use Nip\AutoLoader\AutoLoaderAwareTrait;
|
|
10
|
|
|
use Nip\AutoLoader\AutoLoaderServiceProvider;
|
|
11
|
|
|
use Nip\Container\ContainerAliasBindingsTrait;
|
|
12
|
|
|
use Nip\Container\ServiceProviders\ServiceProviderAwareTrait;
|
|
13
|
|
|
use Nip\Database\DatabaseServiceProvider;
|
|
14
|
|
|
use Nip\Dispatcher\DispatcherAwareTrait;
|
|
15
|
|
|
use Nip\Dispatcher\DispatcherServiceProvider;
|
|
16
|
|
|
use Nip\Filesystem\FilesystemServiceProvider;
|
|
17
|
|
|
use Nip\FlashData\FlashServiceProvider;
|
|
18
|
|
|
use Nip\Http\Response\Response;
|
|
19
|
|
|
use Nip\I18n\TranslatorServiceProvider;
|
|
20
|
|
|
use Nip\Inflector\InflectorServiceProvider;
|
|
21
|
|
|
use Nip\Locale\LocaleServiceProvider;
|
|
22
|
|
|
use Nip\Logger\LoggerServiceProvider;
|
|
23
|
|
|
use Nip\Mail\MailServiceProvider;
|
|
24
|
|
|
use Nip\Mvc\MvcServiceProvider;
|
|
25
|
|
|
use Nip\Router\RouterAwareTrait;
|
|
26
|
|
|
use Nip\Router\RouterServiceProvider;
|
|
27
|
|
|
use Nip\Router\RoutesServiceProvider;
|
|
28
|
|
|
use Nip\Staging\StagingAwareTrait;
|
|
29
|
|
|
use Nip\Staging\StagingServiceProvider;
|
|
30
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
31
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
32
|
|
|
|
|
33
|
|
|
/**
|
|
34
|
|
|
* Class Application
|
|
35
|
|
|
* @package Nip
|
|
36
|
|
|
*/
|
|
37
|
|
|
class Application implements ApplicationInterface
|
|
38
|
|
|
{
|
|
39
|
|
|
use ContainerAliasBindingsTrait;
|
|
40
|
|
|
use CoreBootstrapersTrait;
|
|
41
|
|
|
use ServiceProviderAwareTrait;
|
|
42
|
|
|
use BindPathsTrait;
|
|
43
|
|
|
use EnviromentConfiguration;
|
|
44
|
|
|
use AutoLoaderAwareTrait;
|
|
45
|
|
|
use RouterAwareTrait;
|
|
46
|
|
|
use DispatcherAwareTrait;
|
|
47
|
|
|
use StagingAwareTrait;
|
|
48
|
|
|
|
|
49
|
|
|
/**
|
|
50
|
|
|
* The ByTIC framework version.
|
|
51
|
|
|
*
|
|
52
|
|
|
* @var string
|
|
53
|
|
|
*/
|
|
54
|
|
|
const VERSION = '1.0.1';
|
|
55
|
|
|
|
|
56
|
|
|
/**
|
|
57
|
|
|
* Indicates if the application has "booted".
|
|
58
|
|
|
*
|
|
59
|
|
|
* @var bool
|
|
60
|
|
|
*/
|
|
61
|
|
|
protected $booted = false;
|
|
62
|
|
|
|
|
63
|
|
|
/**
|
|
64
|
|
|
* @var null|Request
|
|
65
|
|
|
*/
|
|
66
|
|
|
protected $request = null;
|
|
67
|
|
|
|
|
68
|
|
|
/**
|
|
69
|
|
|
* Create a new Illuminate application instance.
|
|
70
|
|
|
*
|
|
71
|
|
|
* @param string|null $basePath
|
|
72
|
|
|
*
|
|
73
|
|
|
* @return void
|
|
|
|
|
|
|
74
|
|
|
*/
|
|
75
|
1 |
|
public function __construct($basePath = null)
|
|
76
|
|
|
{
|
|
77
|
1 |
|
if ($basePath) {
|
|
|
|
|
|
|
78
|
|
|
$this->setBasePath($basePath);
|
|
79
|
|
|
}
|
|
80
|
1 |
|
}
|
|
81
|
|
|
|
|
82
|
|
|
public function setupAutoLoaderPaths()
|
|
83
|
|
|
{
|
|
84
|
|
|
}
|
|
85
|
|
|
|
|
86
|
|
|
public function boot()
|
|
87
|
|
|
{
|
|
88
|
|
|
if ($this->isBooted()) {
|
|
89
|
|
|
return;
|
|
90
|
|
|
}
|
|
91
|
|
|
|
|
92
|
|
|
$this->bootProviders();
|
|
93
|
|
|
$this->booted = true;
|
|
94
|
|
|
}
|
|
95
|
|
|
|
|
96
|
|
|
/**
|
|
97
|
|
|
* Determine if the application has booted.
|
|
98
|
|
|
*
|
|
99
|
|
|
* @return bool
|
|
100
|
|
|
*/
|
|
101
|
1 |
|
public function isBooted()
|
|
102
|
|
|
{
|
|
103
|
1 |
|
return $this->booted;
|
|
104
|
|
|
}
|
|
105
|
|
|
|
|
106
|
|
|
/** @noinspection PhpUnusedParameterInspection
|
|
107
|
|
|
*
|
|
108
|
|
|
* @param Request $request
|
|
109
|
|
|
* @param Response $response
|
|
110
|
|
|
* @return Response
|
|
111
|
|
|
*/
|
|
112
|
|
|
public function filterResponse(Response $response, Request $request)
|
|
|
|
|
|
|
113
|
|
|
{
|
|
114
|
|
|
return $response;
|
|
115
|
|
|
}
|
|
116
|
|
|
|
|
117
|
|
|
public function terminate()
|
|
118
|
|
|
{
|
|
119
|
|
|
}
|
|
120
|
|
|
|
|
121
|
|
|
/**
|
|
122
|
|
|
* @return array
|
|
123
|
|
|
*/
|
|
124
|
|
|
public function getConfiguredProviders()
|
|
125
|
|
|
{
|
|
126
|
|
|
return [
|
|
127
|
|
|
AutoLoaderServiceProvider::class,
|
|
128
|
|
|
LoggerServiceProvider::class,
|
|
129
|
|
|
InflectorServiceProvider::class,
|
|
130
|
|
|
LocaleServiceProvider::class,
|
|
131
|
|
|
MailServiceProvider::class,
|
|
132
|
|
|
MvcServiceProvider::class,
|
|
133
|
|
|
DispatcherServiceProvider::class,
|
|
134
|
|
|
StagingServiceProvider::class,
|
|
135
|
|
|
RouterServiceProvider::class,
|
|
136
|
|
|
RoutesServiceProvider::class,
|
|
137
|
|
|
DatabaseServiceProvider::class,
|
|
138
|
|
|
TranslatorServiceProvider::class,
|
|
139
|
|
|
FlashServiceProvider::class,
|
|
140
|
|
|
FilesystemServiceProvider::class,
|
|
141
|
|
|
];
|
|
142
|
|
|
}
|
|
143
|
|
|
|
|
144
|
|
|
/**
|
|
145
|
|
|
* Determine if the application configuration is cached.
|
|
146
|
|
|
*
|
|
147
|
|
|
* @return bool
|
|
148
|
|
|
*/
|
|
149
|
|
|
public function configurationIsCached()
|
|
150
|
|
|
{
|
|
151
|
|
|
return false;
|
|
152
|
|
|
// return file_exists($this->getCachedConfigPath());
|
|
|
|
|
|
|
153
|
|
|
}
|
|
154
|
|
|
|
|
155
|
|
|
/**
|
|
156
|
|
|
* Throw an HttpException with the given data.
|
|
157
|
|
|
*
|
|
158
|
|
|
* @param int $code
|
|
159
|
|
|
* @param string $message
|
|
160
|
|
|
* @param array $headers
|
|
161
|
|
|
* @return void
|
|
162
|
|
|
*
|
|
163
|
|
|
* @throws HttpException
|
|
164
|
|
|
*/
|
|
165
|
|
|
public function abort($code, $message = '', array $headers = [])
|
|
166
|
|
|
{
|
|
167
|
|
|
if ($code == 404) {
|
|
168
|
|
|
throw new NotFoundHttpException($message);
|
|
169
|
|
|
}
|
|
170
|
|
|
throw new HttpException($code, $message, null, $headers);
|
|
171
|
|
|
}
|
|
172
|
|
|
|
|
173
|
|
|
/**
|
|
174
|
|
|
* @return string
|
|
175
|
|
|
*/
|
|
176
|
4 |
|
public function getRootNamespace()
|
|
177
|
|
|
{
|
|
178
|
4 |
|
return 'App\\';
|
|
179
|
|
|
}
|
|
180
|
|
|
|
|
181
|
|
|
/**
|
|
182
|
|
|
* @param Request $request
|
|
183
|
|
|
* @return Response
|
|
184
|
|
|
*/
|
|
185
|
|
|
protected function getResponseFromRequest($request)
|
|
186
|
|
|
{
|
|
187
|
|
|
if ($request->hasMCA()) {
|
|
188
|
|
|
$response = $this->dispatchRequest($request);
|
|
189
|
|
|
ob_get_clean();
|
|
190
|
|
|
|
|
191
|
|
|
return $response;
|
|
192
|
|
|
}
|
|
193
|
|
|
|
|
194
|
|
|
throw new NotFoundHttpException('No MCA in Request');
|
|
195
|
|
|
}
|
|
196
|
|
|
}
|
|
197
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.