Last active
September 15, 2017 16:22
-
-
Save lpj145/11d9174f96603a65a5bcb753c3d4e646 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?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