@@ -100,6 +100,18 @@ class App {
100100 * @since 1.0
101101 */
102102 private static $ LC ;
103+ /**
104+ * Current request instance.
105+ *
106+ * @var Request
107+ */
108+ private static $ Request ;
109+ /**
110+ * Current response instance.
111+ *
112+ * @var Response
113+ */
114+ private static $ Response ;
103115
104116 /**
105117 * The entry point for initiating the system.
@@ -124,6 +136,10 @@ private function __construct() {
124136
125137 //Initialize CLI
126138 self ::getRunner ();
139+
140+ //Initialize Request and Response
141+ self ::$ Request = Request::createFromGlobals ();
142+ self ::$ Response = new Response ();
127143
128144 $ this ->initThemesPath ();
129145
@@ -137,7 +153,7 @@ private function __construct() {
137153 $ this ->initMiddleware ();
138154 $ this ->initRoutes ();
139155 $ this ->initScheduler ();
140- Response:: beforeSend (function ()
156+ self :: getResponse ()-> beforeSend (function ()
141157 {
142158 register_shutdown_function (function ()
143159 {
@@ -146,7 +162,7 @@ private function __construct() {
146162 $ mdArr = $ uriObj ->getMiddleware ();
147163
148164 for ($ x = count ($ mdArr ) - 1 ; $ x > 0 ; $ x --) {
149- $ mdArr [$ x ]->afterSend (Request:: get (), Response:: get ());
165+ $ mdArr [$ x ]->afterSend (self :: getRequest (), self :: getResponse ());
150166 }
151167 }
152168 });
@@ -157,7 +173,7 @@ private function __construct() {
157173 $ mdArr = $ uriObj ->getMiddleware ();
158174
159175 for ($ x = count ($ mdArr ) - 1 ; $ x > 0 ; $ x --) {
160- $ mdArr [$ x ]->after (Request:: get (), Response:: get ());
176+ $ mdArr [$ x ]->after (self :: getRequest (), self :: getResponse ());
161177 }
162178 }
163179 });
@@ -305,8 +321,8 @@ public static function handle() {
305321 App::getRunner ()->start ();
306322 } else {
307323 //route user request.
308- Router::route (Request:: getRequestedURI ());
309- Response:: send ();
324+ Router::route (self :: getRequest ()-> getRequestedURI ());
325+ self :: getResponse ()-> send ();
310326 }
311327 }
312328 }
@@ -423,15 +439,15 @@ public static function getRunner() : Runner {
423439 $ commands = [
424440 '\\WebFiori \\Framework \\Cli \\Commands \\WHelpCommand ' ,
425441 '\\WebFiori \\Framework \\Cli \\Commands \\VersionCommand ' ,
426- '\\ WebFiori \\ Framework \\ Cli \\ Commands \\ SettingsCommand ' ,
442+
427443 '\\WebFiori \\Framework \\Cli \\Commands \\SchedulerCommand ' ,
428444 '\\WebFiori \\Framework \\Cli \\Commands \\CreateCommand ' ,
429445 '\\WebFiori \\Framework \\Cli \\Commands \\AddCommand ' ,
430- '\\ WebFiori \\ Framework \\ Cli \\ Commands \\ ListRoutesCommand ' ,
431- '\\ WebFiori \\ Framework \\ Cli \\ Commands \\ ListThemesCommand ' ,
432- '\\ WebFiori \\ Framework \\ Cli \\ Commands \\ RunSQLQueryCommand ' ,
433- '\\ WebFiori \\ Framework \\ Cli \\ Commands \\ UpdateSettingsCommand ' ,
434- '\\ WebFiori \\ Framework \\ Cli \\ Commands \\ UpdateTableCommand ' ,
446+
447+
448+
449+
450+
435451 '\\WebFiori \\Framework \\Cli \\Commands \\RunMigrationsCommand ' ,
436452 ];
437453
@@ -724,7 +740,7 @@ private function initRoutes() {
724740 * @throws FileException
725741 */
726742 private function initScheduler () {
727- $ uriObj = new RouterUri (Request:: getRequestedURI ( ), '' );
743+ $ uriObj = new RouterUri (self :: getRequest ()-> getUri ()-> getUri ( true , true ), '' );
728744 $ pathArr = $ uriObj ->getPathArray ();
729745
730746 if (!class_exists (APP_DIR .'\Init\InitTasks ' )) {
@@ -764,4 +780,20 @@ private function setHandlers() {
764780 // Handler::registerHandler(new HTTPErrHandler());
765781 // Handler::unregisterHandler(Handler::getHandler('Default'));
766782 }
783+ /**
784+ * Returns the current request instance.
785+ *
786+ * @return Request
787+ */
788+ public static function getRequest () : Request {
789+ return self ::$ Request ;
790+ }
791+ /**
792+ * Returns the current response instance.
793+ *
794+ * @return Response
795+ */
796+ public static function getResponse () : Response {
797+ return self ::$ Response ;
798+ }
767799}
0 commit comments