init Abgabe

This commit is contained in:
WummerMIB
2025-12-04 23:37:05 +01:00
parent dda70db0be
commit 4db823c14a
534 changed files with 72693 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
<?php
class Database {
private static $db = null; // Singleton-Instanz
private $mysqli; // echte DB-Verbindung
// Konstruktor private → kann nur innerhalb der Klasse aufgerufen werden
private function __construct() {
$this->mysqli = new mysqli(
DB_CONNECTION,
DB_USER,
DB_PASS,
DB_DBNAME,
DB_PORT
);
if ($this->mysqli->connect_error) {
die("MySQL Connection Error: " . $this->mysqli->connect_error);
}
}
// Singleton-Zugriff
public static function getInstance() {
if (self::$db === null) {
self::$db = new Database();
}
return self::$db;
}
// Zugriff auf MySQLi
public function getConnection() {
return $this->mysqli;
}
}
+17
View File
@@ -0,0 +1,17 @@
<?php
class Factory{
public static function createLoginModel(){
return new LoginModel();
}
public static function createBenutzerModel(){
return new BenutzerModel();
}
public static function createChatModel(){
return new ChatModel();
}
}
+69
View File
@@ -0,0 +1,69 @@
<?php
class Model{
protected $errorArray = [];
public function setValues($values) {
foreach ($values as $key => $value) {
$method = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
if (method_exists($this, $method)) {
$this->$method($value);
}
}
}
/**
* Automatische Validierung aller Attribute der Subklasse
* Prüft:
* - leere Felder
* - minimale Länge (2)
* - potenziell unsichere Zeichen
*/
protected function validate() {
$this->errorArray = [];
$reflection = new ReflectionClass($this); // Reflektiert Subklasse
$properties = $reflection->getProperties(ReflectionProperty::IS_PROTECTED);
foreach ($properties as $prop) {
$name = $prop->getName();
$value = $this->$name;
// 1) Pflichtfeldprüfung
if (empty($value)) {
$this->errorArray[$name] = "Bitte gib einen Wert für {$name} ein.";
continue;
}
// 2) Minimale Länge prüfen (nur Strings)
if (is_string($value) && strlen($value) < 2) {
$this->errorArray[$name] = "Der Wert von {$name} muss mindestens 2 Zeichen lang sein.";
}
// 3) Prüfen auf potenziell unsichere Zeichen (XSS / SQL-Injection)
if ($this->containsInvalidChars($value)) {
$this->errorArray[$name] = "Der Wert von {$name} enthält ungültige Zeichen.";
}
}
return $this->errorArray; // Fehler-Array zurückgeben
}
/**
* Prüft auf verdächtige Zeichen
*/
protected function containsInvalidChars($value) {
if (!is_string($value)) return false;
// einfache Regeln: < > ' " ; %
if (preg_match('/[<>\'"%;]/', $value)) {
return true;
}
return false;
}
}