new
This commit is contained in:
1 parent
85219fdb59
commit
bfd16c310d
1 file changed
+197
-4
@@ -34,6 +34,7 @@ $dirs = [
|
||||
'WEBROOT/src/utils',
|
||||
'WEBROOT/src/MVC',
|
||||
'WEBROOT/src/MVC/Core',
|
||||
'WEBROOT/src/MVC/Classes',
|
||||
'WEBROOT/src/MVC/Controller',
|
||||
'WEBROOT/src/MVC/Model',
|
||||
'WEBROOT/src/MVC/View',
|
||||
@@ -398,6 +399,148 @@ function db_connect() {
|
||||
}
|
||||
}
|
||||
PHP;
|
||||
// -- CLASSES --
|
||||
|
||||
$files['WEBROOT/src/MVC/Classes/Api.php'] = <<<'PHP'
|
||||
<?php
|
||||
|
||||
namespace MVC\Classes;
|
||||
|
||||
class Api {
|
||||
public static function jsonResponse($data, int $statusCode = 200) {
|
||||
header('Content-Type: application/json');
|
||||
http_response_code($statusCode);
|
||||
echo json_encode(
|
||||
[
|
||||
'status' => $statusCode === 200 ? 'success' : 'error',
|
||||
'data' => $data,
|
||||
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE
|
||||
);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
PHP;
|
||||
|
||||
$files['WEBROOT/src/MVC/Classes/Client.php'] = <<<'PHP'
|
||||
<?php
|
||||
|
||||
namespace MVC\Classes;
|
||||
|
||||
class Client {
|
||||
|
||||
public static function ip() {
|
||||
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||
$ipList = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
|
||||
return trim($ipList[0]);
|
||||
} else if (!empty($_SERVER['REMOTE_ADDR'])) {
|
||||
return $_SERVER['REMOTE_ADDR'];
|
||||
} else {
|
||||
return 'UNKNOWN';
|
||||
}
|
||||
}
|
||||
|
||||
public static function port() {
|
||||
return $_SERVER['REMOTE_PORT'] ?? 'UNKNOWN';
|
||||
}
|
||||
|
||||
public static function country() {
|
||||
$response = file_get_contents('http://ip-api.com/json/{' . self::ip() . '}?fields=country,countryCode');
|
||||
$data = json_decode($response);
|
||||
return $data->country ?? 'UNKNOWN';
|
||||
}
|
||||
|
||||
public static function userAgent() {
|
||||
return $_SERVER['HTTP_USER_AGENT'] ?? 'UNKNOWN';
|
||||
}
|
||||
}
|
||||
PHP;
|
||||
|
||||
$files['WEBROOT/src/MVC/Classes/Cookie.php'] = <<<'PHP'
|
||||
<?php
|
||||
|
||||
namespace MVC\Classes;
|
||||
|
||||
class Cookie {
|
||||
public function set(string $CookieName, int $CookieValue, int $CookieTime) {
|
||||
setcookie($CookieName, $CookieValue, time()+($CookieTime*60));
|
||||
}
|
||||
|
||||
public function read(string $CookieName) {
|
||||
if (isset($_COOKIE[$CookieName])) {
|
||||
return $_COOKIE[$CookieName];
|
||||
}
|
||||
return 'Cookie not set';
|
||||
}
|
||||
|
||||
public function Delete(string $CookieName) {
|
||||
setcookie($CookieName, "", time()-(3600*24));
|
||||
}
|
||||
}
|
||||
PHP;
|
||||
|
||||
$files['WEBROOT/src/MVC/Classes/Request.php'] = <<<'PHP'
|
||||
<?php
|
||||
|
||||
namespace MVC\Classes;
|
||||
|
||||
class Request {
|
||||
public static function method() {
|
||||
return $_SERVER['REQUEST_METHOD'] ?? 'UNKNOWN';
|
||||
}
|
||||
|
||||
public static function uri() {
|
||||
return $_SERVER['REQUEST_URI'] ?? 'UNKNOWN';
|
||||
}
|
||||
|
||||
public static function headers() {
|
||||
return getallheaders();
|
||||
}
|
||||
|
||||
public static function body() {
|
||||
return file_get_contents('php://input');
|
||||
}
|
||||
|
||||
public static function queryParams() {
|
||||
return $_GET;
|
||||
}
|
||||
|
||||
public static function time() {
|
||||
return $_SERVER['REQUEST_TIME'] ?? 'UNKNOWN';
|
||||
}
|
||||
|
||||
public static function referrer() {
|
||||
return $_SERVER['HTTP_REFERER'] ?? 'UNKNOWN';
|
||||
}
|
||||
}
|
||||
PHP;
|
||||
|
||||
$files['WEBROOT/src/MVC/Classes/Server.php'] = <<<'PHP'
|
||||
<?php
|
||||
|
||||
namespace MVC\Classes;
|
||||
|
||||
class Server {
|
||||
public static function documentRoot() {
|
||||
return $_SERVER['DOCUMENT_ROOT'] ?? 'UNKNOWN';
|
||||
}
|
||||
|
||||
public static function currentDir() {
|
||||
return __DIR__;
|
||||
}
|
||||
|
||||
public static function currentScript() {
|
||||
return $_SERVER['SCRIPT_NAME'] ?? 'UNKNOWN';
|
||||
}
|
||||
|
||||
public static function name() {
|
||||
return $_SERVER['SERVER_NAME'] ?? 'UNKNOWN';
|
||||
}
|
||||
|
||||
public static function port() {
|
||||
return $_SERVER['SERVER_PORT'] ?? 'UNKNOWN';
|
||||
}
|
||||
}
|
||||
PHP;
|
||||
|
||||
// --- CORE ---
|
||||
$files['WEBROOT/src/MVC/Core/Controller.php'] = <<<'PHP'
|
||||
@@ -666,6 +809,7 @@ $files['WEBROOT/src/MVC/Layout/Templates/main.php'] = <<<'HTML'
|
||||
.btn-toggle:hover { background: rgba(255,255,255,0.1); }
|
||||
nav a { display: block; padding: 12px; text-decoration: none; color: inherit; border-radius: 5px; margin-bottom: 5px; }
|
||||
nav a:hover { background: rgba(0,0,0,0.05); }
|
||||
nav a.active { background: rgba(0,0,0,0.05); }
|
||||
.logo { font-size: 1.4rem; font-weight: bold; }
|
||||
</style>
|
||||
</head>
|
||||
@@ -692,10 +836,31 @@ $files['WEBROOT/src/MVC/Layout/Templates/main.php'] = <<<'HTML'
|
||||
HTML;
|
||||
|
||||
// --- CONTROLLERS ---
|
||||
$files['WEBROOT/src/MVC/Controller/ApiController.php'] = <<<'PHP'
|
||||
<?php
|
||||
|
||||
namespace MVC\Controller;
|
||||
|
||||
use MVC\Core\Controller;
|
||||
use MVC\Classes\Api;
|
||||
|
||||
class ApiController extends Controller {
|
||||
public static function (){
|
||||
return Api::jsonResponse([
|
||||
'data' => 'DummyData',
|
||||
]);
|
||||
}
|
||||
}
|
||||
PHP;
|
||||
|
||||
$files['WEBROOT/src/MVC/Controller/HomeController.php'] = <<<'PHP'
|
||||
<?php
|
||||
namespace MVC\Controller;
|
||||
use MVC\Core\Controller;
|
||||
use MVC\Classes\Client;
|
||||
use MVC\Classes\Cookie;
|
||||
use MVC\Classes\Request;
|
||||
use MVC\Classes\Server;
|
||||
class HomeController extends Controller {
|
||||
|
||||
public function index() {
|
||||
@@ -718,6 +883,10 @@ $files['WEBROOT/src/MVC/Controller/TestController.php'] = <<<'PHP'
|
||||
<?php
|
||||
namespace MVC\Controller;
|
||||
use MVC\Core\Controller;
|
||||
use MVC\Classes\Client;
|
||||
use MVC\Classes\Cookie;
|
||||
use MVC\Classes\Request;
|
||||
use MVC\Classes\Server;
|
||||
class TestController extends Controller {
|
||||
|
||||
public function service1() {
|
||||
@@ -750,7 +919,22 @@ $files['WEBROOT/src/MVC/View/test1.php'] = "<h1>Service 1</h1><p><?= \$msg ?></p
|
||||
$files['WEBROOT/src/MVC/View/test2.php'] = "<h1>System Check</h1><ul><?php foreach(\$data as \$k => \$v): ?><li><b><?= \$k ?>:</b> <?= \$v ?></li><?php endforeach; ?></ul>";
|
||||
|
||||
// --- API ---
|
||||
$files['WEBROOT/api/v1/get.php'] = "<?php header('Content-Type: application/json'); echo json_encode(['status' => 'online']);";
|
||||
$files['WEBROOT/api/v1/get.php'] = <<<'PHP
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require_once __DIR__ . '/../../src/MVC/autoloader.php';
|
||||
|
||||
use MVC\Controller\ApiController;
|
||||
|
||||
$api = (new ApiController());
|
||||
|
||||
try {
|
||||
Api::jsonResponse($api->get());
|
||||
catch (\Exception $e) {
|
||||
Api::jsonResponse(§e->getMessage(), 404);
|
||||
}
|
||||
|
||||
PHP;
|
||||
|
||||
// --- ENTRY POINT ---
|
||||
$files['WEBROOT/index.php'] = <<<'PHP'
|
||||
@@ -772,11 +956,16 @@ try {
|
||||
|
||||
// Sidebar Block
|
||||
ob_start();
|
||||
$navItems = [
|
||||
'home' => '🏠 Home',
|
||||
'test1' => '🛠️Test 1',
|
||||
'test2' => '📊 Test 2',
|
||||
];
|
||||
?>
|
||||
<nav>
|
||||
<a href="?service=home">🏠 Home</a>
|
||||
<a href="?service=test1">🛠️ Test 1</a>
|
||||
<a href="?service=test2">📊 Test 2</a>
|
||||
<?php foreach ($navItems as $navKey => $navLabel): ?>
|
||||
<a href="?service=<?= $navKey ?>" class="<?= $service === $navKey ? 'active' : '' ?>"><?= $navLabel ?></a>
|
||||
<?php endforeach; ?>
|
||||
</nav>
|
||||
<?php
|
||||
$layout->setBlock('sidebar', ob_get_clean());
|
||||
@@ -909,6 +1098,10 @@ $controllerContent = <<<PHPCTRL
|
||||
namespace MVC\Controller;
|
||||
|
||||
use MVC\Core\Controller;
|
||||
use MVC\Classes\Client;
|
||||
use MVC\Classes\Cookie;
|
||||
use MVC\Classes\Request;
|
||||
use MVC\Classes\Server;
|
||||
// use MVC\Model\YourModel; // Importiere dein Model
|
||||
|
||||
class {$className}Controller extends Controller {
|
||||
|
||||
Reference in new issue
Block a user