Docs

Router Class


Definition

Namespace: DafCore
Phar: DafCore.phar

for the following
$path is a spesific path
example:
"/Users"
"/Accounts/Login"

the $path variable can hold parameters
example:
"/Users/{id}"

the array of ...$callbacks for the minimal api
can containe middlewares and the last element is the endpoit.

Constructor

new Router(ServicesProvidor $sp, ApplicationContext $context, ViewManager $viewManager)
  • ServicesProvidor $sp - DI Container
  • ApplicationContext $context - Hold the request, response, endpoint and endpoint metadata.
  • ViewManager $viewManager - Render logic

Methods

function Resolve() : void
Trigger the pipline (start process the requst).
Only the internal App logic need to use it. [ $app->Run() ]
function SetBasePath(string $path) : void
Set the prefix for all the next routes.
function AddMiddleware(callable $callback) : void
Add the callback as a global middleware.
global middleware will be executed before the route middleware.
function AddController(string $controllerClass) : void
Add all the routes in a controll and attributes.
routes difined with [ HttpGet, HttpPost, HttpPut, HttpDelete ]
attributes difined as middlewares.
function Get(string $path, ...$callbacks) : void
Add a GET route to the pipline.
function Post(string $path, ...$callbacks) : void
Add a POST route to the pipline.
function Put(string $path, ...$callbacks) : void
Add a GET route to the pipline.
function Delete(string $path, ...$callbacks) : void
Add a DELETE route to the pipline.