Skip to content

Routing

AngelNovo edited this page Aug 10, 2024 · 3 revisions

Route methods

As of version 0.0.1.alpha1, there's only support for 'GET' and 'POST' handling

Route creation

Raw routes

A raw route can be defined as a route without any under the hood middleware/effect. This types of routes should be created in /routes/raw.php

Static routes

A static route can be defined as a route with no dynamic parameters

// Including the route handler
use lib\components\Route;

/*
 The class instance must follow the following notation -> ClassName::class
*/
Route::Get(string $route, $class_instance, string $functionName);
// Same with POST
Route::Post(...)

Dynamic routes

The declaration of a dynamic route is identical to a static route, it's the route string that changes

Untyped parameters

/*
 Everything inside of '{' and '}' will be treated as a dynamic parameter and 
 will be obtained as a string
*/
'/user/{id}'
'/user/{id:}'

Typed parameters

/*
 In this case, id will be converted to an integer and the slug to a string
*/
'/user/{id:int}/article/{slug:string}'

Valid route types

  • int
    • If the route contains an invalid integer, 0 will be passed to the controller
  • string
    • this type is not necessary, as every untyped param is considered a string

Handling Not found route

The Not found route declaration is identical to regular routes. If the route string contains *.* however, it is considered a not found route regardless of the method.

Clone this wiki locally