Exemple #1
0
    {
        $put = $this->parseInput();
        return $put;
        // return array( 'id' => $id );
    }
    public function delete($resource, $id)
    {
        $args = $this->parseInput();
        // print_r($args);
        return array('id' => $id);
    }
    public function find($resource)
    {
        return range(1, 10);
    }
}
$router = new Roller\Router(null, array('cache_id' => 'router_demo'));
$restful = new Roller\Plugin\RESTful(array('prefix' => '/='));
$restful->setGenericHandler('MyGenericHandler');
$router->addPlugin($restful);
# foreach( range(1,100) as $i )
#     $router->add("/foo$i" , function() {  return 'true'; });
$router->add('/', function () {
    return 'Hello World, please request /=/test for RESTful resource handler demo.';
});
$r = $router->dispatch(isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/');
if ($r) {
    echo $r();
} else {
    die('Page not found');
}
Exemple #2
0
<?php

require 'tests/bootstrap.php';
require 'tests/RESTfulTest.php';
// start profiling
xhprof_enable();
// do something here
$router = new Roller\Router(null, array('cache_id' => 'roller_xhprof', 'cache_dir' => 'cache'));
$restful = new Roller\Plugin\RESTful(array('prefix' => '/restful'));
$restful->registerResource('blog', 'BlogResourceHandler');
$router->addPlugin($restful);
$_SERVER['REQUEST_METHOD'] = 'GET';
$r = $router->dispatch('/restful/blog/1');
if ($r) {
    $r();
}
// stop profiler
$xhprof_data = xhprof_disable();
// Saving the XHProf run
// using the default implementation of iXHProfRuns.
include_once "xhprof_lib/utils/xhprof_lib.php";
include_once "xhprof_lib/utils/xhprof_runs.php";
$xhprof_runs = new XHProfRuns_Default();
// Save the run under a namespace "xhprof_foo".
//
// **NOTE**:
// By default save_run() will automatically generate a unique
// run id for you. [You can override that behavior by passing
// a run id (optional arg) to the save_run() method instead.]
$profiler_namespace = 'xhprof_roller';
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_roller");