1. Go to this page and download the library: Download corviz/router 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/ */
corviz / router example snippets
use Corviz\Router\Facade\RouterFacade as Router;
/*
* Application routes
*/
Router::get('/', function() {
return 'Hello world!';
});
Route::get('/user/(\d+)', function(int $id){
return "Show information for user $id";
});
use Corviz\Router\Middleware;
class AcceptJsonMiddleware extends Middleware
{
public function handle(Closure $next): mixed
{
//Interrupts in case wrong content-type was sent
if (!$_SERVER['CONTENT_TYPE'] != 'application/json') {
return 'Invalid content type';
}
return $next(); //Proceed with the request
}
}
use Corviz\Router\Facade\RouterFacade as Router;
Router::any( /*...*/ )
->middleware(AcceptJsonMiddleware::class);
use Corviz\Router\Facade\RouterFacade as Router;
Router::any( /*...*/ )
->middleware([Middleware1::class, Middleware2::class]);