Docs
This commit is contained in:
parent
4d25387a47
commit
03da043be3
3
exam/api/docs/index.css
Normal file
3
exam/api/docs/index.css
Normal file
@ -0,0 +1,3 @@
|
||||
body {
|
||||
background-color: red;
|
||||
}
|
||||
@ -1 +1,10 @@
|
||||
DOCUMENTATION
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<link href="./index.css" rel="stylesheet" />
|
||||
|
||||
<title>Calculator</title>
|
||||
</head>
|
||||
|
||||
<body></body>
|
||||
</html>
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
<?php
|
||||
foreach (glob(__DIR__ . '/*/index.php') as $filename) {
|
||||
require_once($filename);
|
||||
}
|
||||
|
||||
Headers::redirect("docs/index.html");
|
||||
|
||||
26
exam/api/posts/index.php
Normal file
26
exam/api/posts/index.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
switch ($method) {
|
||||
case "GET":
|
||||
return get();
|
||||
default:
|
||||
return Response::api("$method not supported", 500);
|
||||
}
|
||||
|
||||
function get()
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
|
||||
$query =
|
||||
"SELECT
|
||||
*
|
||||
FROM
|
||||
egb_gaestebuch";
|
||||
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->execute();
|
||||
|
||||
Response::api($stmt->fetchAll());
|
||||
}
|
||||
@ -11,5 +11,16 @@ switch ($method) {
|
||||
|
||||
function get()
|
||||
{
|
||||
Response::api("GET USERS");
|
||||
$db = Database::getInstance();
|
||||
|
||||
$query =
|
||||
"SELECT
|
||||
*
|
||||
FROM
|
||||
egb_benutzer";
|
||||
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->execute();
|
||||
|
||||
Response::api($stmt->fetchAll());
|
||||
}
|
||||
|
||||
9
exam/config/database.php
Normal file
9
exam/config/database.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
"host" => "usersql.zedat.fu-berlin.de",
|
||||
"user" => "khofmann-sql",
|
||||
"passwd" => "xz8c7m7p",
|
||||
"database" => "khofmann-db1",
|
||||
"charset" => "utf8",
|
||||
];
|
||||
@ -4,7 +4,11 @@ $path = ltrim(str_replace(Config::getBasePath(), "", $_SERVER['REQUEST_URI']), "
|
||||
|
||||
try {
|
||||
if (substr($path, 0, 3) === "api") {
|
||||
require_once __DIR__ . "/../api/index.php";
|
||||
if (strpos($path, "docs") === false) {
|
||||
require_once __DIR__ . "/../$path/index.php";
|
||||
} else {
|
||||
Headers::redirect("index.html");
|
||||
}
|
||||
} else {
|
||||
require_once __DIR__ . "/../pages/index.html";
|
||||
}
|
||||
|
||||
7
exam/vendor/config/config.php
vendored
7
exam/vendor/config/config.php
vendored
@ -5,10 +5,12 @@ class Config
|
||||
private static $instances = [];
|
||||
|
||||
private array $app;
|
||||
private array $database;
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
$this->app = require_once __DIR__ . "/../../config/app.php";
|
||||
$this->database = require_once __DIR__ . "/../../config/database.php";
|
||||
}
|
||||
|
||||
protected function __clone()
|
||||
@ -34,4 +36,9 @@ class Config
|
||||
{
|
||||
return Config::getInstance()->app["basePath"];
|
||||
}
|
||||
|
||||
public static function getDatabase()
|
||||
{
|
||||
return Config::getInstance()->database;
|
||||
}
|
||||
}
|
||||
|
||||
32
exam/vendor/database/database.php
vendored
Normal file
32
exam/vendor/database/database.php
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
class Database extends PDO
|
||||
{
|
||||
private static $instances = [];
|
||||
|
||||
protected function __construct($dsn, $username = null, $password = null, array $options = null)
|
||||
{
|
||||
parent::__construct($dsn, $username, $password, $options);
|
||||
}
|
||||
|
||||
public static function getInstance(): Database
|
||||
{
|
||||
$cls = static::class;
|
||||
if (!isset(self::$instances[$cls])) {
|
||||
$dataAccess = Config::getDatabase();
|
||||
self::$instances[$cls] = new static(
|
||||
"mysql:host={$dataAccess["host"]};dbname={$dataAccess["database"]};charset={$dataAccess["charset"]}",
|
||||
$dataAccess["user"],
|
||||
$dataAccess["passwd"],
|
||||
[
|
||||
PDO::ATTR_PERSISTENT => false,
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return self::$instances[$cls];
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user