2017 © Pedro PelĂĄez
 

library router

WOK Router component

image

wok/router

WOK Router component

  • Thursday, March 30, 2017
  • by graphidev
  • Repository
  • 1 Watchers
  • 0 Stars
  • 35 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 14 Versions
  • 3 % Grown

The README.md

Router

This library provides a leightweight router based on regular expressions., (*1)

SensioLabsInsight, (*2)

Diclaimer : This component is part of the WOK (Web Operational Kit) framework. It however can be used as a standalone library., (*3)

Install

It is recommanded to install that component as a dependency using Composer :, (*4)

composer require wok/router

You're also free to get it with git or by direct download while this package has no dependencies., (*5)

git clone https://github.com/web-operational-kit/router.git

Features

As any other router, these features are available :, (*6)

  • Routing with a method and a URI (see the usage section)
  • Route Parameters replacing and matching
  • Manipulating routes definition afterwards
  • Retrieving routes meta data independently
  • Routes collection manipulation

Note : Some features will not be implemented for now because of the wish of simplicity (and independance) of that library., (*7)

This is why the dispatcher does not execute any function. It only returns the first matching route with the information that would be needed., (*8)

Make your own opinion :), (*9)

Basic usage

``` php use \WOK\Router\Route; use \WOK\Router\Collection;, (*10)

// First instanciate a collection $collection = new Collection();, (*11)

$collection = new Collection(); $collection->addRoute( new Route( ['POST', 'GET', 'HEAD'],// Define the accepted HTTP methods '/path/to/the/{resource}', // Define the route URI [ // Define the URI parameters 'resource' => '[a-z0-9-]+' ] ), 'Controller::action', // Define the target (function name, class, object, array, Closure, ...) 'Controller->Action' // Define the route name );, (*12)

// Define many other routes ..., (*13)

// Retrieve the first matching route try {, (*14)

$route = $collection->match('GET', '/path/to/the/resource-file-name');

}, (*15)

// No route match the current request catch(\DomainException $e) {, (*16)

$route = (object) array(
    'name'          => 'Controller->pageNotFound',
    'action'        => ['Controller', 'pageNotFound'],
    'parameters'    => []
);

}, (*17)

// Play with the route value call_user_func_array($route->action, $route->parameters); ```, (*18)

Warning: To prevent any borring returned value the Collection::match throws a DomainException if no route is found., (*19)

That way, feel free to define any not found behavior, (*20)

The Versions

30/03 2017

dev-master

9999999-dev

WOK Router component

  Sources   Download

MIT

The Requires

 

by SĂ©bastien ALEXANDRE

30/03 2017

v0.4.1

0.4.1.0

WOK Router component

  Sources   Download

MIT

The Requires

 

by SĂ©bastien ALEXANDRE

30/03 2017

dev-develop

dev-develop

WOK Router component

  Sources   Download

MIT

The Requires

 

by SĂ©bastien ALEXANDRE

01/03 2017

v0.4.0

0.4.0.0

WOK Router component

  Sources   Download

MIT

The Requires

 

by SĂ©bastien ALEXANDRE

05/01 2017

v0.3.6

0.3.6.0

WOK Router component

  Sources   Download

MIT

The Requires

 

by SĂ©bastien ALEXANDRE

29/12 2016

v0.3.5

0.3.5.0

WOK Router component

  Sources   Download

MIT

The Requires

 

by SĂ©bastien ALEXANDRE

28/11 2016

v0.3.4

0.3.4.0

WOK Router component

  Sources   Download

MIT

The Requires

 

by SĂ©bastien ALEXANDRE

28/11 2016

v0.3.3

0.3.3.0

WOK Router component

  Sources   Download

MIT

The Requires

 

by SĂ©bastien ALEXANDRE

25/11 2016

v0.3.2

0.3.2.0

WOK Router component

  Sources   Download

MIT

The Requires

 

by SĂ©bastien ALEXANDRE

25/11 2016

v0.3.1

0.3.1.0

WOK Router component

  Sources   Download

MIT

The Requires

 

by SĂ©bastien ALEXANDRE

23/11 2016

v0.3.0

0.3.0.0

WOK Router component

  Sources   Download

MIT

The Requires

 

by SĂ©bastien ALEXANDRE

14/11 2016

v0.2.1

0.2.1.0

WOK Router component

  Sources   Download

MIT

The Requires

 

by SĂ©bastien ALEXANDRE

10/11 2016

v0.2.0

0.2.0.0

WOK Router component

  Sources   Download

MIT

The Requires

 

by SĂ©bastien ALEXANDRE

09/09 2016

v0.1.1

0.1.1.0

WOK Router component

  Sources   Download

MIT

The Requires

 

by SĂ©bastien ALEXANDRE