Download the PHP package lukevear/tbone without Composer
On this page you can find all versions of the php package lukevear/tbone. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lukevear/tbone
More information about lukevear/tbone
Files in lukevear/tbone
Package tbone
Short Description An extremely fast micro PHP router
License MIT
Homepage https://github.com/lukevear/tbone
Informations about the package tbone
TBone
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})
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.
Installation
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.
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).
When an event is fired the specified callback will be run.
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();