1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Quantum PHP Framework |
5
|
|
|
* |
6
|
|
|
* An open source software development framework for PHP |
7
|
|
|
* |
8
|
|
|
* @package Quantum |
9
|
|
|
* @author Arman Ag. <[email protected]> |
10
|
|
|
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) |
11
|
|
|
* @link http://quantum.softberg.org/ |
12
|
|
|
* @since 2.9.5 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Quantum\App\Adapters; |
16
|
|
|
|
17
|
|
|
use Quantum\Libraries\Encryption\Exceptions\CryptorException; |
18
|
|
|
use Quantum\Libraries\Database\Exceptions\DatabaseException; |
19
|
|
|
use Quantum\Libraries\Session\Exceptions\SessionException; |
20
|
|
|
use Quantum\Libraries\Logger\Exceptions\LoggerException; |
21
|
|
|
use Quantum\Libraries\Config\Exceptions\ConfigException; |
22
|
|
|
use Quantum\Middleware\Exceptions\MiddlewareException; |
23
|
|
|
use Quantum\Libraries\Csrf\Exceptions\CsrfException; |
24
|
|
|
use Quantum\Libraries\Lang\Exceptions\LangException; |
25
|
|
|
use Quantum\Router\Exceptions\ModuleLoaderException; |
26
|
|
|
use Quantum\Environment\Exceptions\EnvException; |
27
|
|
|
use Quantum\Exceptions\StopExecutionException; |
28
|
|
|
use Quantum\Router\Exceptions\RouteException; |
29
|
|
|
use Quantum\Exceptions\ControllerException; |
30
|
|
|
use Quantum\App\Contracts\AppInterface; |
31
|
|
|
use Quantum\Di\Exceptions\DiException; |
32
|
|
|
use Quantum\Exceptions\BaseException; |
33
|
|
|
use Quantum\Exceptions\ViewException; |
34
|
|
|
use Quantum\App\Traits\WebAppTrait; |
35
|
|
|
use DebugBar\DebugBarException; |
36
|
|
|
use Quantum\Debugger\Debugger; |
37
|
|
|
use Quantum\Hooks\HookManager; |
38
|
|
|
use Twig\Error\RuntimeError; |
39
|
|
|
use Twig\Error\SyntaxError; |
40
|
|
|
use Twig\Error\LoaderError; |
41
|
|
|
use Quantum\Mvc\MvcManager; |
42
|
|
|
use Quantum\Http\Response; |
43
|
|
|
use Quantum\Http\Request; |
44
|
|
|
use ReflectionException; |
45
|
|
|
use Quantum\Di\Di; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Class WebAppAdapter |
49
|
|
|
* @package Quantum\App |
50
|
|
|
*/ |
51
|
|
|
class WebAppAdapter extends AppAdapter implements AppInterface |
52
|
|
|
{ |
53
|
|
|
|
54
|
|
|
use WebAppTrait; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return int|null |
58
|
|
|
* @throws BaseException |
59
|
|
|
* @throws ConfigException |
60
|
|
|
* @throws ControllerException |
61
|
|
|
* @throws CryptorException |
62
|
|
|
* @throws CsrfException |
63
|
|
|
* @throws DatabaseException |
64
|
|
|
* @throws DebugBarException |
65
|
|
|
* @throws DiException |
66
|
|
|
* @throws EnvException |
67
|
|
|
* @throws LangException |
68
|
|
|
* @throws LoaderError |
69
|
|
|
* @throws LoggerException |
70
|
|
|
* @throws MiddlewareException |
71
|
|
|
* @throws ModuleLoaderException |
72
|
|
|
* @throws ReflectionException |
73
|
|
|
* @throws RouteException |
74
|
|
|
* @throws RuntimeError |
75
|
|
|
* @throws SessionException |
76
|
|
|
* @throws SyntaxError |
77
|
|
|
* @throws ViewException |
78
|
|
|
*/ |
79
|
|
|
public function start(): ?int |
80
|
|
|
{ |
81
|
|
|
$request = Di::get(Request::class); |
82
|
|
|
$response = Di::get(Response::class); |
83
|
|
|
|
84
|
|
|
try { |
85
|
|
|
$this->loadEnvironment(); |
86
|
|
|
$this->loadConfig(); |
87
|
|
|
|
88
|
|
|
$this->initializeRequestResponse($request, $response); |
89
|
|
|
|
90
|
|
|
$this->loadLanguage(); |
91
|
|
|
|
92
|
|
|
if ($request->isMethod('OPTIONS')) { |
93
|
|
|
stop(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$this->setupErrorHandler(); |
97
|
|
|
$this->initializeDebugger(); |
98
|
|
|
$this->loadModules(); |
99
|
|
|
$this->setupViewCache(); |
100
|
|
|
|
101
|
|
|
$this->initializeRouter($request); |
102
|
|
|
|
103
|
|
|
info(HookManager::getInstance()->getRegistered(), ['tab' => Debugger::HOOKS]); |
104
|
|
|
|
105
|
|
|
MvcManager::handle($request, $response); |
106
|
|
|
|
107
|
|
|
stop(); |
108
|
|
|
} catch (StopExecutionException $exception) { |
109
|
|
|
$this->handleCors($response); |
110
|
|
|
$response->send(); |
111
|
|
|
|
112
|
|
|
return $exception->getCode(); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
} |