- Move 12 markdown files from root to docs/ subdirectories - Organize documentation by category: • docs/troubleshooting/ (1 file) - Technical troubleshooting guides • docs/deployment/ (4 files) - Deployment and security documentation • docs/guides/ (3 files) - Feature-specific guides • docs/planning/ (4 files) - Planning and improvement proposals Root directory cleanup: - Reduced from 16 to 4 markdown files in root - Only essential project files remain: • CLAUDE.md (AI instructions) • README.md (Main project readme) • CLEANUP_PLAN.md (Current cleanup plan) • SRC_STRUCTURE_IMPROVEMENTS.md (Structure improvements) This improves: ✅ Documentation discoverability ✅ Logical organization by purpose ✅ Clean root directory ✅ Better maintainability
109 lines
3.8 KiB
PHP
109 lines
3.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
use App\Framework\Core\RouteCompiler;
|
|
use App\Framework\Discovery\ValueObjects\DiscoveredAttribute;
|
|
use App\Framework\Core\ValueObjects\ClassName;
|
|
use App\Framework\Core\ValueObjects\MethodName;
|
|
use App\Framework\Attributes\Route;
|
|
use App\Framework\Http\Method;
|
|
use App\Framework\Router\HttpRouter;
|
|
use App\Framework\Http\HttpRequest;
|
|
|
|
echo "=== Multi-Parameter Route Testing ===" . PHP_EOL . PHP_EOL;
|
|
|
|
// Test 1: Route Compilation with Multiple Parameters
|
|
echo "Test 1: Kompiliere Route mit mehreren Parametern" . PHP_EOL;
|
|
|
|
$discoveredRoute = new DiscoveredAttribute(
|
|
attributeClass: Route::class,
|
|
className: ClassName::create('TestController'),
|
|
methodName: MethodName::create('handleCampaign'),
|
|
arguments: [
|
|
'path' => '/campaign/{slug}/presave/{platform}',
|
|
'method' => Method::GET
|
|
],
|
|
additionalData: [
|
|
'parameters' => [
|
|
['name' => 'slug', 'type' => 'string', 'isBuiltin' => true, 'hasDefault' => false],
|
|
['name' => 'platform', 'type' => 'string', 'isBuiltin' => true, 'hasDefault' => false]
|
|
]
|
|
]
|
|
);
|
|
|
|
$compiler = new RouteCompiler();
|
|
$compiled = $compiler->compile($discoveredRoute);
|
|
|
|
echo "Compiled Routes: " . print_r(array_keys($compiled), true) . PHP_EOL;
|
|
|
|
if (isset($compiled['GET']['default']['dynamic'][0])) {
|
|
$route = $compiled['GET']['default']['dynamic'][0];
|
|
echo "✅ Route erfolgreich kompiliert" . PHP_EOL;
|
|
echo " Path: " . $route->path . PHP_EOL;
|
|
echo " Regex: " . $route->regex . PHP_EOL;
|
|
echo " Param Names: " . print_r($route->paramNames, true) . PHP_EOL;
|
|
|
|
// Test 2: Regex Matching
|
|
echo PHP_EOL . "Test 2: Teste Regex Matching" . PHP_EOL;
|
|
$testPath = '/campaign/test-campaign/presave/spotify';
|
|
|
|
if (preg_match($route->regex, $testPath, $matches)) {
|
|
echo "✅ Path matched Regex!" . PHP_EOL;
|
|
echo " Matches: " . print_r($matches, true) . PHP_EOL;
|
|
|
|
// Extract parameter values
|
|
$paramValues = [];
|
|
foreach ($route->paramNames as $index => $paramName) {
|
|
// Parameter values start at index 1 (index 0 is full match)
|
|
$paramValues[$paramName] = $matches[$index + 1] ?? null;
|
|
}
|
|
|
|
echo " Extracted Parameters: " . print_r($paramValues, true) . PHP_EOL;
|
|
|
|
if ($paramValues['slug'] === 'test-campaign' && $paramValues['platform'] === 'spotify') {
|
|
echo "✅ Parameter extraction korrekt!" . PHP_EOL;
|
|
} else {
|
|
echo "❌ Parameter extraction fehlgeschlagen" . PHP_EOL;
|
|
}
|
|
} else {
|
|
echo "❌ Path matched NICHT!" . PHP_EOL;
|
|
echo " Expected Pattern: " . $route->regex . PHP_EOL;
|
|
echo " Test Path: " . $testPath . PHP_EOL;
|
|
}
|
|
} else {
|
|
echo "❌ Keine dynamic Route gefunden" . PHP_EOL;
|
|
}
|
|
|
|
// Test 3: Full Router Integration Test
|
|
echo PHP_EOL . "Test 3: Full HttpRouter Integration" . PHP_EOL;
|
|
|
|
$compiledRoutes = $compiler->compileOptimized($discoveredRoute);
|
|
$router = new HttpRouter($compiledRoutes);
|
|
|
|
$request = new HttpRequest(
|
|
method: Method::GET,
|
|
path: '/campaign/test-campaign/presave/spotify'
|
|
);
|
|
|
|
$context = $router->match($request);
|
|
|
|
if ($context->isSuccess()) {
|
|
echo "✅ Router matched route successfully!" . PHP_EOL;
|
|
echo " Matched Route Path: " . $context->match->route->path . PHP_EOL;
|
|
|
|
if ($context->match->route instanceof \App\Framework\Core\DynamicRoute) {
|
|
echo " Route Type: Dynamic" . PHP_EOL;
|
|
echo " Param Values: " . print_r($context->match->route->paramValues, true) . PHP_EOL;
|
|
}
|
|
} else {
|
|
echo "❌ Router konnte Route NICHT matchen" . PHP_EOL;
|
|
echo " Path: " . $context->path . PHP_EOL;
|
|
}
|
|
|
|
echo PHP_EOL . "=== Test Summary ===" . PHP_EOL;
|
|
echo "Routes mit mehreren Parametern funktionieren grundsätzlich: ";
|
|
echo ($context->isSuccess() ? "✅ JA" : "❌ NEIN") . PHP_EOL;
|