|
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
|
|
|
if (!defined('DS')) define('DS', DIRECTORY_SEPARATOR); |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Class WebAppAdapter |
|
51
|
|
|
* @package Quantum\App |
|
52
|
|
|
*/ |
|
53
|
|
|
class WebAppAdapter extends AppAdapter implements AppInterface |
|
54
|
|
|
{ |
|
55
|
|
|
|
|
56
|
|
|
use WebAppTrait; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return int|null |
|
60
|
|
|
* @throws BaseException |
|
61
|
|
|
* @throws ConfigException |
|
62
|
|
|
* @throws ControllerException |
|
63
|
|
|
* @throws CryptorException |
|
64
|
|
|
* @throws CsrfException |
|
65
|
|
|
* @throws DatabaseException |
|
66
|
|
|
* @throws DebugBarException |
|
67
|
|
|
* @throws DiException |
|
68
|
|
|
* @throws EnvException |
|
69
|
|
|
* @throws LangException |
|
70
|
|
|
* @throws LoaderError |
|
71
|
|
|
* @throws LoggerException |
|
72
|
|
|
* @throws MiddlewareException |
|
73
|
|
|
* @throws ModuleLoaderException |
|
74
|
|
|
* @throws ReflectionException |
|
75
|
|
|
* @throws RouteException |
|
76
|
|
|
* @throws RuntimeError |
|
77
|
|
|
* @throws SessionException |
|
78
|
|
|
* @throws SyntaxError |
|
79
|
|
|
* @throws ViewException |
|
80
|
|
|
*/ |
|
81
|
|
|
public function start(): ?int |
|
82
|
|
|
{ |
|
83
|
|
|
$request = Di::get(Request::class); |
|
84
|
|
|
$response = Di::get(Response::class); |
|
85
|
|
|
|
|
86
|
|
|
try { |
|
87
|
|
|
$this->loadEnvironment(); |
|
88
|
|
|
$this->loadConfig(); |
|
89
|
|
|
|
|
90
|
|
|
$this->initializeRequestResponse($request, $response); |
|
91
|
|
|
|
|
92
|
|
|
$this->loadLanguage(); |
|
93
|
|
|
|
|
94
|
|
|
if ($request->isMethod('OPTIONS')) { |
|
95
|
|
|
stop(); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
$this->setupErrorHandler(); |
|
99
|
|
|
$this->initializeDebugger(); |
|
100
|
|
|
$this->loadModules(); |
|
101
|
|
|
$this->setupViewCache(); |
|
102
|
|
|
|
|
103
|
|
|
$this->initializeRouter($request); |
|
104
|
|
|
|
|
105
|
|
|
info(HookManager::getInstance()->getRegistered(), ['tab' => Debugger::HOOKS]); |
|
106
|
|
|
|
|
107
|
|
|
MvcManager::handle($request, $response); |
|
108
|
|
|
|
|
109
|
|
|
stop(); |
|
110
|
|
|
} catch (StopExecutionException $exception) { |
|
111
|
|
|
self::handleCors($response); |
|
|
|
|
|
|
112
|
|
|
$response->send(); |
|
113
|
|
|
|
|
114
|
|
|
return $exception->getCode(); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
} |