Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Request routing using @route annotations
branch: master

This branch is even with chriso:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
docs/html
lib
tests
Doxyfile
LICENSE
README.md
Request.phar
phpunit.xml

README.md

Usage

See ./docs for the API.

<?php require 'Request.phar';

/**
 * @route /
 */
function showIndex($context) {
    $context->render('index.phtml');
}

/**
 * @route /users
 */
class Users {

    /**
     * @route /:id
     */
    public function showUser($context) {
        $user = $context->id;
        //...
    }

    /**
     * @route
     */
    public function showAllUsers($context) {
        //
    }

    /**
     * @route
     * @method post
     */
    public function createUser($context) {
        //
    }
}

dispatch();

Default dispatch

This is what goes on under the hood - customise if you like.

<?php

function dispatch(/* $args */) {

    $args = func_get_args();
    array_unshift($args, new Request\Context);

    //See if there's some cached routes
    $routes = apc_fetch('routes');
    if (false === $routes) {
        require 'phar://Request.phar/Request/Router.php';
        $router = new Request\Router;
        $routes = $router->getRoutes();
        apc_store('routes', $routes);
    }

    //Dispatch to all functions/methods with a @route annotation
    $dispatcher = new Request\Dispatcher;
    $dispatcher->setRoutes($routes);
    $dispatcher->dispatch($args);

}

Tests & Documentation

To run tests and generate documentation using Doxygen, run

phpunit tests && doxygen
Something went wrong with that request. Please try again.