Testing #10

Merged
PBG2H22AWO merged 4 commits from Testing into main 2024-01-17 10:24:24 +01:00
3 changed files with 100 additions and 65 deletions
Showing only changes of commit 9c82aec3c5 - Show all commits

View File

@ -36,6 +36,16 @@ class BenutzerController
return json_encode($data); return json_encode($data);
} }
public function nextId()
{
$result = $this->db->nextId();
return $result;
}
} }
?> ?>

View File

@ -95,6 +95,27 @@ class BenutzerModel extends Database
} }
public function nextId()
{
$pdo = $this->linkDB();
$sql = "SELECT `auto_increment` FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 'Benutzerkonto'; ";
try {
$stmt = $pdo->prepare($sql);
$stmt->execute();
} catch (\PDOException $e) {
return false;
}
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
return $result;
}
} }
?> ?>

View File

@ -14,47 +14,51 @@
file_get_contents('php://input') die übergebenen json-Strings (für PUT/POST-Requests) file_get_contents('php://input') die übergebenen json-Strings (für PUT/POST-Requests)
*/ */
spl_autoload_register(function ($className) { spl_autoload_register(function ($className) {
if (substr($className, 0, 4) !== 'ppb\\') { return; } if (substr($className, 0, 4) !== 'ppb\\') {
return;
}
$fileName = __DIR__.'/'.str_replace('\\', DIRECTORY_SEPARATOR, substr($className, 4)).'.php'; $fileName = __DIR__ . '/' . str_replace('\\', DIRECTORY_SEPARATOR, substr($className, 4)) . '.php';
if (file_exists($fileName)) { include $fileName; } if (file_exists($fileName)) {
}); include $fileName;
}
});
$endpoint = explode('/', trim($_SERVER['PATH_INFO'],'/')); $endpoint = explode('/', trim($_SERVER['PATH_INFO'], '/'));
$data = json_decode(file_get_contents('php://input'), true); $data = json_decode(file_get_contents('php://input'), true);
$controllerName = $endpoint[0]; $controllerName = $endpoint[0];
$endpoint2 = isset($endpoint[1]) ? $endpoint[1] : false; $endpoint2 = isset($endpoint[1]) ? $endpoint[1] : false;
$id = false; $id = false;
$alias = false; $alias = false;
if ($endpoint2) { if ($endpoint2) {
if (preg_match('/^[0-9]+$/', $endpoint2)) { if (preg_match('/^[0-9]+$/', $endpoint2)) {
$id = $endpoint2; $id = $endpoint2;
} else { } else {
$alias = $endpoint2; $alias = $endpoint2;
} }
} }
$controllerClassName = 'ppb\\Controller\\'.ucfirst($controllerName). 'Controller'; $controllerClassName = 'ppb\\Controller\\' . ucfirst($controllerName) . 'Controller';
if ($_SERVER['REQUEST_METHOD'] == "DELETE") { if ($_SERVER['REQUEST_METHOD'] == "DELETE") {
$methodName = "delete" . ucfirst($controllerName); $methodName = "delete" . ucfirst($controllerName);
} else if ($_SERVER['REQUEST_METHOD'] == "PUT") { } else if ($_SERVER['REQUEST_METHOD'] == "PUT") {
$methodName = "update" . ucfirst($controllerName); $methodName = "update" . ucfirst($controllerName);
} else if ($_SERVER['REQUEST_METHOD'] == "POST") { } else if ($_SERVER['REQUEST_METHOD'] == "POST") {
$methodName = "write" . ucfirst($controllerName); $methodName = "write" . ucfirst($controllerName);
} else if ($_SERVER['REQUEST_METHOD'] == "GET") { } else if ($_SERVER['REQUEST_METHOD'] == "GET") {
if ($alias) { if ($alias) {
$methodName = $alias; $methodName = $alias;
} else { } else {
$methodName = "get" . ucfirst($controllerName); $methodName = "get" . ucfirst($controllerName);
} }
} }
if (method_exists($controllerClassName, $methodName)) { if (method_exists($controllerClassName, $methodName)) {
header('Content-Type: application/json'); header('Content-Type: application/json');
@ -66,20 +70,20 @@
} else } else
//POST //POST
if ($_SERVER['REQUEST_METHOD'] == "POST"){ if ($_SERVER['REQUEST_METHOD'] == "POST") {
echo $controller->$methodName($data); echo $controller->$methodName($data);
} else } else
//DELETE //DELETE
if ($_SERVER['REQUEST_METHOD'] == "DELETE"){ if ($_SERVER['REQUEST_METHOD'] == "DELETE") {
echo $controller->$methodName($id); echo $controller->$methodName($id);
} else } else
//PUT //PUT
{ {
echo $controller->$methodName($id, $data); echo $controller->$methodName($id, $data);
} }
} else { } else {
//http_response_code(404); //http_response_code(404);
new \ppb\Library\Msg(true, 'Page not found: '.$controllerClassName.'::'.$methodName); new \ppb\Library\Msg(true, 'Page not found: ' . $controllerClassName . '::' . $methodName);
} }
?> ?>