Repository navigation
Home
pipes is a micro-framework for PHP 5.3, inspired by Sinatra. An example:
require 'pipes.php';
pipes\get('/hi', function() {
return 'Hello, world!';
});
pipes\run();The first parameter to pipes\get() is the path that the route should handle, and the second is the function to call when the route is matched.
The string returned by the function echoed as the response. You can also just echo directly, if desired -- the output is captured and appended to the response.
pipes\get() matches the GET HTTP method. You can also use post(), put(), and delete(). To specify a route that matches any HTTP method, use any(). The first matching route is used, in the order that the routes were defined.
The first parameter to your route callback is a $params hash. Named captures are copied into this object:
pipes\get('/hi/:name', function($params) {
return "Hello, {$params->name}!";
});Regular expression patterns can also be used in the route. An array of any unnamed captures will be copied into $params->captures:
pipes\get('/archive/([0-9]{4})/([0-9]{2})/([0-9]{2})', function($params) {
list($year, $month, $day) = $params->captures;
return "Archive for {$year}-{$month}-{$day}";
});Use pipes\render() to include a PHP file as a view, and capture the output:
pipes\get('/', function() {
return pipes\render('index.php');
});Rendered templates have four variables ($params, $response, $request, and $route) available to them by default. You can pass extra locals via the second parameter to render():
return pipes\render('index.php', array(
'foo' => 'bar' // $foo will be available to the view
));The render() method looks for the files in a views folder next to the pipes.php file by default, but you can override that by passing an option to pipes\run():
pipes\run(array('views' => '/my/custom/views/path'));