Integrates nikic/fast-route with phpnomad/rest as a runtime REST router. This is the standard non-WordPress RestStrategy for PHPNomad applications. It hosts controllers defined against phpnomad/rest inside a FastRoute dispatcher, binds PHP-superglobal-backed Request and Response implementations for phpnomad/http, and dispatches routes in response to a RequestInitiated event.
The Composer package name is phpnomad/fastroute-rest-integration, even though the repository is named fastroute-integration.
composer require phpnomad/fastroute-rest-integrationRestStrategyimplementingPHPNomad\Rest\Interfaces\RestStrategy, backed bynikic/fast-route. It registers controllers as FastRoute handlers, runs any middleware declared on the controller, and runs interceptors after the response is built.RequestandResponseclasses that implement thephpnomad/httpinterfaces.Requestreads from$_SERVER,$_REQUEST, andphp://input.Responseis an in-memory status, headers, and body holder with JSON and error helpers.RestInitializer, a loader initializer that registers the bindings above and attaches aDispatchRequestlistener to theRequestInitiatedevent.
phpnomad/rest, the abstraction this integration implementsphpnomad/loader, to run the initializernikic/fast-route, pulled in automatically by Composer
Add RestInitializer to the initializer list you pass to the Bootstrapper. Once load() runs, your controllers are routed through FastRoute and dispatched when a RequestInitiated event fires.
<?php
use PHPNomad\Core\Bootstrap\CoreInitializer;
use PHPNomad\Di\Container\Container;
use PHPNomad\FastRoute\Component\RestInitializer;
use PHPNomad\Loader\Bootstrapper;
$container = new Container();
(new Bootstrapper(
$container,
new CoreInitializer(),
new RestInitializer(),
new MyAppInitializer()
))->load();MyAppInitializer is where you register your own controllers via HasControllers. See the bootstrapping guide at phpnomad.com for the full picture.
Full PHPNomad documentation lives at phpnomad.com, including the phpnomad/rest reference and the bootstrapping guide. Upstream router documentation lives at nikic/fast-route.
MIT. See LICENSE.