Skip to content

Instantly share code, notes, and snippets.

@arbass22
Created May 7, 2017 16:05
Show Gist options
  • Save arbass22/a0328a74227539fa048c5fd3ae5d0fda to your computer and use it in GitHub Desktop.
Save arbass22/a0328a74227539fa048c5fd3ae5d0fda to your computer and use it in GitHub Desktop.
<?hh
use Facebook\HackRouter\{
HttpMethod,
NotFoundException
};
class Request {
public function __construct(private $controller) {
}
public static function get(): Request {
$router = new Router();
$path = $_SERVER['REQUEST_URI'];
try {
// Attmept to match the path with the autogenerated router
list($controller_name, $_) = $router->routeRequest(HttpMethod::GET, $path);
$controller = new $controller_name();
} catch (NotFoundException $e) {
$controller = new NotFoundController();
}
return new Request($controller);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment