@MárriosDev
composer require marrios/router
use Marrios\Router\HttpRouter;
$router = new HttpRouter();
// Set route
$router->get("/helloworld", [function(){ echo "Hello World!";}])->run();
$router->notFound();When accessing the /helloworld route
Hello World!use App\Controllers\TesteController;
use Marrios\Router\HttpRouter;
$router = new HttpRouter();
// Set route
$router->post("/helloworld", [TesteController::class, "helloWorld"])->run();
$router->notFound();When accessing the /helloworld route
Hello World!* Note: When defining a dynamic route, you must add a parameter to the callback function or in the controller method
use Marrios\Router\HttpRouter;
$router = new HttpRouter();
// Set route
$router->post("/blog/{category}/{id_post}", [ function($param){ echo $param->category;}])->run();
$router->notFound();When accessing the /blog/video/1323 route
videouse Marrios\Router\HttpRouter;
$router = new HttpRouter();
// Instantiating the route object
$router = new Router();
// Set route
$router->get("/blog/{category}/{id_post}", [TesteController::class, "helloWorld"])->run();
$router->notFound();class TesteController
{
public function helloWorld($param)
{
echo $param->id_post;
}
}When accessing the /blog/video/1323 route
1323class Middleware
{
public function handle() {
return true;
}
}use Marrios\Router\HttpRouter;
use Middleware;
$router = new HttpRouter();
// Set route
$router->middleware([Middleware::class])
->get("/ok", [function () {echo "OK";}])
->run();When accessing the /ok route
OK