Created
May 7, 2017 16:05
-
-
Save arbass22/a0328a74227539fa048c5fd3ae5d0fda 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
<?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