2017 © Pedro Peláez
 

library trail

A small routing library written

image

symphlion/trail

A small routing library written

  • Wednesday, April 12, 2017
  • by Symphlion
  • Repository
  • 1 Watchers
  • 0 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

To use it

first, time to require the packages ofcourse.., (*1)

    composer require symphlion/trail

Somewhere in your code, make sure to autoload it all, (*2)

require '../vendor/autoload.php';

And after that, you can start using it., (*3)

``` php, (*4)

use \Trail\Router;, (*5)

Router::get('/account/:id', function( $id ) {, (*6)

echo 'The ID is ' . $id;

});, (*7)

// After defining your routes, we need to call 1 method to bootrstrap the checking Router::verify();, (*8)

// to retrieve the instance, simply call it $router = Router::instance();, (*9)

$router->get( '/events/birthday/:selection', '{namespace}@allBirthdays', [':selection' => '[a-zA-Z-]{1,3}'] );, (*10)

// you can specify both a name and a group for a route, (*11)

$router->get( '/users/:id', function( $selection ) { echo 'This is your selection!'; }, ['name' => 'user-overview'] // this gives this route the name: user-overview );, (*12)

// A different way to name a route: $router->get( '/users/:id', function( $selection ) { echo 'This is your selection!'; } )->name('user-overview');, (*13)

// we also support collections // In fact, we encourage collections, as it narrows down the search paths to follow // hence making it faster to react and match a route, (*14)

$collections = [ [ 'name' => 'account', 'namespace' => '\App\Account', 'prefix' => true, 'scheme' => 'http', 'domain' => 'www.your-domain.com' ] ];, (*15)

// optionally, you can also specify the entire routing array within a collection // like so, (*16)

$collections = [ [ 'name' => 'account', // required, every collection needs a name right? however, you can also specify the key of this array as the name 'path' => '/accounts', // required, the scoped path to listen for 'namespace' => '\App\Account', // optional but highly recommended 'prefix' => true, // optional, whether you want methods to be prefixed by the request_method 'scheme' => 'http', // optional, liten to a specific host scheme 'domain' => 'www.your-domain.com', // optional, listen to a specific domain 'routes' => [ [ ['get', 'post', 'put'], '/:id' // notice how a route within a collection will scope to the /accounts path from it`s parent collection ] ] ] ];, (*17)

The Versions

12/04 2017

dev-master

9999999-dev https://github.com/Symphlion/Trail

A small routing library written

  Sources   Download

MIT

The Requires

  • php ~5.4|~7.0

 

php routing