refactor: reorganize project structure for better maintainability
- Move 45 debug/test files from root to organized scripts/ directories - Secure public/ directory by removing debug files (security improvement) - Create structured scripts organization: • scripts/debug/ (20 files) - Framework debugging tools • scripts/test/ (18 files) - Test and validation scripts • scripts/maintenance/ (5 files) - Maintenance utilities • scripts/dev/ (2 files) - Development tools Security improvements: - Removed all debug/test files from public/ directory - Only production files remain: index.php, health.php Root directory cleanup: - Reduced from 47 to 2 PHP files in root - Only essential production files: console.php, worker.php This improves: ✅ Security (no debug code in public/) ✅ Organization (clear separation of concerns) ✅ Maintainability (easy to find and manage scripts) ✅ Professional structure (clean root directory)
This commit is contained in:
90
scripts/maintenance/compile-container.php
Normal file
90
scripts/maintenance/compile-container.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
// build-container.php
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use App\Framework\DI\DefaultContainer;
|
||||
use App\Framework\DI\ContainerCompiler;
|
||||
|
||||
// Container initialisieren
|
||||
$container = new DefaultContainer();
|
||||
|
||||
// Hier wichtige Core-Klassen registrieren
|
||||
$container->bind(\App\Framework\Http\RequestFactory::class, \App\Framework\Http\RequestFactory::class);
|
||||
// Weitere Bindungen...
|
||||
|
||||
// Liste der zu kompilierenden Services
|
||||
$services = [
|
||||
\App\Framework\Core\Application::class,
|
||||
\App\Framework\EventBus\DefaultEventBus::class,
|
||||
\App\Framework\CommandBus\DefaultCommandBus::class,
|
||||
\App\Framework\Router\HttpRouter::class,
|
||||
\App\Framework\Http\RequestFactory::class,
|
||||
// Weitere wichtige Services...
|
||||
];
|
||||
|
||||
// Services aus Verzeichnissen automatisch erkennen
|
||||
$servicesFromDiscovery = discoverServicesFromDirectories([
|
||||
__DIR__ . '/../src/Application',
|
||||
__DIR__ . '/../src/Framework',
|
||||
]);
|
||||
$services = array_merge($services, $servicesFromDiscovery);
|
||||
|
||||
// Container kompilieren
|
||||
$compiler = new ContainerCompiler();
|
||||
$compiler->compile(
|
||||
$container,
|
||||
$services,
|
||||
__DIR__ . '/../cache/CompiledContainer.php'
|
||||
);
|
||||
|
||||
echo "Container kompiliert!\n";
|
||||
|
||||
// Hilfsfunktion zum Entdecken von Services
|
||||
function discoverServicesFromDirectories(array $directories): array
|
||||
{
|
||||
$services = [];
|
||||
foreach ($directories as $directory) {
|
||||
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
|
||||
foreach ($iterator as $file) {
|
||||
if ($file->isFile() && $file->getExtension() === 'php') {
|
||||
$className = getClassNameFromFile($file->getRealPath());
|
||||
if ($className) {
|
||||
$services[] = $className;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $services;
|
||||
}
|
||||
|
||||
function getClassNameFromFile(string $file): ?string
|
||||
{
|
||||
$content = file_get_contents($file);
|
||||
$tokens = token_get_all($content);
|
||||
$namespace = '';
|
||||
$class = '';
|
||||
$namespaceFound = false;
|
||||
$classFound = false;
|
||||
|
||||
foreach ($tokens as $token) {
|
||||
if (is_array($token)) {
|
||||
if ($token[0] === T_NAMESPACE) {
|
||||
$namespaceFound = true;
|
||||
} elseif ($namespaceFound && $token[0] === T_STRING) {
|
||||
$namespace .= $token[1];
|
||||
} elseif ($namespaceFound && $token[0] === T_NS_SEPARATOR) {
|
||||
$namespace .= '\\';
|
||||
} elseif ($token[0] === T_CLASS) {
|
||||
$classFound = true;
|
||||
} elseif ($classFound && $token[0] === T_STRING) {
|
||||
$class = $token[1];
|
||||
break;
|
||||
}
|
||||
} elseif ($namespaceFound && $token === ';') {
|
||||
$namespaceFound = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $namespace && $class ? $namespace . '\\' . $class : null;
|
||||
}
|
||||
Reference in New Issue
Block a user