PHP code example of reinink / roundabout

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

    

reinink / roundabout example snippets




use \Reinink\Roundabout\Router;
use \Symfony\Component\HttpFoundation\Request;

// Include Composer autoloader



// Home page
$router->get(
    '/',
    function () {
        // do something
    }
);

// Contact page
$router->get(
    '/contact',
    function () {
        // do something
    }
);

// Process form post
$router->post(
    '/form-submit',
    function () {
        // do something
    }
);

// Secure (HTTPS) page
$router->getSecure(
    '/login',
    function () {
        // do something
    }
);

// PUT request
$router->put(
    '/resource',
    function () {
        // do something
    }
);

// DELETE request
$router->delete(
    '/resource',
    function () {
        // do something
    }
);



// User profile
$router->get(
    '/user/([0-9]+)',
    function ($userId) {
        // do something with $userId
    }
);

// Output image
$router->get(
    '/photo/(xlarge|large|medium|small|xsmall)/([0-9]+)',
    function ($imageSize, $imageId) {
        // do something with $imageSize and $imageId
    }
);



// Home page
$router->get('/', 'Controller::index');

// Contact page
$router->get('/contact', 'Controller::contact');

// Process form post
$router->post('/form-submit', 'Controller::process_form');

// Secure (HTTPS) page
$router->getSecure('/login', 'Controller::login');



$router->import(
    [
        [
            'path' => '/',
            'method' => 'GET',
            'secure' => false,
            'callback' => 'Controller::index'
        ],
        [
            'path' => '/contact',
            'method' => 'GET',
            'secure' => false,
            'callback' => 'Controller::contact'
        ],
        [
            'path' => '/form-submit',
            'method' => 'POST',
            'secure' => false,
            'callback' => 'Controller::process_form'
        ],
        [
            'path' => '/login',
            'method' => 'GET',
            'secure' => true,
            'callback' => 'Controller::login'
        ]
    ]
);



// Your IoC container
$ioc = new Container;

// Create router
$router = new Router(
    $request,
    function ($class, $method, $parameters) use ($ioc) {

        $controller = $ioc->make($class);

        return call_user_func_array(array($controller, $method), $parameters);
    }
);