Skip to content

Commit 21b650e

Browse files
authored
chore: Merge pull request #273 from WebFiori/dev
Dev
2 parents e6a10a8 + 7d230c9 commit 21b650e

45 files changed

Lines changed: 265 additions & 2078 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

App/Apis/RoutingTestClass.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<?php
22
namespace App\Apis;
33

4-
use WebFiori\Http\Response;
4+
use WebFiori\Framework\App;
55

66
class RoutingTestClass {
77
public function __construct(?string $param = null, ?string $second = null) {
8-
Response::write("I'm inside the class.");
8+
App::getResponse()->write("I'm inside the class.");
99
}
1010
public function doSomething() {
11-
Response::clear();
12-
Response::write("I'm doing something.");
11+
App::getResponse()->clear();
12+
App::getResponse()->write("I'm doing something.");
1313
}
1414
public function doSomethingExtra(?string $p1 = null, ?string $p2 = null) {
15-
Response::clear();
16-
Response::write("I'm doing something.");
15+
App::getResponse()->clear();
16+
App::getResponse()->write("I'm doing something.");
1717
}
1818
}

WebFiori/Framework/App.php

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

WebFiori/Framework/Cli/Commands/ListRoutesCommand.php

Lines changed: 0 additions & 56 deletions
This file was deleted.

WebFiori/Framework/Cli/Commands/ListThemesCommand.php

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)