Basic Framework

This commit is contained in:
2024-07-13 17:22:53 +02:00
parent c1fffec124
commit 4d25387a47
22 changed files with 250 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
Order deny,allow
Deny from all
Allow from 127.0.0.1
+7
View File
@@ -0,0 +1,7 @@
<?php
spl_autoload_register(function ($name) {
$_name = lcfirst($name);
require_once __DIR__ . "/$_name/$_name.php";
});
+37
View File
@@ -0,0 +1,37 @@
<?php
class Config
{
private static $instances = [];
private array $app;
protected function __construct()
{
$this->app = require_once __DIR__ . "/../../config/app.php";
}
protected function __clone()
{
}
public function __wakeup()
{
throw new \Exception("Cannot unserialize a singleton.");
}
private static function getInstance(): Config
{
$cls = static::class;
if (!isset(self::$instances[$cls])) {
self::$instances[$cls] = new static();
}
return self::$instances[$cls];
}
public static function getBasePath()
{
return Config::getInstance()->app["basePath"];
}
}
+22
View File
@@ -0,0 +1,22 @@
<?php
class Headers
{
static function json()
{
header('Content-Type: text/html; charset=utf-8');
header("Content-Type: text/json");
}
static function html()
{
header('Content-Type: text/html; charset=utf-8');
}
static function redirect(string $newUrl, bool $permanent = FALSE)
{
header('Location: ' . $newUrl, true, $permanent ? 301 : 303);
exit();
}
}
+11
View File
@@ -0,0 +1,11 @@
<?php
class Response
{
public static function api($content, int $code = 200)
{
Headers::json();
http_response_code($code);
echo json_encode($content);
}
}