Ejemplo n.º 1
0
 function test()
 {
     $router = new Roller\Router();
     $router->importAnnotationMethods('AnnotationTestController', '/Action$/');
     $route = $router->dispatch('/');
     ok($route);
     is('index', $route());
     $route = $router->dispatch('/hello/John');
     ok($route);
     is('John', $route());
 }
Ejemplo n.º 2
0
 function test()
 {
     $router = new Roller\Router();
     $router->any('/hello', function () {
         return 'Hello';
     });
     $matched = $router->dispatch('/hello');
     ok($matched);
     ok(is_callable($matched));
     ok($matched['callback']);
     is('Hello', $matched());
     is('/hello', $matched->path);
 }
Ejemplo n.º 3
0
 function testPHPDumper()
 {
     $routes1 = new Roller\RouteSet();
     $routes2 = new Roller\RouteSet();
     $routes1->add('/item', function () {
         return 'item';
     });
     $routes2->add('/subitem', function () {
         return 'subitem';
     });
     $routes1->mount('/item', $routes2);
     $dumper = new Roller\Dumper\PhpDumper();
     $code = $dumper->dump($routes1);
     $cRoutes = eval($code);
     $router = new Roller\Router($cRoutes);
     $r = $router->dispatch('/item');
     is('item', $r());
     $r = $router->dispatch('/item/subitem');
     is('subitem', $r());
 }
Ejemplo n.º 4
0
 function testApcCache()
 {
     ini_set('apc.enable_cli', 1);
     apc_store('test', 3);
     is(3, apc_fetch('test'));
     $router = new Roller\Router(null, array('cache_id' => '_router_testing_'));
     is(Roller\Router::cache_type_apc, $router->cache);
     $router->add('/item/:id', function ($id) {
         return $id;
     });
     $r = $router->dispatch('/item/12');
     $code = apc_fetch('_router_testing_');
     ok($code);
     $routes = eval($code);
     ok($routes);
     ok($routes->routes);
     // make sure cache reload works
     $router = new Roller\Router(null, array('cache_id' => '_router_testing_'));
     $r = $router->dispatch('/item/12');
     is('12', $r());
     apc_delete('_router_testing_');
 }
Ejemplo n.º 5
0
Archivo: bench.php Proyecto: c9s/roller
<?php

if (extension_loaded('roller')) {
    echo "extension loaded\n";
}
require '../vendor/pear/Universal/ClassLoader/BasePathClassLoader.php';
$loader = new \Universal\ClassLoader\BasePathClassLoader(array('../src', '../vendor/pear', '/opt/local/lib/php'));
$loader->useIncludePath(true);
$loader->register();
echo "init router\n";
$router = new Roller\Router();
$router->add('/', function () {
    return 'Hello World, please request /=/test for RESTful resource handler demo.';
});
foreach (range(1, 1000) as $i) {
    $router->add('/foo' . $i, function () {
        return 'bar';
    });
}
$router->routes->compile();
// var_dump( $router->routes->routes );
echo "dispatching\n";
$b = new SimpleBench();
$b->setN(10);
$b->iterate('roller_ext', 'roller_ext', function () use($router) {
    $r = roller_dispatch($router->routes->routes, '/foo1000');
});
$router->enableExtension = false;
$b->iterate('roller', 'roller', function () use($router) {
    $r = $router->dispatch('/foo1000');
});
Ejemplo n.º 6
0
 function testFileCache()
 {
     if (!file_exists('tests/cache')) {
         mkdir('tests/cache', 0755, true);
     }
     $router = new Roller\Router(null, array('cache_id' => '_router_testing_', 'cache_dir' => 'tests/cache'));
     is(Roller\Router::cache_type_file, $router->cache);
     $router->add('/item/:id', function ($id) {
         return $id;
     });
     $r = $router->dispatch('/item/12');
     ok($r);
     is('12', $r());
     ok(file_exists('tests/cache/_router_testing_'));
     // the cache should be reloaded.
     $router = new Roller\Router(null, array('cache_id' => '_router_testing_', 'cache_dir' => 'tests/cache'));
     $r = $router->dispatch('/item/12');
     ok($r);
     is('12', $r());
     unlink('tests/cache/_router_testing_');
 }
Ejemplo n.º 7
0
Archivo: index.php Proyecto: c9s/roller
    {
        $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');
}
Ejemplo n.º 8
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");