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:
2025-10-05 10:59:15 +02:00
parent 03e5188644
commit 887847dde6
77 changed files with 3902 additions and 787 deletions

View File

@@ -0,0 +1,170 @@
<?php
require_once __DIR__ . '/vendor/autoload.php';
// Test with real category structure like CommandGroupRegistry
use App\Framework\Console\Components\TuiState;
use App\Framework\Console\Components\TuiInputHandler;
use App\Framework\Console\Components\TuiCommandExecutor;
use App\Framework\Console\CommandHistory;
use App\Framework\Console\TuiView;
use App\Framework\Console\TuiKeyCode;
echo "Testing Real Navigation with CommandGroupRegistry Structure...\n";
echo "============================================================\n\n";
try {
// Create mock executor
$mockExecutor = new class implements \App\Framework\Console\Components\TuiCommandExecutor {
public function executeSelectedCommand(object $command): void {
echo "Mock: Execute command\n";
}
public function executeCommand(string $commandName): void {
echo "Mock: Execute command: $commandName\n";
}
public function validateSelectedCommand(object $command): void {
echo "Mock: Validate command\n";
}
public function validateCommand(string $commandName): void {
echo "Mock: Validate command: $commandName\n";
}
public function showSelectedCommandHelp(object $command): void {
echo "Mock: Show help\n";
}
public function showCommandHelp(string $commandName): void {
echo "Mock: Show help: $commandName\n";
}
public function showAllCommandsHelp(): void {
echo "Mock: Show all commands help\n";
}
public function startInteractiveForm(object $command, \App\Framework\Console\Components\TuiState $state): void {
echo "Mock: Start form\n";
}
public function findCommandObject(string $commandName): ?object {
return null;
}
};
$state = new TuiState();
$history = new CommandHistory();
$inputHandler = new TuiInputHandler($mockExecutor);
// Simulate the EXACT structure from CommandGroupRegistry::getOrganizedCommands()
// After uasort by priority and array_values conversion
$organizedCategories = [
'Testing' => [
'name' => 'Testing',
'description' => '',
'icon' => '🧪',
'priority' => 0,
'commands' => []
],
'Demo' => [
'name' => 'Demo',
'description' => '',
'icon' => '🎮',
'priority' => 0,
'commands' => []
],
'Generator' => [
'name' => 'Generator',
'description' => '',
'icon' => '⚙️',
'priority' => 0,
'commands' => []
],
'General' => [
'name' => 'General',
'description' => '',
'icon' => '📂',
'priority' => 0,
'commands' => []
]
];
// Sort by priority (all have priority 0 in this case, so order by keys)
uasort($organizedCategories, fn($a, $b) => $b['priority'] <=> $a['priority']);
echo "📊 Before array_values() conversion (associative array):\n";
foreach ($organizedCategories as $key => $category) {
echo " Key: '$key' => Category: '{$category['name']}'\n";
}
echo "\n";
// Convert to numeric array like our fix
$numericCategories = array_values($organizedCategories);
echo "📊 After array_values() conversion (numeric array):\n";
foreach ($numericCategories as $index => $category) {
echo " Index: $index => Category: '{$category['name']}'\n";
}
echo "\n";
// Test with the numeric array structure
$state->setCategories($numericCategories);
$state->setCurrentView(TuiView::CATEGORIES);
$state->setRunning(true);
echo "✓ Setup Complete:\n";
echo " Categories Count: " . count($numericCategories) . "\n";
echo " Current View: " . $state->getCurrentView()->name . "\n";
echo " Selected Category Index: " . $state->getSelectedCategory() . "\n";
$currentCategory = $state->getCurrentCategory();
if ($currentCategory) {
echo " Current Category Name: '{$currentCategory['name']}'\n";
} else {
echo " ❌ Current Category: NULL (This would cause navigation issues!)\n";
}
echo "\n";
// Test navigation with the real structure
echo "🔍 Testing Navigation with Real Structure:\n\n";
// Test 1: Arrow Down
echo "Test 1: Arrow DOWN\n";
$beforeCategory = $state->getCurrentCategory();
$beforeIndex = $state->getSelectedCategory();
echo " Before: Index $beforeIndex => '{$beforeCategory['name']}'\n";
$inputHandler->handleInput(TuiKeyCode::ARROW_DOWN->value, $state, $history);
$afterCategory = $state->getCurrentCategory();
$afterIndex = $state->getSelectedCategory();
echo " After: Index $afterIndex => '{$afterCategory['name']}'\n";
echo " ✓ Navigation worked: " . ($beforeIndex !== $afterIndex ? "YES" : "NO") . "\n\n";
// Test 2: Arrow Down again
echo "Test 2: Arrow DOWN again\n";
$beforeCategory = $state->getCurrentCategory();
$beforeIndex = $state->getSelectedCategory();
echo " Before: Index $beforeIndex => '{$beforeCategory['name']}'\n";
$inputHandler->handleInput(TuiKeyCode::ARROW_DOWN->value, $state, $history);
$afterCategory = $state->getCurrentCategory();
$afterIndex = $state->getSelectedCategory();
echo " After: Index $afterIndex => '{$afterCategory['name']}'\n";
echo " ✓ Navigation worked: " . ($beforeIndex !== $afterIndex ? "YES" : "NO") . "\n\n";
// Test 3: Arrow Up
echo "Test 3: Arrow UP\n";
$beforeCategory = $state->getCurrentCategory();
$beforeIndex = $state->getSelectedCategory();
echo " Before: Index $beforeIndex => '{$beforeCategory['name']}'\n";
$inputHandler->handleInput(TuiKeyCode::ARROW_UP->value, $state, $history);
$afterCategory = $state->getCurrentCategory();
$afterIndex = $state->getSelectedCategory();
echo " After: Index $afterIndex => '{$afterCategory['name']}'\n";
echo " ✓ Navigation worked: " . ($beforeIndex !== $afterIndex ? "YES" : "NO") . "\n\n";
echo "✅ Real Navigation Test COMPLETED\n";
} catch (\Throwable $e) {
echo "\n❌ Real Navigation Test FAILED:\n";
echo "Error: " . $e->getMessage() . "\n";
echo "File: " . $e->getFile() . ":" . $e->getLine() . "\n";
echo "\nStack trace:\n" . $e->getTraceAsString() . "\n";
}