PHP code example of allmarkedup / super-sharp-router

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

    

allmarkedup / super-sharp-router example snippets



$router = new Amu\SuperSharp\Router();

$router->get('/hello', function(){
    return 'Hello world!';
});

echo $router->match('/hello'); // Prints: Hello World!


use Amu\SuperSharp\Http\Response;
use Symfony\Component\Routing\Exception\RouteNotFoundException;

$router = new Amu\SuperSharp\Router();
$router->get('/', function(){
    return new Response('This is the homepage');
});

try {
    $response = $router->match(); // matches against the current request
} catch (ResourceNotFoundException $e) {
    $response = new Response('No matching route found', 404);
}

$response->send();



$router->post('/articles', function(){
    return 'Article added!';
});

$router->get('/articles/{slug}', function($slug){
    return Example::find($slug);
});

$router->get('/users/{id}', function($id){
    return Example::find($id);
})
->assert('id', '\d') // $id route parameter must be a digit
->