PHP code example of bonfim / router

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

    

bonfim / router example snippets





use Bonfim\Router\Route;

Route::get('/', function () {
    echo 'Hello World!';
});

Route::get('/', function () {
    echo 'Hello World!';
});

function hello()
{
    echo 'Hello World!';
}

Route::get('/', 'hello');

class Greeting
{
    public static function hello()
    {
        echo 'Hello World!';    
    }
}

Route::get('/', ['Greeting', 'hello']);

class Greeting
{
    private $name;

    public function __construct()
    {
        $this->name = 'Edson Onildo';
    }

    public function hello()
    {
        echo 'Hello, {$this->name}!';    
    }
}

$greeting = new Greeting();

Route::get('/', [$greeting, 'hello']);

Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);

Route::match(['get', 'post'], '/', function() {
    //
});

Route::any('/', function() {
    //
});

Route::get('/@name/@id', function($name, $id) {
    echo "hello, $name ($id)!";
});

Route::get('/@name/@id:[0-9]{3}', function($name, $id) {
    // This will match /bob/123
    // But will not match /bob/12345
});