Implement M5 service providers, M6 MVC bases, and URL extension negotiation; update docs and tests
• M5: Add ServiceProviderInterface and ProviderRepository; integrate providers into Kernel (register before container build, boot after); add RouteRegistry with clear(); add default core providers (Routing, Template, ORM, Flags, Testing) and AppServiceProvider; add contracts and default drivers (Template/Eyrie, Orm/Pairity, Flags/Flagpole, Testing/Codeception)
• Routing: allow providers to contribute routes; add ProviderRouteTest
• Config: add config/providers.php; extend config/app.php with driver keys; document env keys
• M6: Introduce MVC bases: Controller, APIController (JSON helpers), ViewController (html + renderView helpers), View (transformData + renderer); add ViewWithDefaultTemplate and default-template flow; adjust method signatures to data-first and delegate template override to View
• HTTP: Add UrlExtensionNegotiationMiddleware (opt-in via URL_EXTENSION_NEGOTIATION, whitelist via URL_EXTENSION_WHITELIST with default json|php|none); wire before ContentNegotiationMiddleware
• Tests: add UrlExtensionNegotiationTest and MvcViewTest; ensure RouteRegistry::clear prevents duplicate routes in tests
• Docs: Update README with M5 provider usage, M6 MVC examples and template selection conventions, and URL extension negotiation; mark M5 complete in MILESTONES; add M12 task to provide XML support and enable xml in whitelist by default
2025-12-15 22:08:57 +00:00
|
|
|
<?php
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Phred\Http\Routing;
|
|
|
|
|
|
|
|
|
|
use FastRoute\RouteCollector;
|
|
|
|
|
use Phred\Http\Router;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Allows providers to register route callbacks that will be applied
|
|
|
|
|
* when the FastRoute dispatcher is built.
|
|
|
|
|
*/
|
|
|
|
|
final class RouteRegistry
|
|
|
|
|
{
|
|
|
|
|
/** @var list<callable(RouteCollector, Router):void> */
|
|
|
|
|
private static array $callbacks = [];
|
|
|
|
|
|
2026-01-06 17:02:05 +00:00
|
|
|
/** @var array<string,bool> */
|
|
|
|
|
private static array $loadedFiles = [];
|
|
|
|
|
|
|
|
|
|
public static function markAsLoaded(string $filePath): void
|
|
|
|
|
{
|
|
|
|
|
self::$loadedFiles[realpath($filePath) ?: $filePath] = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function isLoaded(string $filePath): bool
|
|
|
|
|
{
|
|
|
|
|
return isset(self::$loadedFiles[realpath($filePath) ?: $filePath]);
|
|
|
|
|
}
|
|
|
|
|
|
Implement M5 service providers, M6 MVC bases, and URL extension negotiation; update docs and tests
• M5: Add ServiceProviderInterface and ProviderRepository; integrate providers into Kernel (register before container build, boot after); add RouteRegistry with clear(); add default core providers (Routing, Template, ORM, Flags, Testing) and AppServiceProvider; add contracts and default drivers (Template/Eyrie, Orm/Pairity, Flags/Flagpole, Testing/Codeception)
• Routing: allow providers to contribute routes; add ProviderRouteTest
• Config: add config/providers.php; extend config/app.php with driver keys; document env keys
• M6: Introduce MVC bases: Controller, APIController (JSON helpers), ViewController (html + renderView helpers), View (transformData + renderer); add ViewWithDefaultTemplate and default-template flow; adjust method signatures to data-first and delegate template override to View
• HTTP: Add UrlExtensionNegotiationMiddleware (opt-in via URL_EXTENSION_NEGOTIATION, whitelist via URL_EXTENSION_WHITELIST with default json|php|none); wire before ContentNegotiationMiddleware
• Tests: add UrlExtensionNegotiationTest and MvcViewTest; ensure RouteRegistry::clear prevents duplicate routes in tests
• Docs: Update README with M5 provider usage, M6 MVC examples and template selection conventions, and URL extension negotiation; mark M5 complete in MILESTONES; add M12 task to provide XML support and enable xml in whitelist by default
2025-12-15 22:08:57 +00:00
|
|
|
public static function add(callable $registrar): void
|
|
|
|
|
{
|
|
|
|
|
self::$callbacks[] = $registrar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function clear(): void
|
|
|
|
|
{
|
|
|
|
|
self::$callbacks = [];
|
2026-01-06 17:02:05 +00:00
|
|
|
self::$loadedFiles = [];
|
Implement M5 service providers, M6 MVC bases, and URL extension negotiation; update docs and tests
• M5: Add ServiceProviderInterface and ProviderRepository; integrate providers into Kernel (register before container build, boot after); add RouteRegistry with clear(); add default core providers (Routing, Template, ORM, Flags, Testing) and AppServiceProvider; add contracts and default drivers (Template/Eyrie, Orm/Pairity, Flags/Flagpole, Testing/Codeception)
• Routing: allow providers to contribute routes; add ProviderRouteTest
• Config: add config/providers.php; extend config/app.php with driver keys; document env keys
• M6: Introduce MVC bases: Controller, APIController (JSON helpers), ViewController (html + renderView helpers), View (transformData + renderer); add ViewWithDefaultTemplate and default-template flow; adjust method signatures to data-first and delegate template override to View
• HTTP: Add UrlExtensionNegotiationMiddleware (opt-in via URL_EXTENSION_NEGOTIATION, whitelist via URL_EXTENSION_WHITELIST with default json|php|none); wire before ContentNegotiationMiddleware
• Tests: add UrlExtensionNegotiationTest and MvcViewTest; ensure RouteRegistry::clear prevents duplicate routes in tests
• Docs: Update README with M5 provider usage, M6 MVC examples and template selection conventions, and URL extension negotiation; mark M5 complete in MILESTONES; add M12 task to provide XML support and enable xml in whitelist by default
2025-12-15 22:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function apply(RouteCollector $collector, Router $router): void
|
|
|
|
|
{
|
|
|
|
|
foreach (self::$callbacks as $cb) {
|
|
|
|
|
$cb($collector, $router);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|