Skip to content

Instantly share code, notes, and snippets.

@alexrohleder
Created February 20, 2016 04:48
Show Gist options
  • Save alexrohleder/bc302708653b68d1b053 to your computer and use it in GitHub Desktop.
Save alexrohleder/bc302708653b68d1b053 to your computer and use it in GitHub Desktop.
<?php
include "vendor/autoload.php";
include "routes.php";
$collector = new Codeburner\Router\Collector();
$matcher = new Codeburner\Router\Matcher($collector);
foreach ($routes as $path) {
$collector->get($path, function () use ($path) {
echo "Matched route with path: $path, passed ", count(func_get_args()), " args.";
});
}
$route = $matcher->match("get", $routes[count($routes) - 1]);
$route->call();
{
"require": {
"nikic/fast-route": "^0.7.0",
"codeburner/router": "^2.0"
}
}
<?php
include "vendor/autoload.php";
include "routes.php";
$mapper = new FastRoute\RouteCollector(new FastRoute\RouteParser\Std, new FastRoute\DataGenerator\GroupCountBased);
foreach ($routes as $path) {
$mapper->addRoute("GET", $path, function () use ($path) {
echo "Matched route with path: $path, passed ", count(func_get_args()), " args.";
});
}
$matcher = new FastRoute\Dispatcher\GroupCountBased($mapper->getData());
$route = $matcher->dispatch("GET", $routes[count($routes) - 1]);
call_user_func_array($route[1], $route[2]);
<?php
/**
* This file is used to generate the routes for both routers.
*/
$routes = [];
//** for 100 routes with args variating on 1 to 9
foreach (range(1, 10) as $i) {
foreach (range(1, 10) as $j) {
$uri = '/' . $i;
foreach (range(1, $j) as $k) {
$uri .= '/{arg' . $k . '}';
}
$routes[] = $uri;
}
}
/**/
/** for 100 routes with 9 args like nikic benchmark
$args = implode('/', array_map(function ($i) {
return "{arg$i}";
}, range(1, 9)));
for ($i = 0, $str = 'a'; $i < 100; $i++, $str++) {
$routes[] = '/' . $str . '/' . $args;
}
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment