- 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
141 lines
3.5 KiB
PHP
141 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Router;
|
|
|
|
use App\Framework\Attributes\Singleton;
|
|
|
|
/**
|
|
* Type-safe route helper for generating URLs with specific route enums
|
|
*/
|
|
#[Singleton]
|
|
final readonly class RouteHelper
|
|
{
|
|
public function __construct(
|
|
private UrlGenerator $urlGenerator
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Generate URL for web routes
|
|
*
|
|
* @param array<string, mixed> $params
|
|
*/
|
|
public function web(WebRoutes $route, array $params = [], bool $absolute = false): string
|
|
{
|
|
return $this->urlGenerator->route($route, $params, $absolute);
|
|
}
|
|
|
|
/**
|
|
* Generate URL for API routes
|
|
*
|
|
* @param array<string, mixed> $params
|
|
*/
|
|
public function api(ApiRoutes $route, array $params = [], bool $absolute = false): string
|
|
{
|
|
return $this->urlGenerator->route($route, $params, $absolute);
|
|
}
|
|
|
|
/**
|
|
* Generate URL for admin routes
|
|
*
|
|
* @param array<string, mixed> $params
|
|
*/
|
|
public function admin(AdminRoutes $route, array $params = [], bool $absolute = false): string
|
|
{
|
|
return $this->urlGenerator->route($route, $params, $absolute);
|
|
}
|
|
|
|
/**
|
|
* Generate URL for health routes
|
|
*
|
|
* @param array<string, mixed> $params
|
|
*/
|
|
public function health(HealthRoutes $route, array $params = [], bool $absolute = false): string
|
|
{
|
|
return $this->urlGenerator->route($route, $params, $absolute);
|
|
}
|
|
|
|
/**
|
|
* Generate URL for media routes
|
|
*
|
|
* @param array<string, mixed> $params
|
|
*/
|
|
public function media(MediaRoutes $route, array $params = [], bool $absolute = false): string
|
|
{
|
|
return $this->urlGenerator->route($route, $params, $absolute);
|
|
}
|
|
|
|
/**
|
|
* Generate URL for any route implementing RouteNameInterface
|
|
*
|
|
* @param array<string, mixed> $params
|
|
*/
|
|
public function any(RouteNameInterface $route, array $params = [], bool $absolute = false): string
|
|
{
|
|
return $this->urlGenerator->route($route, $params, $absolute);
|
|
}
|
|
|
|
/**
|
|
* Generate absolute URL for web routes
|
|
*
|
|
* @param array<string, mixed> $params
|
|
*/
|
|
public function absoluteWeb(WebRoutes $route, array $params = []): string
|
|
{
|
|
return $this->web($route, $params, true);
|
|
}
|
|
|
|
/**
|
|
* Generate absolute URL for API routes
|
|
*
|
|
* @param array<string, mixed> $params
|
|
*/
|
|
public function absoluteApi(ApiRoutes $route, array $params = []): string
|
|
{
|
|
return $this->api($route, $params, true);
|
|
}
|
|
|
|
/**
|
|
* Generate absolute URL for admin routes
|
|
*
|
|
* @param array<string, mixed> $params
|
|
*/
|
|
public function absoluteAdmin(AdminRoutes $route, array $params = []): string
|
|
{
|
|
return $this->admin($route, $params, true);
|
|
}
|
|
|
|
/**
|
|
* Check if current route matches given web route
|
|
*/
|
|
public function isCurrentWeb(WebRoutes $route): bool
|
|
{
|
|
return $this->urlGenerator->isCurrentRoute($route);
|
|
}
|
|
|
|
/**
|
|
* Check if current route matches given API route
|
|
*/
|
|
public function isCurrentApi(ApiRoutes $route): bool
|
|
{
|
|
return $this->urlGenerator->isCurrentRoute($route);
|
|
}
|
|
|
|
/**
|
|
* Check if current route matches given admin route
|
|
*/
|
|
public function isCurrentAdmin(AdminRoutes $route): bool
|
|
{
|
|
return $this->urlGenerator->isCurrentRoute($route);
|
|
}
|
|
|
|
/**
|
|
* Check if current route matches any route
|
|
*/
|
|
public function isCurrent(RouteNameInterface $route): bool
|
|
{
|
|
return $this->urlGenerator->isCurrentRoute($route);
|
|
}
|
|
} |