Skip to content

phpnomad/fastroute-integration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

phpnomad/fastroute-rest-integration

Latest Version Total Downloads PHP Version License

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.

Installation

The Composer package name is phpnomad/fastroute-rest-integration, even though the repository is named fastroute-integration.

composer require phpnomad/fastroute-rest-integration

What This Provides

  • RestStrategy implementing PHPNomad\Rest\Interfaces\RestStrategy, backed by nikic/fast-route. It registers controllers as FastRoute handlers, runs any middleware declared on the controller, and runs interceptors after the response is built.
  • Request and Response classes that implement the phpnomad/http interfaces. Request reads from $_SERVER, $_REQUEST, and php://input. Response is an in-memory status, headers, and body holder with JSON and error helpers.
  • RestInitializer, a loader initializer that registers the bindings above and attaches a DispatchRequest listener to the RequestInitiated event.

Requirements

Usage

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.

Documentation

Full PHPNomad documentation lives at phpnomad.com, including the phpnomad/rest reference and the bootstrapping guide. Upstream router documentation lives at nikic/fast-route.

License

MIT. See LICENSE.

About

FastRoute integration providing a REST routing strategy for PHPNomad applications

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages