Abhängigkeiten nicht gefunden
DOCUMENT_ROOT: {$_SERVER['DOCUMENT_ROOT']}

Datei nicht gefunden: {$_SERVER['DOCUMENT_ROOT']}/../vendor/autoload.php

"; echo "

Häufigste Ursache

"; exit(1); } // file exists require_once realpath($_SERVER['DOCUMENT_ROOT'] . "/../vendor/autoload.php"); } catch (Exception $ex) { echo "DOCUMENT_ROOT
{$_SERVER['DOCUMENT_ROOT']}
Error
" . $ex->getMessage() . "
"; } use eftec\bladeone\BladeOne; /* Routing Script for PHP Dev Server */ $verbosity = VERBOSITY; if (preg_match('/\.(?:css|js|png|jpg|jpeg|gif)$/', $_SERVER["REQUEST_URI"])) { return false; } else { if ($verbosity > 1) { echo "
Verbosity-Level: {$verbosity}
" . "
" . print_r($_SERVER, 1) . "

"; } FrontController::handleRequest("$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]", $_SERVER['REQUEST_METHOD'], VERBOSITY); } class RequestData { /** * @var array Request Querystring, broken down to key-value pairs */ public array $query; /** * @var array Request arguments from path, after cutting two segments out for controller and action names */ public array $args; /** * @var string HTTP Verb used */ public string $method; public function getData() { return array_merge($_GET, $_POST); } /** * @return array */ public function getPostData() { return $_POST; } /** * @return array */ public function getGetData() { return $_GET; } /** * RequestData is the way the Router will provide information, use it in your Action methods. * @param $method string Verb used * @param $args array Arguments * @param $query array Key-Value Pairs */ public function __construct($method, $args, $query) { $this->query = $query; $this->args = $args; $this->method = $method; } } class FrontController { public static function handleRequest($url, $method = 'GET', $verbosity = 0, $configPath = CONFIG_WEBROUTES) { assert_blade(); // check if the class is found if (!str_contains($url, ':')) $url = $_SERVER['HTTP_HOST'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI']; $scriptPath = dirname(__FILE__, 2) . '/'; $controllerDirectory = $scriptPath . 'controllers/'; // get a router/web-like config array to override filebased convention $config = FrontController::getConfig($configPath); // /Impressum/ --> ImpressumController->index() $request = parse_url($url); $ctrlName = $request['path']; $actionName = 'index'; $args = array(); $query = array(); parse_str($request['query'] ?? "", $query); // provide POST data if ($method != 'GET') $query = array_merge($query, $_REQUEST); // check, if route has two levels if (strpos($ctrlName, '/', 1) > 0) { $path = explode('/', $request['path']); // Werbeseite/Speise/1/mobile?pretty=true&user=marcel array_shift($path); // skip once $ctrlName = array_shift($path); // Werbeseite $actionName = array_shift($path); // Speise $args = $path; // remainder of path-parts // [1][mobile] if ($verbosity > 1) { echo "
Request\n", print_r($request), "
"; echo "
Path\n", print_r($path), "
"; echo "
Query\n", print_r($query), "
"; } } // fix: trim slashes $ctrlName = trim($ctrlName, '/'); $actionName = trim($actionName, '/'); // $config based renaming of Controller/Action, precedes filebased convention // $config values must use syntax @ if (array_key_exists('/' . $ctrlName . '/' . $actionName, $config)) { $routingConfig = explode('@', $config['/' . $ctrlName . '/' . $actionName]); if ($verbosity > 0) { echo "

Routing Config matched request for /" . $ctrlName . "/" . $actionName . ":

routing config is

" . print_r($routingConfig, 1) . '
'; } // important: overwriting controller and action name $ctrlClass = $routingConfig[0]; $actionName = $routingConfig[1]; } elseif (array_key_exists($request['path'], $config)) { // exact match on full path, this also means "/" $routingConfig = explode('@', $config[$request['path']]); if ($verbosity > 0) { echo "

Routing Config matched for full path " . $request['path'] . ":

routing config is

" . print_r($routingConfig, 1) . '
'; } // important: overwriting controller and action name $ctrlClass = $routingConfig[0]; $actionName = $routingConfig[1]; } else { if ($verbosity > 0) { echo "Request $ctrlName/$actionName was not in \$config."; } // fall back to filebased convention: match controller classes in directory $ctrlClass = ucfirst($ctrlName . 'Controller'); } $ctrlFile = ($ctrlClass . '.php'); $validControllers = FrontController::getValidControllers($controllerDirectory); if (!in_array($controllerDirectory . $ctrlFile, $validControllers)) { if ($verbosity > 0) { echo "

Controller: $ctrlFile not found in

" . print_r($validControllers, 1) . "

Config Array:

" . print_r($config, 1) . "
"; } // #ERROR FrontController::showErrorMessage("

Web Software Error

shrug" . "

Keine entspreche Zuordnung der Route für {$ctrlName}::{$actionName} gefunden. Tippfehler in der Route?" . "

