2017 © Pedro Peláez
 

library rootr

Routing URLs like a boss.

image

eddmann/rootr

Routing URLs like a boss.

  • Monday, June 2, 2014
  • by eddmann
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

rootr

Routing URLs like a boss., (*1)

Build Status Coverage Status Scrutinizer Code Quality, (*2)

Install

Get composer:, (*3)

wget http://getcomposer.org/composer.phar

Then add this to a composer.json in your project's root:, (*4)

{
    "require": {
        "eddmann/rootr": "*"
    }
}

Now install:, (*5)

php composer.phar install

Closure Example

<?php

$router = new Rootr\Router;

$router->get('/', function () {
   return '/';
});

$router->get('/products', function () {
    return '/products';
});

$router->get('/products/{id:\d+}', function ($id) {
   return "/products/$id";
});

$router->get('/products/show/{id:\d+}/{?name}', function ($id, $name = 'na') {
    return "/products/show/$id/$name";
});

$router->get('/product.json', function () {
    $product = json_encode([ 'name' => 'Cheese', 'value' => 12.55 ]);

    return (new Rootr\Response(200, $product))->asJson();
});

$dispatcher = new Rootr\Dispatcher($router);

$response = $dispatcher->dispatch('GET', '/products/4');

$response->render(); // /products/4

Controller Example

<?php

$router = new Rootr\Router;

class ProductController extends Rootr\Controller
{
    public function indexAction()
    {
        return '/products';
    }

    /**
     * @method GET
     * @route /{id:\d+}
     */
    public function displayByIdAction($id)
    {
        return "/products/$id";
    }

    public function showAction($id, $name = 'na')
    {
        return "/products/show/$id/$name";
    }
}

$router->get('/', function () {
    return '/';
});

$router->mountController('/products', 'ProductController');

$dispatcher = new Rootr\Dispatcher($router);

$response = $dispatcher->dispatch('GET', '/products/show/2/cheese');

$response->render(); // /products/show/2/cheese

Examples

You can run the examples using PHP's built-in web server by running the following:, (*6)

./examples.sh

Influenced By

The Versions

02/06 2014

dev-master

9999999-dev

Routing URLs like a boss.

  Sources   Download

The Requires

  • php >=5.4.0
  • jeremeamia/superclosure dev-multiple-parsers

 

The Development Requires