bulldog/router

v0.1.0 2018-08-11 20:25 UTC

This package is auto-updated.

Last update: 2024-04-05 17:11:39 UTC


README

Build Status Coverage Status

A simple PHP router that utilizes nikic/FastRoute.

Installation

composer require bulldog/router

Usage

<?php

use Bulldog\Router;
use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\ServerRequestFactory;

// You'll usually use the line below, but to demonstrate, we will create our own request.
// $request = ServerRequestFactory::fromGlobals();
$request = new ServerRequest([], [], '/', 'GET');

$router = new Router;
$router->addRoute('get', '/', 'callable');
$router->run($request);

echo $router->handler();
// callable

var_dump($router->vars());
// array(0) {
// }

With Array Parameters

<?php

use Bulldog\Router;
use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\ServerRequestFactory;

// You'll usually use the line below, but to demonstrate, we will create our own request.
// $request = ServerRequestFactory::fromGlobals();
$request = new ServerRequest([], [], '/user/1', 'GET');

$router = new Router;
$router->addRoute('get', '/user/{id}', 'callable');
$router->run($request);

echo $router->handler();
// callable

var_dump($router->vars());
// array(1) {
//   'id' =>
//   string(1) "1"
// }

Contributing

All contributions welcome! Please first create an issue if something is wrong and let us know if you intend to fix it. Then fork the repo, create a new branch, and work on the issue. The branch name should be relevant to the issue.

Style

Run php-cs-fixer with the default rules.

php-cs-fixer fix ./src