Initial commit

This commit is contained in:
Porawit Dongwang
2026-09-16 23:20:08 +07:00
commit 0041668dbb
32577 changed files with 3687927 additions and 0 deletions
@@ -0,0 +1,43 @@
<?php
namespace app\Core;
class App {
protected $controller = 'Home';
protected $method = 'index';
protected $params = [];
public function __construct() {
$url = $this->parseUrl();
// Check if controller exists
if(isset($url[0]) && file_exists('../app/Controllers/' . ucfirst($url[0]) . 'Controller.php')) {
$this->controller = ucfirst($url[0]);
unset($url[0]);
}
require_once '../app/Controllers/' . $this->controller . 'Controller.php';
$controllerClass = '\\app\\Controllers\\' . $this->controller . 'Controller';
$this->controller = new $controllerClass;
// Check if method exists
if(isset($url[1])) {
if(method_exists($this->controller, $url[1])) {
$this->method = $url[1];
unset($url[1]);
}
}
// Get params
$this->params = $url ? array_values($url) : [];
// Call the method with params
call_user_func_array([$this->controller, $this->method], $this->params);
}
public function parseUrl() {
if(isset($_GET['url'])) {
return explode('/', filter_var(rtrim($_GET['url'], '/'), FILTER_SANITIZE_URL));
}
return [];
}
}