Es konnte keine Klasse " . $ctrlFile . " gefunden werden! Request fehlgeschlagen.

" . "

Prüfen Sie die Einträge in der Datei config/web.php und gleichen Sie den getätigten Aufruf damit ab.

"); } // a file matching has been found, now try to load the class try { require_once $controllerDirectory . $ctrlFile; // instantiate the controller $controller = new $ctrlClass(); $rd = new RequestData($method, $args, $query); if ($verbosity > 0) { var_dump($controller, $rd); } // the controller will load model and view and return some html print call_user_func_array(array($controller, $actionName), array($rd)); } catch (Exception $ex) { // #ERROR FrontController::showErrorMessage( "

Fehler in Controller " . get_class($controller) . "!

Stellen Sie sicher, dass die Action/der Controller existiert.

Das Routing Config-Array hat " . count($config) . " Einträge.

Exception text
" . $ex->getMessage() . "

"); } } public static function showErrorMessage($text, $severity = 3, $die = true) { $styles = array(0 => "background-color: #F08170; border: 2px solid lightgray; padding: 2em; margin: 5em; width: 50%; box-shadow: 0em 0em 1em #F08170;", 1 => "background-color: #F08170; border: 2px solid lightgray; padding: 2em; margin: 5em; width: 50%; box-shadow: 0em 0em 1em #F08170;", 2 => "background-color: #F08170; border: 2px solid lightgray; padding: 2em; margin: 5em; width: 50%; box-shadow: 0em 0em 1em #F08170;", 3 => "background-color: #F08170; border: 2px solid lightgray; padding: 2em; margin: 5em; width: 50%; box-shadow: 0em 0em 1em #F08170;"); print("
{$text}
"); if ($die) exit($severity); } public static function getConfig($configPath) { try { // load the $config Array from a file given in $configPath $path_to_config = realpath($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $configPath); // print("Path to config " . $path_to_config); $config = include $path_to_config; } catch (Exception $e) { print_r($e); $config = array('/' => 'HomeController@index'); } finally { return $config; } } public static function getValidControllers($path = '') { if ($path == '') { $path = getcwd() . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR; } return glob($path . '*Controller.php'); } } function connectdb() { $path_to_config_db = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . CONFIG_DB; $config = include $path_to_config_db; $link = mysqli_connect( // Daten aus config/db.php $config['host'], $config['user'], $config['password'], $config['database'], // Auswahl der Datenbank $config['port'] ?? 3306); if (!$link) { FrontController::showErrorMessage("

Verbindung mit der Datenbank nicht möglich

Verbindung fehlgeschlagen: " . mysqli_connect_error() . ".

Prüfen Sie

  1. die Angaben in der Datei config/db.php: ( ist Benutzer {$config['user']} an Datenbank {$config['database']} auf Server {$config['host']} korrekt?)
  2. ob Ihre Datenbank unter der oben gezeigten Adresse läuft
"); exit(1); } if (mysqli_connect_errno()) { FrontController::showErrorMessage("

Verbindung mit der Datenbank nicht möglich

Fehlermeldung
" . mysqli_connect_error() . "
", 2, true); exit(1); } return $link; } function view($viewname, $viewargs = array()) { $views = dirname(__DIR__) . '/views'; $cache = dirname(__DIR__) . '/storage/cache'; $blade = new BladeOne($views, $cache, BladeOne::MODE_DEBUG); return $blade->run($viewname, $viewargs); } /** * let the script die if the php minimum version is not met. * @param $minversion * @return void */ function assert_php_version($minversion = '8.0.0') { $version_too_low = 0; $minver = explode('.', $minversion); $version = explode('.', phpversion()); if (intval($minver[0]) > intval($version[0])) { $version_too_low = 1; } elseif (intval($minver[1]) > intval($version[1])) { $version_too_low = 1; } elseif (intval($minver[2]) > intval($version[2])) { $version_too_low = 1; } if ($version_too_low) { FrontController::showErrorMessage("Diese PHP-Version wird nicht unterstützt: Minimum PHP Version " . $minversion . "
Sie betreiben gerade PHP Version " . phpversion()); exit(1); } // version is okay, go on. } /** * let the script die if the path contains problematic characters. * @return void */ function assert_path(): void { static $chars = array("[", "]", "{", "}"); $charsfound = 0; str_ireplace($chars, '', $_SERVER['DOCUMENT_ROOT'], $charsfound); if ($charsfound > 0) { FrontController::showErrorMessage("

Bitte verwenden Sie einen anderen Ordner für das Projekt!

Der Pfad " . $_SERVER['DOCUMENT_ROOT'] . " enthält " . $charsfound . " problematische Zeichen, die die korrekte Ausführung verhindern.

>

Bekannte problematische Zeichen sind

 " . implode(" ", $chars) . " 
"); exit(1); } } function assert_blade(): void { if (!class_exists('eftec\bladeone\BladeOne')) { // #ERROR FrontController::showErrorMessage("

Fehler: Blade wurde nicht gefunden

Tipps für die Lösung:

"); exit(1); } }