Skip to content

Instantly share code, notes, and snippets.

@lpj145
Last active September 15, 2017 16:22
Show Gist options
  • Save lpj145/11d9174f96603a65a5bcb753c3d4e646 to your computer and use it in GitHub Desktop.
Save lpj145/11d9174f96603a65a5bcb753c3d4e646 to your computer and use it in GitHub Desktop.
<?php
namespace App\Core;
class Core {
public function run() {
$url = '/';
if (isset($_GET['url'])) {
$url .= $_GET['url'];
}
$params = array();
if (!empty($url) && $url != '/') {
$url = explode('/', $url);
array_shift($url);
$currentController = $url[0] . 'Controller';
array_shift($url);
if (isset($url[0]) && !empty($url[0])) {
$currentAction = $url[0];
array_shift($url);
} else {
$currentAction = 'index';
}
if (count($url) > 0) {
$params = $url;
}
} else {
$currentController = 'homeController';
$currentAction = 'index';
}
$controllerClassName = '\\App\\Controllers\\'.$currentController;
if (!class_exists($controllerClassName)) {
(new \App\Controllers\errorController())->index();
return;
}
$controllerClass = new $controllerClassName();
$controllerClass->{$currentAction}($params);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment