- Add comprehensive health check system with multiple endpoints - Add Prometheus metrics endpoint - Add production logging configurations (5 strategies) - Add complete deployment documentation suite: * QUICKSTART.md - 30-minute deployment guide * DEPLOYMENT_CHECKLIST.md - Printable verification checklist * DEPLOYMENT_WORKFLOW.md - Complete deployment lifecycle * PRODUCTION_DEPLOYMENT.md - Comprehensive technical reference * production-logging.md - Logging configuration guide * ANSIBLE_DEPLOYMENT.md - Infrastructure as Code automation * README.md - Navigation hub * DEPLOYMENT_SUMMARY.md - Executive summary - Add deployment scripts and automation - Add DEPLOYMENT_PLAN.md - Concrete plan for immediate deployment - Update README with production-ready features All production infrastructure is now complete and ready for deployment.
143 lines
5.9 KiB
PHP
143 lines
5.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
use App\Framework\Router\ValueObjects\Placeholder;
|
|
use App\Framework\Router\ValueObjects\RouteGroup;
|
|
use App\Framework\Router\ValueObjects\RoutePath;
|
|
|
|
echo "=== Testing Route Groups & Prefixes System ===\n\n";
|
|
|
|
echo "1. Creating API route group with prefix '/api/v1':\n";
|
|
|
|
try {
|
|
$apiGroup = RouteGroup::prefix(RoutePath::fromString('api/v1'))
|
|
->middleware('auth', 'rate-limit')
|
|
->get(RoutePath::fromString('users'), 'UserController::index', 'api.users.index')
|
|
->post(RoutePath::fromString('users'), 'UserController::store', 'api.users.store')
|
|
->get(RoutePath::fromElements('users', Placeholder::fromString('id')), 'UserController::show', 'api.users.show')
|
|
->put(RoutePath::fromElements('users', Placeholder::fromString('id')), 'UserController::update', 'api.users.update')
|
|
->delete(RoutePath::fromElements('users', Placeholder::fromString('id')), 'UserController::destroy', 'api.users.destroy')
|
|
->build();
|
|
|
|
echo " ✅ Created API group with {$apiGroup->getRouteCount()} routes\n";
|
|
echo " 📍 Prefix: {$apiGroup->getPrefix()->toString()}\n";
|
|
echo " 🔧 Middleware: " . implode(', ', $apiGroup->getMiddleware()) . "\n";
|
|
echo " 🎯 Has dynamic routes: " . ($apiGroup->hasDynamicRoutes() ? 'Yes' : 'No') . "\n\n";
|
|
|
|
echo " 📋 Compiled routes with prefix applied:\n";
|
|
foreach ($apiGroup->getCompiledRoutes() as $route) {
|
|
echo " • {$route->toString()}\n";
|
|
echo " Middleware: [" . implode(', ', $route->getMiddleware()) . "]\n";
|
|
}
|
|
echo "\n";
|
|
|
|
} catch (\Throwable $e) {
|
|
echo " ❌ Error: {$e->getMessage()}\n\n";
|
|
}
|
|
|
|
echo "2. Creating admin route group with nested groups:\n";
|
|
|
|
try {
|
|
$adminGroup = RouteGroup::prefix(RoutePath::fromString('admin'))
|
|
->middleware('admin-auth')
|
|
->get(RoutePath::fromString('dashboard'), 'AdminController::dashboard', 'admin.dashboard')
|
|
->group(RoutePath::fromString('users'), function ($group) {
|
|
$group->get(RoutePath::fromString('index'), 'AdminUserController::index', 'admin.users.index')
|
|
->post(RoutePath::fromString('create'), 'AdminUserController::store', 'admin.users.store')
|
|
->get(RoutePath::fromElements(Placeholder::fromString('id'), 'edit'), 'AdminUserController::edit', 'admin.users.edit');
|
|
})
|
|
->group(RoutePath::fromString('settings'), function ($group) {
|
|
$group->get(RoutePath::fromString('general'), 'SettingsController::general', 'admin.settings.general')
|
|
->get(RoutePath::fromString('security'), 'SettingsController::security', 'admin.settings.security');
|
|
})
|
|
->build();
|
|
|
|
echo " ✅ Created admin group with {$adminGroup->getRouteCount()} routes\n";
|
|
echo " 📍 Prefix: {$adminGroup->getPrefix()->toString()}\n\n";
|
|
|
|
echo " 📋 All compiled routes with nested prefixes:\n";
|
|
foreach ($adminGroup->getCompiledRoutes() as $route) {
|
|
echo " • {$route->toString()}\n";
|
|
}
|
|
echo "\n";
|
|
|
|
} catch (\Throwable $e) {
|
|
echo " ❌ Error: {$e->getMessage()}\n\n";
|
|
}
|
|
|
|
echo "3. Creating resource routes using helper methods:\n";
|
|
|
|
try {
|
|
$resourceGroup = RouteGroup::prefix(RoutePath::fromString('api'))
|
|
->middleware('api-auth')
|
|
->resource('posts', 'PostController')
|
|
->apiResource('comments', 'CommentController')
|
|
->build();
|
|
|
|
echo " ✅ Created resource group with {$resourceGroup->getRouteCount()} routes\n";
|
|
echo " 📍 Prefix: {$resourceGroup->getPrefix()->toString()}\n\n";
|
|
|
|
echo " 📋 RESTful routes generated:\n";
|
|
foreach ($resourceGroup->getCompiledRoutes() as $route) {
|
|
echo " • {$route->toString()}\n";
|
|
}
|
|
echo "\n";
|
|
|
|
} catch (\Throwable $e) {
|
|
echo " ❌ Error: {$e->getMessage()}\n\n";
|
|
}
|
|
|
|
echo "4. Testing route group methods and utilities:\n";
|
|
|
|
try {
|
|
$testGroup = RouteGroup::prefix(RoutePath::fromString('test'))
|
|
->get(RoutePath::fromString('static'), 'TestController::static')
|
|
->get(RoutePath::fromElements('dynamic', Placeholder::fromString('param')), 'TestController::dynamic')
|
|
->build();
|
|
|
|
echo " ✅ Created test group\n";
|
|
echo " 🔢 Route count: {$testGroup->getRouteCount()}\n";
|
|
echo " 🎯 Has dynamic routes: " . ($testGroup->hasDynamicRoutes() ? 'Yes' : 'No') . "\n";
|
|
echo " 📝 Group summary: {$testGroup->toString()}\n\n";
|
|
|
|
foreach ($testGroup->getRoutes() as $route) {
|
|
echo " 📊 Route details:\n";
|
|
echo " Path: {$route->getPath()->toString()}\n";
|
|
echo " Method: {$route->getMethod()->value}\n";
|
|
echo " Handler: {$route->getHandler()}\n";
|
|
echo " Dynamic: " . ($route->isDynamic() ? 'Yes' : 'No') . "\n";
|
|
if ($route->isDynamic()) {
|
|
echo " Parameters: " . implode(', ', $route->getParameterNames()) . "\n";
|
|
echo " Regex: {$route->toRegex()}\n";
|
|
}
|
|
echo "\n";
|
|
}
|
|
|
|
} catch (\Throwable $e) {
|
|
echo " ❌ Error: {$e->getMessage()}\n\n";
|
|
}
|
|
|
|
echo "5. Testing middleware inheritance and combination:\n";
|
|
|
|
try {
|
|
$middlewareGroup = RouteGroup::prefix(RoutePath::fromString('secure'))
|
|
->middleware('global-middleware', 'auth-middleware')
|
|
->get(RoutePath::fromString('profile'), 'ProfileController::show')
|
|
->build()
|
|
->withMiddleware(['additional-middleware']);
|
|
|
|
$compiledRoute = $middlewareGroup->getCompiledRoutes()[0];
|
|
echo " ✅ Created middleware test group\n";
|
|
echo " 🔧 Group middleware: [" . implode(', ', $middlewareGroup->getMiddleware()) . "]\n";
|
|
echo " 🔧 Route middleware: [" . implode(', ', $compiledRoute->getMiddleware()) . "]\n";
|
|
echo " 📍 Final route: {$compiledRoute->toString()}\n\n";
|
|
|
|
} catch (\Throwable $e) {
|
|
echo " ❌ Error: {$e->getMessage()}\n\n";
|
|
}
|
|
|
|
echo "=== Route Groups & Prefixes Test Completed ===\n";
|