2017 © Pedro Peláez
 

package tbone

An extremely fast micro PHP router

image

lukevear/tbone

An extremely fast micro PHP router

  • Thursday, November 24, 2016
  • by lukevear
  • Repository
  • 1 Watchers
  • 0 Stars
  • 17 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

TBone

Latest Stable Version Build Status Coverage Status License, (*1)

A very simple, very fast PHP router.

  • Exceptionally easy to use
  • Supports OPTIONS, HEAD, GET, POST, PUT, PATCH and DELETE requests
  • Simple event system for error handling

Note: TBone does not support route parameters (such as /customers/{id}), (*2)

When to use TBone

TBone is designed to be used in in very simple, relatively static PHP applications where your application logic can sit within a set of closures. If you try to use TBone for anything beyond simple sites, you're going to have a bad time. If you're after something more impressive I would suggest nikic/FastRoute., (*3)

Installation

composer require lukevear/tbone

Activating the router

You may use TBone wherever you feel is appropiate in your project, however the most common usage would be in an index.php file in your document directory. If running from an index.php file, you should have a .htaccess file similar to the one below., (*4)

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Basic Example

use TBone\TBone;

$router = new TBone;

// Add a GET route
$router->get('/', function() {
    echo 'Welcome to my homepage';
});

// Add a POST route
$router->post('/contact-us', function() {
    echo 'Thanks for your submission';
});

// Run the router
$router->dispatch();

Event System

TBone's event system exists to provide a mechanism for you to handle routing related events. TBone supports ROUTE_DISPATCH_REQUESTED (fired when dispatch() is called), ROUTE_NOT_FOUND (fired when a route cannot be matched) and ROUTE_DISPATCHED (fired when a route is matched and the callback has been run)., (*5)

When an event is fired the specified callback will be run., (*6)

use TBone\TBone;
use TBone\TBoneEvent;

$router = new TBone;

// Add a GET route
$router->get('/', function() {
    echo 'Welcome to my homepage';
});

// Register our 404 page
$router->addHandler(TBoneEvent::ROUTE_NOT_FOUND, function() {
    http_response_code(404);
    echo 'Sorry, that page doesn\'t exist!';
});

// Run the router
$router->dispatch();

The Versions

24/11 2016

dev-master

9999999-dev https://github.com/lukevear/tbone

An extremely fast micro PHP router

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

route routing router

20/01 2016

2.0.3

2.0.3.0 https://github.com/lukevear/tbone

An extremely fast micro PHP router

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

route routing router

20/01 2016

2.0.2

2.0.2.0 https://github.com/lukevear/tbone

An extremely fast micro PHP router

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

route routing router

20/01 2016

2.0.1

2.0.1.0 https://github.com/lukevear/tbone

An extremely fast micro PHP router

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

route routing router

20/01 2016

2.0.0

2.0.0.0 https://github.com/lukevear/tbone

An extremely fast micro PHP router

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

route routing router

18/12 2015

1.0.2

1.0.2.0 https://github.com/lukevear/tbone

An extremely fast micro PHP router

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

route routing router

18/12 2015

1.0.1

1.0.1.0 https://github.com/lukevear/tbone

An extremely fast micro PHP router

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

route routing router

17/12 2015

1.0.0

1.0.0.0 https://github.com/lukevear/tbone

An extremely fast micro PHP router

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

route routing router