PHP code example of vitodtagliente / pure-routing

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

    

vitodtagliente / pure-routing example snippets


    $router = new Pure/Routing/Router();
    
    
    $router->get('/foo', $callback);    // GET method
    $router->post('/foo', $callback);   // POST method
    $router->put('/foo', $callback);    // PUT method
    $router->delete('/foo', $callback); // DELETE method
    

        $router->get('/foo', function(){ ... });
        

        function foo(){ ... }
        $router->get('/foo', 'foo');
        

        $router->get('/foo', 'FooController@action');
        
        
        $router->get('/foo', 'App\Controllers\FooController@action');
        
        $router->get('/foo', 'App\Controllers\FooController::class . '@action');
        

        $router->namespace('app', 'App\Controllers');
        $router->get('/foo', 'app::FooController@action');
        

        $routes->get('/user/$username', function($username){} );
        

        $router->get('/user/$id:i', function($id){ ... } );
        

        $router->rule('k', 'regular_expression');
        

use Pure\Routing\Middleware;

class AuthMiddleware extends Middleware
{
    public function handle(){
        // returns true if the user is logged in
        return MyAuthNamespace\Auth::check();
    }
}

$router->get('/dashboard', $callback)->middleware(AuthMiddleware::class);