Skip to content

Instantly share code, notes, and snippets.

@wilcorrea
Last active December 1, 2016 19:36
Show Gist options
  • Save wilcorrea/f24e966cd83aebee7d625de4d3d82611 to your computer and use it in GitHub Desktop.
Save wilcorrea/f24e966cd83aebee7d625de4d3d82611 to your computer and use it in GitHub Desktop.
<?php
namespace Hero;
class Router
{
private $routes = [];
public function on($method, $path, $callback)
{
$method = strtolower($method);
if (!isset($this->routes[$method])) {
$this->routes[$method] = [];
}
$uri = substr($path, 0, 1) !== '/' ? '/' . $path : $path;
$pattern = str_replace('/', '\/', $uri);
$route = '/^' . $pattern . '$/';
$this->routes[$method][$route] = $callback;
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment