Skip to content

Instantly share code, notes, and snippets.

@aligoren
Last active March 6, 2019 06:19
Show Gist options
  • Save aligoren/6559f109eb9c0fa3ab1ae524acfcb796 to your computer and use it in GitHub Desktop.
Save aligoren/6559f109eb9c0fa3ab1ae524acfcb796 to your computer and use it in GitHub Desktop.
Router Class
<?php
require_once 'RouterProvider.php';
Router::Map('GET', '/hakkimda', function() {
echo 'Hakkımda';
});
Router::Map('GET', '/hakkimda/iletisim', function() {
echo 'İletişim';
});
<?php
class Router {
public static function Map($method, $page, $closure) {
$reqMethod = $_SERVER['REQUEST_METHOD'] === strtoupper($method);
$reqPage = $_GET['params'] === ltrim($page, '/');
if($reqMethod and $reqPage) {
return (is_object($closure) && ($closure instanceof Closure)) ? $closure() : $closure;
}
}
}
/*
EN: Usage
TR: Kullanım
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment