PHP code example of silawrenc / traffic

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

    

silawrenc / traffic example snippets


$router = new Traffic;
$router->add('GET', '/foo/bar', function() {
    // do stuff
});

$router->get('/foo/bar', function () {
    // show stuff
});

$router->post('/foo/bar', function () {
    // save stuff
});

$router->add('(GET|POST)', '/user/([a-z]+)', function ($method, $username) {
    // as you were
});

$router->add('*', '/foo/{bar}/{baz:[A-Z]+}', function ($method, $bar, $baz) {
    // important stuff
});

$router->add('(?:PATCH|PUT)', '/foo/{bar}', function ($bar) {
    // using a non-capturing regex group for the method
});

// return false from auth(), and render won't be invoked
$router->get('hello/world', auth(), render('landing'));

$router->get('hello/world', routeSpecificMiddleWare(), render('landing'), otherMiddleWare());

$router->route($method, $path);