Skip to content

Instantly share code, notes, and snippets.

@adrian-enspired
Created March 26, 2020 16:09
Show Gist options
  • Save adrian-enspired/a8bc1bebe7a1b67e8bf85dd1b34ed61f to your computer and use it in GitHub Desktop.
Save adrian-enspired/a8bc1bebe7a1b67e8bf85dd1b34ed61f to your computer and use it in GitHub Desktop.
<?php
class SimpleRouter {
protected $routes = [];
public function add(string $route, callable $controller) : SimpleRouter {
$this->routes[$route] = $controller;
return $this;
}
public function match(string $route) : callable {
if (! isset($this->routes[$route])) {
throw new NotFoundException();
}
return $this->routes[$route];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment