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:
@@ -1,90 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
// Force production environment test by reading .env directly
|
||||
declare(strict_types=1);
|
||||
|
||||
// Load environment from .env file (override container env)
|
||||
$envFile = __DIR__ . '/../.env';
|
||||
if (file_exists($envFile)) {
|
||||
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
foreach ($lines as $line) {
|
||||
if (strpos($line, '#') === 0) continue;
|
||||
if (strpos($line, '=') !== false) {
|
||||
[$key, $value] = explode('=', $line, 2);
|
||||
$key = trim($key);
|
||||
$value = trim($value);
|
||||
|
||||
// Override environment
|
||||
$_ENV[$key] = $value;
|
||||
putenv("$key=$value");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$tests = [
|
||||
'environment' => [
|
||||
'app_env_file' => $_ENV['APP_ENV'] ?? 'not-set',
|
||||
'app_debug_file' => $_ENV['APP_DEBUG'] ?? 'not-set',
|
||||
'app_env_server' => $_SERVER['APP_ENV'] ?? 'not-set',
|
||||
'app_debug_server' => $_SERVER['APP_DEBUG'] ?? 'not-set',
|
||||
'status' => ($_ENV['APP_ENV'] ?? '') === 'production' && ($_ENV['APP_DEBUG'] ?? '') === 'false' ? 'PASS' : 'FAIL'
|
||||
],
|
||||
'performance_debug' => [
|
||||
'analytics_track_performance' => $_ENV['ANALYTICS_TRACK_PERFORMANCE'] ?? 'not-set',
|
||||
'status' => (strpos($_ENV['ANALYTICS_TRACK_PERFORMANCE'] ?? '', 'false') !== false) ? 'PASS' : 'FAIL'
|
||||
],
|
||||
'xdebug' => [
|
||||
'xdebug_mode' => $_ENV['XDEBUG_MODE'] ?? 'not-set',
|
||||
'status' => ($_ENV['XDEBUG_MODE'] ?? '') === 'off' ? 'PASS' : 'FAIL'
|
||||
],
|
||||
'files' => [
|
||||
'env_file_exists' => file_exists($envFile) ? 'PASS' : 'FAIL',
|
||||
'env_backup_created' => glob(__DIR__ . '/../.env.backup.*') ? 'PASS' : 'FAIL'
|
||||
]
|
||||
];
|
||||
|
||||
// Calculate overall status
|
||||
$overall_status = 'PASS';
|
||||
foreach ($tests as $category => $test) {
|
||||
if (isset($test['status']) && $test['status'] === 'FAIL') {
|
||||
$overall_status = 'FAIL';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'deployment_status' => $overall_status,
|
||||
'timestamp' => date('Y-m-d H:i:s'),
|
||||
'note' => 'Reading production config from .env file (container env vars need rebuild)',
|
||||
'tests' => $tests
|
||||
], JSON_PRETTY_PRINT);
|
||||
?>
|
||||
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
// Simple production test endpoint
|
||||
declare(strict_types=1);
|
||||
|
||||
// Load environment
|
||||
$envFile = __DIR__ . '/../.env';
|
||||
if (file_exists($envFile)) {
|
||||
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
foreach ($lines as $line) {
|
||||
if (strpos($line, '#') === 0) continue;
|
||||
if (strpos($line, '=') !== false) {
|
||||
[$key, $value] = explode('=', $line, 2);
|
||||
$_ENV[trim($key)] = trim($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'production-test',
|
||||
'app_env' => $_ENV['APP_ENV'] ?? 'not-set',
|
||||
'app_debug' => $_ENV['APP_DEBUG'] ?? 'not-set',
|
||||
'analytics_track_performance' => $_ENV['ANALYTICS_TRACK_PERFORMANCE'] ?? 'not-set',
|
||||
'xdebug_mode' => $_ENV['XDEBUG_MODE'] ?? 'not-set',
|
||||
'timestamp' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
// Security test endpoint for production deployment validation
|
||||
declare(strict_types=1);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$tests = [
|
||||
'environment' => [
|
||||
'app_env' => $_ENV['APP_ENV'] ?? 'not-set',
|
||||
'app_debug' => $_ENV['APP_DEBUG'] ?? 'not-set',
|
||||
'status' => ($_ENV['APP_ENV'] ?? '') === 'production' && ($_ENV['APP_DEBUG'] ?? '') === 'false' ? 'PASS' : 'FAIL'
|
||||
],
|
||||
'performance_debug' => [
|
||||
'analytics_track_performance' => $_ENV['ANALYTICS_TRACK_PERFORMANCE'] ?? 'not-set',
|
||||
'status' => (strpos($_ENV['ANALYTICS_TRACK_PERFORMANCE'] ?? '', 'false') !== false) ? 'PASS' : 'FAIL'
|
||||
],
|
||||
'xdebug' => [
|
||||
'xdebug_mode' => $_ENV['XDEBUG_MODE'] ?? 'not-set',
|
||||
'status' => ($_ENV['XDEBUG_MODE'] ?? '') === 'off' ? 'PASS' : 'FAIL'
|
||||
],
|
||||
'security_headers' => [
|
||||
'https_only' => isset($_SERVER['HTTPS']) ? 'PASS' : 'FAIL',
|
||||
'user_agent_required' => !empty($_SERVER['HTTP_USER_AGENT']) ? 'PASS' : 'FAIL'
|
||||
]
|
||||
];
|
||||
|
||||
// Calculate overall status
|
||||
$overall_status = 'PASS';
|
||||
foreach ($tests as $category => $test) {
|
||||
if (isset($test['status']) && $test['status'] === 'FAIL') {
|
||||
$overall_status = 'FAIL';
|
||||
break;
|
||||
}
|
||||
if (is_array($test)) {
|
||||
foreach ($test as $key => $value) {
|
||||
if ($key === 'status' || !is_string($value)) continue;
|
||||
if ($value === 'FAIL') {
|
||||
$overall_status = 'FAIL';
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'overall_status' => $overall_status,
|
||||
'timestamp' => date('Y-m-d H:i:s'),
|
||||
'tests' => $tests
|
||||
], JSON_PRETTY_PRINT);
|
||||
?>
|
||||
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
ini_set('display_errors',1);
|
||||
ini_set('display_startup_errors',1);
|
||||
error_reporting(E_ALL);
|
||||
echo 'DEBUG '.date('Y-m-d H:i:s');
|
||||
Reference in New Issue
Block a user