2017 © Pedro Peláez
 

library routing

image

assouan/routing

  • Tuesday, April 26, 2016
  • by Assouan
  • Repository
  • 1 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Routing - PHP Library

, (*1)

Router class for PSR-7 http, (*2)

Installation

Install using composer:, (*3)

$ composer require assouan/routing

Usage

$router = new Routing\Router();

$router->map($regex1, $callable1);
$router->map($regex2, $callable2);
$router->map($regex3, $callable3);

$response = $router->match($request);

echo $reponse;

Example

$router = new Routing\Router();

$router->map('/', 'sample_func');
$router->map('/special', 'SampleController::special')->setOption('method', 'post')->setOption('scheme', 'https');
$router->map('/hello/(?<name>\w+)', 'SampleController::hello');

$response = $router->match($request); // $request = Psr\Http\Message\ServerRequestInterface

echo $response;
function sample_func()
{
    return 'Hello world!';
}
class SampleController
{
    public function special()
    {
        return 'Page only in HTTPS POST';
    }

    public static function hello($request, $name)
    {
        // with function parameter
        $username = $name;
        // with request attribute
        $username = $request->getAttribute('name');

        return 'Hello '.$username;
    }
}

The Versions

26/04 2016

dev-master

9999999-dev

  Sources   Download

The Requires

 

The Development Requires