Router Class
Definition
Namespace: DafCore
Phar: DafCore.phar
instance used to handle routes and middleware in an organized way.
for the following$path is a spesific pathexample:
"/Users""/Accounts/Login"the
$path variable can hold parametersexample:
"/Users/{id}"
the array of ...$callbacks for the minimal api
can containe middlewares and the last element is the endpoit.
Constructor
__construct(ServicesProvidor $sp, ApplicationContext $context, IViewManager $viewManager)
- ServicesProvidor $sp - DI Container
- ApplicationContext $context - Hold the request, response, endpoint and endpoint metadata.
- ViewManager $viewManager - Render logic
Methods
function Resolve(): string
Trigger the pipline (start process the requst).
Only the internal App logic need to use it. [ $app->Run() ]
function AddMiddleware(callable $callback): void
Add the callback as a global middleware.
global middleware will be executed before the route middleware.
function Get($path, ...$callback): void
Add a GET route to the pipline.
function Put($path, ...$callback): void
Add a PUT route to the pipline.
function Post($path, ...$callback): void
Add a POST route to the pipline.
function Delete($path, ...$callback): void
Add a DELETE route to the pipline.
function RegisterControllers(array $controllers): void
Register all the routes in a controll and attributes.
routes difined with [ HttpGet, HttpPost, HttpPut, HttpDelete ]
attributes difined as middlewares.
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 NeedsRecache(): bool
If router finds route from pending controllers its turn on the needsRecache flag sow we can update the cache file.
function LoadRoutesCache(string $cacheFile): bool
Load the routes from the cache file located in: vendor/storage/routes.cache.php.
function SaveRoutesCache(string $cacheFile): void
Save the routes in the cache file located in: vendor/storage/routes.cache.php.