add docs
This commit is contained in:
1 parent
ec6be1da80
commit
655db43616
1 file changed
+117
-4
@@ -930,6 +930,22 @@ class AuthController extends Controller {
|
||||
}
|
||||
PHP;
|
||||
|
||||
$files['WEBROOT/src/MVC/Controller/DocsController.php'] = <<<'PHP'
|
||||
<?php
|
||||
|
||||
namespace MVC\Controller;
|
||||
|
||||
use MVC\Core\Controller;
|
||||
|
||||
class DocsController extends Controller {
|
||||
public function index() {
|
||||
return $this->render('docs', [
|
||||
'title' => '📚 System-Dokumentation'
|
||||
]);
|
||||
}
|
||||
}
|
||||
PHP;
|
||||
|
||||
$files['WEBROOT/src/MVC/Controller/TestController.php'] = <<<'PHP'
|
||||
<?php
|
||||
namespace MVC\Controller;
|
||||
@@ -988,6 +1004,100 @@ $files['WEBROOT/src/MVC/View/home.php'] = "<h1>Dashboard</h1><p>Willkommen in de
|
||||
$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>";
|
||||
|
||||
$files['WEBROOT/src/MVC/View/docs.php'] = <<<'HTML'
|
||||
<div class="docs-container">
|
||||
<h1>🏛️ Framework Architektur & Dokumentation</h1>
|
||||
|
||||
<div class="toc">
|
||||
<h3>Inhalt</h3>
|
||||
<ul>
|
||||
<li><a href="#intro">1. Einführung</a></li>
|
||||
<li><a href="#files">2. Datei-Referenz (Deep Dive)</a></li>
|
||||
<li><a href="#api">3. API-System</a></li>
|
||||
<li><a href="#database">4. Datenbank & Models</a></li>
|
||||
<li><a href="#classes">5. Helper Klassen</a></li>
|
||||
<li><a href="#generators">6. CLI-Generatoren</a></li>
|
||||
<li><a href="#best-practices">7. Best Practices</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<section id="intro">
|
||||
<h2>1. Einführung</h2>
|
||||
<p>Dieses Framework basiert auf dem <strong>Model-View-Controller (MVC)</strong> Entwurfsmuster und nutzt einen <strong>Front Controller</strong> (index.php). Alle Anfragen werden zentral verarbeitet, was globale Middleware (wie Authentifizierung) und ein einheitliches Layout ermöglicht.</p>
|
||||
</section>
|
||||
|
||||
<section id="files">
|
||||
<h2>2. Datei-Referenz (Deep Dive)</h2>
|
||||
<h3>Framework Core</h3>
|
||||
<ul>
|
||||
<li><strong>Router.php:</strong> Verwaltet die Routen. Unterstützt Middlewares. Das Dispatching erfolgt über den <code>service</code> Parameter in der URL.</li>
|
||||
<li><strong>Controller.php:</strong> Basisklasse für alle Controller. Bietet <code>render()</code> für Views und <code>json()</code> für API-Responses.</li>
|
||||
<li><strong>Model.php:</strong> Abstrakte Basis für Datenbank-Entitäten. Kapselt die <code>databaseMethods.php</code> in ein objektorientiertes Interface.</li>
|
||||
<li><strong>View.php:</strong> Behandelt das Extrahieren von Daten in HTML-Templates.</li>
|
||||
</ul>
|
||||
<h3>Konfiguration</h3>
|
||||
<ul>
|
||||
<li><strong>env.ini:</strong> Speichert Datenbank-Zugangsdaten für <code>dev</code> und <code>live</code> Umgebungen.</li>
|
||||
<li><strong>autoloader.php:</strong> Registriert einen PSR-4 ähnlichen Autoloader für den <code>MVC\</code> Namespace.</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section id="api">
|
||||
<h2>3. API-System</h2>
|
||||
<p>APIs liegen im Verzeichnis <code>WEBROOT/api/v1/</code>. Sie nutzen die <code>ApiController</code>-Klasse.</p>
|
||||
<pre>
|
||||
// Beispiel: WEBROOT/api/v1/get.php
|
||||
use MVC\Classes\Api;
|
||||
use MVC\Controller\ApiController;
|
||||
|
||||
Api::jsonResponse((new ApiController())->get());
|
||||
</pre>
|
||||
</section>
|
||||
|
||||
<section id="database">
|
||||
<h2>4. Datenbank & Models</h2>
|
||||
<p>Das Framework nutzt <code>mysqli</code> mit Prepared Statements für maximale Sicherheit.</p>
|
||||
<h3>databaseMethods.php (Die Power-Tools)</h3>
|
||||
<ul>
|
||||
<li><code>DatabaseShow($table, $columns, $where, ...$values)</code></li>
|
||||
<li><code>DatabaseInsert($table, $columns, ...$values)</code></li>
|
||||
<li><code>DatabaseUpdate($table, $set, $where, ...$values)</code></li>
|
||||
<li><code>DatabaseDelete($table, $where, ...$values)</code></li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section id="classes">
|
||||
<h2>5. Helper Klassen (MVC\Classes)</h2>
|
||||
<ul>
|
||||
<li><strong>Request:</strong> Zugriff auf <code>method()</code>, <code>queryParams()</code>, <code>headers()</code>.</li>
|
||||
<li><strong>Client:</strong> Ermittelt <code>ip()</code>, <code>userAgent()</code>, <code>country()</code>.</li>
|
||||
<li><strong>Cookie:</strong> Interface zum <code>set()</code>, <code>read()</code>, <code>Delete()</code> von Cookies.</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section id="generators">
|
||||
<h2>6. CLI-Generatoren</h2>
|
||||
<p><code>php create_module.php [Name]</code> - Erstellt Controller & View.</p>
|
||||
<p><code>php create_model.php [Tabelle] [Spalten]</code> - Erstellt ein Model.</p>
|
||||
</section>
|
||||
|
||||
<section id="best-practices">
|
||||
<h2>7. Best Practices</h2>
|
||||
<p><strong>Naming:</strong> Controller immer mit <code>Controller</code>-Suffix. Models im Singular.</p>
|
||||
<p><strong>Security:</strong> Nutze <code>['auth']</code> Middleware konsequent für alle internen Seiten.</p>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.docs-container { max-width: 1000px; color: var(--text); }
|
||||
.toc { background: var(--sidebar); padding: 20px; border-radius: 8px; margin-bottom: 30px; border: 1px solid var(--border); }
|
||||
.toc h3 { margin-top: 0; }
|
||||
section { margin-bottom: 50px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
|
||||
h2 { color: var(--accent); font-size: 1.8rem; margin-bottom: 20px; }
|
||||
pre { background: #1e1e1e; color: #d4d4d4; padding: 15px; border-radius: 5px; overflow-x: auto; border: 1px solid #333; font-size: 0.9rem; }
|
||||
</style>
|
||||
HTML;
|
||||
|
||||
$files['WEBROOT/src/MVC/View/login.php'] = <<<'HTML'
|
||||
<style>
|
||||
.login-container { max-width: 400px; margin: 50px auto; padding: 30px; border: 1px solid var(--border); border-radius: 8px; background: var(--sidebar); box-shadow: 0 4px 15px rgba(0,0,0,0.1); }
|
||||
@@ -1028,6 +1138,7 @@ try {
|
||||
// LOGIN EIN/AUSSCHALTEN: Einfach ['auth'] als 4. Parameter hinzufügen oder entfernen
|
||||
$router->add('home', \MVC\Controller\HomeController::class, 'index');
|
||||
$router->add('toggle_theme', \MVC\Controller\HomeController::class, 'toggle_theme');
|
||||
$router->add('docs', \MVC\Controller\DocsController::class, 'index');
|
||||
$router->add('test1', \MVC\Controller\TestController::class, 'service1', ['auth']);
|
||||
$router->add('test2', \MVC\Controller\TestController::class, 'service2', ['auth']);
|
||||
$router->add('login', \MVC\Controller\AuthController::class, 'login');
|
||||
@@ -1039,9 +1150,12 @@ try {
|
||||
|
||||
$headerActions = '<button class="btn-toggle" onclick="toggleTheme()">🌓 Theme umschalten</button>';
|
||||
if (isset($_SESSION['user_logged_in'])) {
|
||||
$headerActions = '<span style="margin-right: 15px; font-size: 0.9rem;">👤 ' . htmlspecialchars($_SESSION['username']) . '</span>' . '<a href="?service=logout" class="btn-toggle" style="text-decoration: none; background: rgba(255,255,255,0.2); margin-right: 10px;">🚪 Logout</a> ' . $headerActions;
|
||||
$headerActions = '<span style="margin-right: 15px; font-size: 0.9rem;">👤 ' . htmlspecialchars($_SESSION['username']) . '</span>' .
|
||||
'<a href="?service=logout" class="btn-toggle" style="text-decoration: none; background: rgba(255,255,255,0.2); margin-right: 10px;">🚪 Logout</a> ' .
|
||||
$headerActions;
|
||||
} else {
|
||||
$headerActions = '<a href="?service=login" class="btn-toggle" style="text-decoration: none; background: var(--accent); color: white; margin-right: 10px;">🔑 Login</a> ' . $headerActions;
|
||||
$headerActions = '<a href="?service=login" class="btn-toggle" style="text-decoration: none; background: var(--accent); color: white; margin-right: 10px;">🔑 Login</a> ' .
|
||||
$headerActions;
|
||||
}
|
||||
$layout->setBlock('header_actions', $headerActions);
|
||||
|
||||
@@ -1051,6 +1165,7 @@ try {
|
||||
'home' => ['label' => '🏠 Home', 'auth' => false],
|
||||
'test1' => ['label' => '🛠️ Test 1', 'auth' => true],
|
||||
'test2' => ['label' => '📊 Test 2', 'auth' => true],
|
||||
'docs' => ['label' => '📚 Dokumentation', 'auth' => false],
|
||||
];
|
||||
?>
|
||||
<nav>
|
||||
@@ -1269,5 +1384,3 @@ echo "\n✨ Projekt '$projectName' wurde initialisiert!\n";
|
||||
echo "1. Richte deine Datenbankverbindung in WEBROOT/src/config/env.ini ein.\n";
|
||||
echo "2. Starten: php server.php\n";
|
||||
echo "3. Öffnen: http://localhost:8000\n";
|
||||
echo "";
|
||||
echo "Default Login: USER:[user] - PASSWD:[user123]";
|
||||
Reference in new issue
Block a user