Compare commits

..

No commits in common. "1826e9f61bb3738f036af881c435d14830e992c2" and "b6ec972c19e3e3126414554b9172c0bb21a4de92" have entirely different histories.

3 changed files with 65 additions and 95 deletions

View File

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

View File

@ -94,25 +94,7 @@ class BenutzerModel extends Database
return $result; return $result;
} }
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

@ -1,4 +1,4 @@
<?php <?php
/* /*
Dieses Skript analysiert die URL und generiert daraus die passenden Controller-Aufrufe Dieses Skript analysiert die URL und generiert daraus die passenden Controller-Aufrufe
@ -14,76 +14,72 @@
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\\') { if (substr($className, 0, 4) !== 'ppb\\') { return; }
return;
$fileName = __DIR__.'/'.str_replace('\\', DIRECTORY_SEPARATOR, substr($className, 4)).'.php';
if (file_exists($fileName)) { include $fileName; }
});
$endpoint = explode('/', trim($_SERVER['PATH_INFO'],'/'));
$data = json_decode(file_get_contents('php://input'), true);
$controllerName = $endpoint[0];
$endpoint2 = isset($endpoint[1]) ? $endpoint[1] : false;
$id = false;
$alias = false;
if ($endpoint2) {
if (preg_match('/^[0-9]+$/', $endpoint2)) {
$id = $endpoint2;
} else {
$alias = $endpoint2;
}
} }
$fileName = __DIR__ . '/' . str_replace('\\', DIRECTORY_SEPARATOR, substr($className, 4)) . '.php'; $controllerClassName = 'ppb\\Controller\\'.ucfirst($controllerName). 'Controller';
if (file_exists($fileName)) { if ($_SERVER['REQUEST_METHOD'] == "DELETE") {
include $fileName; $methodName = "delete" . ucfirst($controllerName);
} else if ($_SERVER['REQUEST_METHOD'] == "PUT") {
$methodName = "update" . ucfirst($controllerName);
} else if ($_SERVER['REQUEST_METHOD'] == "POST") {
$methodName = "write" . ucfirst($controllerName);
} else if ($_SERVER['REQUEST_METHOD'] == "GET") {
if ($alias) {
$methodName = $alias;
} else {
$methodName = "get" . ucfirst($controllerName);
}
} }
});
if (method_exists($controllerClassName, $methodName)) {
$endpoint = explode('/', trim($_SERVER['PATH_INFO'], '/'));
$data = json_decode(file_get_contents('php://input'), true); header('Content-Type: application/json');
$controllerName = $endpoint[0]; $controller = new $controllerClassName();
$endpoint2 = isset($endpoint[1]) ? $endpoint[1] : false; //GET
$id = false; if ($_SERVER['REQUEST_METHOD'] == "GET") {
$alias = false;
echo $controller->$methodName($id);
if ($endpoint2) {
if (preg_match('/^[0-9]+$/', $endpoint2)) { } else
$id = $endpoint2; //POST
} else { if ($_SERVER['REQUEST_METHOD'] == "POST"){
$alias = $endpoint2;
}
}
$controllerClassName = 'ppb\\Controller\\' . ucfirst($controllerName) . 'Controller';
if ($_SERVER['REQUEST_METHOD'] == "DELETE") {
$methodName = "delete" . ucfirst($controllerName);
} else if ($_SERVER['REQUEST_METHOD'] == "PUT") {
$methodName = "update" . ucfirst($controllerName);
} else if ($_SERVER['REQUEST_METHOD'] == "POST") {
$methodName = "write" . ucfirst($controllerName);
} else if ($_SERVER['REQUEST_METHOD'] == "GET") {
if ($alias) {
$methodName = $alias;
} else {
$methodName = "get" . ucfirst($controllerName);
}
}
if (method_exists($controllerClassName, $methodName)) {
header('Content-Type: application/json');
$controller = new $controllerClassName();
//GET
if ($_SERVER['REQUEST_METHOD'] == "GET") {
echo $controller->$methodName($id);
} else
//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);
} }
?> ?>