PHP code example of franco2911 / avrestirouter

1. Go to this page and download the library: Download franco2911/avrestirouter 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/ */

    

franco2911 / avrestirouter example snippets




use AvrestiRouter\Routing\AvrestiRouter;
use AvrestiRouter\Routing\Facade\Route;

$router = new AvrestiRouter();
Route::setRouter($router);

Route::get('/contact', function () {
    return new \GuzzleHttp\Psr7\Response(200, [], "<h1>Contact page</h1>");
});

Route::get('/about', function () {
    return new \GuzzleHttp\Psr7\Response(200, [], "<h1>About page</h1>");
})->name('about');

Route::group(['group' => 'auth'], function () {
    Route::get('/dashboard', function () {
        return new \GuzzleHttp\Psr7\Response(200, [], "Dashboard");
    })->name('dashboard');

    Route::get('/settings', [\TestController::class, 'create'])->name('settings');
    
    Route::get('/profile/{id}', function ($id) {
        return new \GuzzleHttp\Psr7\Response(200, [], "<h1>Profile ID: $id</h1>");
    })->name('profile.show');
});

use GuzzleHttp\Psr7\ServerRequest;

$request = ServerRequest::fromGlobals();
$response = Route::resolve($request);

// Output the response body
echo $response->getBody();

echo Route::generateUrl('profile.show', ['id' => 1259]); // Output: /profile/1259