undertext/arouter

Annotation based router

v0.1.0 2018-09-27 14:30 UTC

This package is auto-updated.

Last update: 2020-11-19 16:11:44 UTC


README

Php annotation based router. Documentation can be found here

Requirements

PHP version >= 7.1

Installation

To install ARouter, run the command below:

composer require undertext/arouter

Quick example

// Enable annotations autolading. This is a required step.
AnnotationRegistry::registerLoader('class_exists');
// Build annotaion based router, find controllers in 'src/Controller' folder.
$router = RouterFactory::getRouter('src/Controller');
// Get response based on request.
try {
   $response = $router->getResponse(ServerRequest::fromGlobals());
} catch (RouteHandlerNotFoundException $e) {
    $response = new Response(404, [], "Route not found"); // This is an example of Guzzle HTTP Response usage.
}

outputResponse($response); // outputResponse is a function that converts response to string and outputs it.

Main documentation sections:

NOTE: Due to Doxygen parser all code examples with PHP annotations do not wrap those annotations in DocBlock comment

Build Status codecov