Last active
December 1, 2016 19:36
-
-
Save wilcorrea/f24e966cd83aebee7d625de4d3d82611 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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