Download the PHP package c9s/roller without Composer
On this page you can find all versions of the php package c9s/roller. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package roller
Short Description High performance PHP router
License BSD-3-Clause
Homepage http://github.com/c9s/php-Roller
Informations about the package roller
Roller
PHP Roller is a simple/fast router for PHP.
Roller compiles your routes into a simple array to store routes, therefore it's fast.
Beyond that, Roller provides an extension to improve more performance for you.
FEATURES
- Highly customizable
- Flexible
- Simple DSL (Sinatra-like syntax)
- APC cache support.
- File cache support.
- Built-in RESTful route generator, resource handler.
- Customizable RESTful route generator, resource handler.
- Simple, Useful route path syntax. (rails-style)
- High performance (through PHP extension, can dispatch 1607% faster than pure php version)
- High unit test coverage, coverage > 88%.
- Ready for Frameworks.
- Annotation reader support.
Benchmark
ROUTE CONSOLE DUMPER
INSTALL
Install from Composer:
Install through PEAR:
pear channel-discover pear.corneltek.com
pear install corneltek/Roller
Or clone this repository:
pear install -f package.xml
Use thie library as a git submodule: clone this repository, pick up a PSR-0 classloader, and add src/
to class
path.
To use console dumper, you need ezc/ConsoleTools, please use PEAR installer to install:
pear channel-discover components.ez.no
pear install -a ezc/ConsoleTools
SYNOPSIS
Roller router provides a simple DSL for you to declare sinatra-like routes:
More usage:
Initialize a router:
Add a new route with simple callback
Add a new route with class callback
Add a new route with class/action callback string:
To add a new route with requirement:
To add a new route with requirement and closure:
Or by any
:
An alias for GET method:
An alias for POST method:
META ATTRIBUTE
Roller currently supports: method
, default
, requirement
, post
, get
attributes.
To add a new route with requirement and default value:
To add a new route with request method (like POST method):
RouteSet
RouteSet is a route collection class, you can mount a route set to another route set.
To use RouteSet is very easy:
Mount paths
To mount route set:
Dispatch
To dispatch path:
To evalulate response content:
Customize Route Class
Use Annotation Reader for controllers
Cache
To enable apc cache:
To enable file cache:
RESTful interface
Roller Router has a built-in RESTful route generator, it's pretty easy to define a bunch of RESTful routes, Roller Router also provides a simple RESTful route generator, which is pretty easy to customize your own RESTful routes.
First, initalize a RESTful plugin object:
Add RESTful plugin to your router manager:
To support RESTful, you have two solutions:
ResourceHandler
: If you need to define differnt logic for each resource, you can useResourceHandler
, you can separate different resource logic into different handler class.GenericHandler
: If your resources use the same logic and the same permission controll, you can useGenericHandler
for every resources.
To use ResourceHandler, register your resource id to router with your resource handler class name, each resource id is mapping to an resource handler:
Define your resource handler, here is a simple blog example that defines how RESTful CRUD works:
For the status code, see the list below:
- codeOk (200)
- codeCreated (201)
- codeAccepted (202)
- codeNoContent (204)
- codeBadRequest (400)
- codeForbidden (403)
- codeNotFound (404)
Before you dispatch URLs, router object calls the expand
method of ResourceHandler
class, which
generates RESTful routes into the routeset of router object. And below is the generated URLs:
GET /restful/blog - get blog list
GET /restful/blog/:id - get one blog record
POST /restful/blog - create one blog record
PUT /restful/blog/:id - update one blog record
DELETE /restful/blog/:id - delete one blog record
You can override the expand
method to define your own style RESTful URLs.
Now you should be able to dispatch RESTful urls:
Customize Resource Handler
Here is how RESTful route generator works:
To define your own RESTful Resource Handler (Generator), you can simply inherit class from
Roller\Plugin\RESTful\ResourceHandler
:
.htaccess File for Apache
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ your_router.php/$1 [NC,L]
Install Extension
$ cd extension
$ phpize
$ ./configure
$ make && make install
Add config to your php.ini:
Hacking
Run Composer Install:
composer install --dev
Install ConsoleTools:
pear channel-discover components.ez.no
pear install -a ezc/ConsoleTools
Get Onion and install it:
$ curl -s http://install.onionphp.org/ | bash
Run onion to install depedencies:
$ onion install
Now you should be able to run phpunit =)
$ phpunit tests
TODO
- Expandable Controller (route table inside)
- Auto Expandable Controller (expand routes automatically, based on method name)