hi leute, bin bisschen müde und mir war langweilig. hab eben mal so kurz ne kleine router gemacht (NICHT FERTIG, werd glaub morgen weiter machen yo).
code:
PHP
<?php
namespace Shotly\System;
if(!defined('IN_CMS'))
exit ('Permission denied.');
class Router {
public static function add($url, $ControllerMethod) {
if(!array_key_exists($url, self::$routes)) {
$controllerMethod = explode('@', $ControllerMethod);
self::$routes[$url] = [$controllerMethod[0], $controllerMethod[1]];
}
}
public static function run() {
self::$routeFile = include('routes.php');
self::check();
}
private static function check() {
$requestURI = explode('/', trim($_SERVER['REQUEST_URI'], '/'));
$scriptName = explode('/', trim($_SERVER['SCRIPT_NAME'], '/'));
$parts = array_diff_assoc($requestURI, $scriptName);
if (empty($parts))
{
return '/';
}
$uri = implode('/', $parts);
if (isset(self::$routes[$uri]))
{
//gefunden im array
}
else {
//error
}
}
private static function get($uri) {
if(array_key_exists($uri, self::$routes)) {
return self::$routes[$uri];
}
else {
return null;
}
}
private static function ErrorDispatcher() {
}
public static function redirect($url, $errorCode = null) {
}
private static $routes = [];
private static $routeFile;
}
Alles anzeigen
PHP
<?php
self::add('', 'HomeController@test');
self::add('hallo', 'TestController@test');
self::add('hallo/digger/penis', 'TestController@test');
jo gönnt euch