PHP code example of devsrealm / tonics-router-system
1. Go to this page and download the library: Download devsrealm/tonics-router-system library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
devsrealm / tonics-router-system example snippets
$onRequestProcess = new OnRequestProcess(
new RouteResolver(
new Container()
),
new Route(
new RouteTreeGenerator(
new RouteTreeGeneratorState(), new RouteNode()
)
)
);
$router = new Router(
$onRequestProcess,
$onRequestProcess->getRouteObject(),
new Response(
$onRequestProcess, new RequestInput()
)
);
$route = $router->getRoute();
$route->get('/', function() {
return 'Welcome To My Home Page';
});
class Authenticated implements TonicsRouterRequestInterceptorInterface
{
/**
* @inheritDoc
*/
public function handle(OnRequestProcess $request): void
{
if (UserData::isAuthenticated() === false){
# If this is for admin, then redirect to admin login
if (str_starts_with($request->getRequestURL(), '/admin')){
redirect(route('admin.login'));
}
# If this is for customer, then redirect to customer login
if (str_starts_with($request->getRequestURL(), '/customer')){
redirect(route('customer.login'));
}
# Else...
SimpleState::displayUnauthorizedErrorMessage();
}
}
}