-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Milestone
Description
Description
Note: this task requires task #1 to be done.
Web::class has a bad design. It just has a bunch of static methods for requests and routes.
It should be splitted respecting the following:
-
Http\Request::classwill receive http request data;- ex:
new Request($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER).
- ex:
-
Http\RouteCollection::classwill store all routes;- ex:
new RouteCollection(array).
- ex:
-
Http\Route::classwill be created by RouteCollection object;- ex:
new Route(key, array); - ex:
RouteCollection::getByRequest(Request).
- ex:
Utility classes:
-
StaticHandler::classacts as a static handler for alll objects. -
Http\URL::classshould contains only utils static methods for manipulating urls.
config/forks/ must be renamed into config/routes/.
Note: this task is part of the milestone named Improve Request methods usage.
Example
For framework usage:
use Arshwell\Monolith\Http\Request;
use Arshwell\Monolith\Http\RouteCollection;
use Arshwell\Monolith\Http\Route;
use Arshwell\Monolith\StaticHandler;
$request = new Request($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER);
$routeCollection = new RouteCollection(array); // array of all routes
$route = $routeCollection->getByRequest($request); // returns Route|null
// static handler for global usage
StaticHandler::setRequest($request);
StaticHandler::setRouteCollection($routeCollection);
StaticHandler::setRoute($route);For user usage:
use Arshwell\Monolith\Http\Request;
use Arshwell\Monolith\Http\Route;
$request = new Request(); // gets minimal default values
$request->setUrlPath("path/to/page");
$request->setMethod("POST");
$key = StaticHandler::getRouteCollection()->getKeyByRequest($request);
$route = StaticHandler::getRouteCollection()->getByRequest($request); // returns Route|null
$route->getUrl();
$route->generateRequest(); // returns RequestFor html usage:
<a href="<?= Arshwell\Monolith\StaticHandler::getRoute()->getUrl() ?>">
this page
</a>
<a href="<?= Arshwell\Monolith\StaticHandler::getRouteCollection()->getByKey('key')->getUrl() ?>">
page nr 2
</a>
<a href="<?= Arshwell\Monolith\StaticHandler::getRouteCollection('key')->getUrl() ?>">
page nr 2
</a>Arshwell Version
0.*
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels