Download the PHP package gears/router without Composer
On this page you can find all versions of the php package gears/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package router
Short Description Laravel Router Standalone
License MIT
Homepage https://github.com/phpgearbox/router
Informations about the package router
Looking for maintainers, I no longer do much if any PHP dev, I have moved on, mostly work in dotnet core, node.js & golang these days. If anyone is keen to take over these projects, get in touch - [email protected]
The Router Gear
Laravel Router Standalone
Okay so by now hopefully you have heard of Laravel, the PHP framework that just makes things easy. So first things first full credit goes to Taylor Otwell for the Router API.
How to Install
Installation via composer is easy:
composer require gears/router:*
How to Use
In your legacy - non Laravel application. You can use the Laravel Router API like so:
The can either be a routes php file. eg: this file would look just like any routes.php file you would find in any other Laravel App.
OR
The path can be to a folder containing lots of route files. The files will be included automatically for you and added to the router. This is my prefered solution.
A little aside: In my Laravel Apps I place some code, similar to what is in this Router that loops through a routes folder inside my app dir. I place one route definition per file. I rarely use Controllers. I name each route file like search-{postcode}.GET.php which contains:
It makes for a very fast prototyping development life cycle.
An Example Route
So just like a Laravel Route, see: http://laravel.com/docs/routing Here is an example route file.
Class Alias Behind the scenes when you call we automatically create a new class alias called , this sets up the normal public API you are used to. However if the class is already in existence. We also alias ourselves to .
The 404 Error
Out of the box we have built in a simple and clean looking 404 error page. Credits go to: http://html5boilerplate.com/ Thank Guys.
However if you wish to overide the 404 content the router returns. The instalation of the router might look like:
The 404 Exception If you set the 404 parameter to a boolean value of false. Then we will simply re-throw the 404 exception, which is an instance of:
You can then deal with this yourself. An example use case might be to have multiple routers. Which then could provide a HMVC type setup.
Exit On Complete
For most setups you will probably want the execution of PHP to stop after the router has done it's thing and sent the response. However if for whatever reason you don't want this, perhaps some sort of output buffering or something. The instalation of the router might look like:
So now for the why?
While laravel is so awesomely cool and great. If you want to pull a feature out and use it in another project it can become difficult. Firstly you have to have an innate understanding of the IoC Container.
You then find that this class needs that class which then requires some other config variable that is normally present in the IoC when run inside a normal Laravel App but in your case you haven't defined it and don't really want to define that value because it makes no sense in your lets say legacy application.
Perfect example is when I tried to pull the session API out to use in wordpress. It wanted to know about a method, which I think comes from . At this point in time I already had to add various other things into the IoC to make it happy and it was the last straw that broke the camels back, I chucked a coders tantrum, walked to the fridge, grabbed another Redbull and sat back down with a new approach.
The result is this project.
Developed by Brad Jones - [email protected]