2017 © Pedro Peláez
 

library roundabout

RESTful router based on the Symfony2 HttpFoundation.

image

reinink/roundabout

RESTful router based on the Symfony2 HttpFoundation.

  • Tuesday, February 25, 2014
  • by reinink
  • Repository
  • 1 Watchers
  • 4 Stars
  • 104 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Roundabout

RESTful router based on the Symfony2 HttpFoundation., (*1)

Highlights

  • Extremely simple API
  • RESTful support: GET, POST, PUT & DELETE
  • Based on the Symfony2 HttpFoundation (it just works)
  • Supports closures, functions and controller (class) callbacks
  • Ability to bulk imports routes using arrays
  • Custom controller instantiation (for IoC container integration)

Getting started

Installation

Roundabout is available via Composer:, (*2)

{
    "require": {
        "reinink/roundabout": "1.*"
    }
}

Setup

<?php

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

// Include Composer autoloader
require 'vendor/autoload.php';

// Create request object
$request = Request::createFromGlobals();

// Create router
$router = new Router($request);

Basic routes

<?php

// 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
    }
);

More complicated routes

<?php

// 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
    }
);

Working with controller classes

<?php

// 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');

Bulk route definitions

<?php

$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'
        ]
    ]
);

Custom controller instantiation

By default Roundabout instantiates controller classes automatically, but this beahavior can be overridden using the $instantiation_callback paramater. This can be helpful in situations where you want to use an inversion of control container., (*3)

<?php

// 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);
    }
);

The Versions

25/02 2014

dev-master

9999999-dev

RESTful router based on the Symfony2 HttpFoundation.

  Sources   Download

MIT

The Requires

 

25/02 2014

1.0.4

1.0.4.0

RESTful router based on the Symfony2 HttpFoundation.

  Sources   Download

MIT

The Requires

 

19/09 2013

1.0.3

1.0.3.0

RESTful router based on the Symfony2 HttpFoundation.

  Sources   Download

MIT

The Requires

 

16/09 2013

1.0.2

1.0.2.0

RESTful router based on the Symfony2 HttpFoundation.

  Sources   Download

MIT

The Requires

 

19/07 2013

1.0.1

1.0.1.0

RESTful router based on the Symfony2 HttpFoundation.

  Sources   Download

MIT

The Requires

 

11/07 2013

1.0.0

1.0.0.0

RESTful router based on the Symfony2 HttpFoundation.

  Sources   Download

MIT

The Requires