PHP code example of kito92 / epicroute

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

    

kito92 / epicroute example snippets



= \EpicRoute\Route::getInstance();

$route->get('/', function(){
    echo 'response';
});

$route->dispatch();

$route->get('/...', function(){ /*...*/ });
$route->post('/...', function(){ /*...*/ });
$route->put('/...', function(){ /*...*/ });
$route->patch('/...', function(){ /*...*/ });
$route->delete('/...', function(){ /*...*/ });

$route->get('/users/:name', function($name){
    echo 'Welcome back ' . $name;
});

$route->get('/users/:id{[0-9]*}', function($id){
    echo 'user id ' . $id;
});

$route->get('/:slug+', function($paths){
    print_r($paths);
});

$route->get('/users/:id{[0-9]*}', function($id){ /*...*/ })
	  ->get('/users/:name', function($name){ /*...*/ })
	  ->dispatch();

class CustomMiddleware implements \EpicRoute\Middleware{
    /**
     * This method will be executed before the routing
     *
     * @return mixed
     */
    function before(){
        // TODO: Implement before() method.
    }

    /**
     * This method will be executed after the routing
     *
     * @return mixed
     */
    function after(){
        // TODO: Implement after() method.
    }
}

$route->get('/', function(){
    echo 'home';
}, ['middleware' => CustomMiddleware::class]);

$route->group(['middleware' => CustomMiddleware::class], function () use ($route){
    $route->get('/users/:id{[0-9]*}', function ($id){
        echo 'user id ' . $id;
    });
    $route->get('/users/:name', function ($name){
        echo 'Welcome back ' . $name;
    });
})->dispatch();