Download the PHP package jetfirephp/routing without Composer
On this page you can find all versions of the php package jetfirephp/routing. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jetfirephp/routing
More information about jetfirephp/routing
Files in jetfirephp/routing
Package routing
Short Description JetFire - Routing
License MIT
Informations about the package routing
JetFire PHP Routing
A simple & powerful router for PHP 5.4+
Features
V1.3
- Support subdomain
- Support group resolver
V1.2
- ClosureTemplate resolver
- ControllerTemplate resolver
- Possibility to choose a resolver
V1.1
- Support dependency injection container
- Add your custom matcher and dispatcher
V1.0
- Support static & dynamic route patterns
- Support REST routing
- Support reversed routing using named routes
- Uri matcher
- Array matcher
- Closure resolver
- Template resolver
- Controller resolver
- Route Middleware
- Integration with other libraries
Getting started
- PHP 5.4+ is required
- Install
JetFire\Routing
using Composer - Setup URL rewriting so that all requests are handled by index.php
Installation
Via composer
.htaccess
Usage
Create an instance of JetFire\Routing\RouteCollection
and define your routes. Then create an instance of JetFire\Routing\Router
and run your routes.
Matcher
JetFire\Routing
provide 2 type of matcher for your routes : JetFire\Routing\Matcher\ArrayMatcher
and JetFire\Routing\Matcher\UriMatcher
Uri Matcher
With Uri Matcher you don't have to define your routes. Depending on the uri it can check if a target exist for the current url. But you have to define your views directory path and controllers namespace to the collection :
For example if the uri is : /home/index
Resolver
Here are the list of Uri Matcher resolver :
Template resolver
Uri Matcher check if an index.php
file exist in /_VIEW_DIR_PATH_/Home
directory.
If you want to check for other extension (html,json,...) You can configure the router like this :
Controller resolver
With Controller resolver, Uri Matcher checks if a controller with name HomeController
located in the namespace _CONTROLLERS_NAMESPACE_
has the index
method.
You have to require your controller before matching or you can use your custom autoloader to load your controllers.
Uri Matcher support also dynamic routes. For example if the uri is : /home/user/peter/parker
then you must have a method user
with two parameters like this :
Array Matcher
With Array Matcher you have to add your routes like this :
We recommend that you define your routes in a separate file and pass the path to addRoutes()
method.
Resolver
Here are the list of Uri Matcher resolver :
You have 5 actions possible for Array Routing. We assume you are using a separate file for your routes.
Template resolver
Controller resolver
Controller and Template resolver
Controller group resolver
Closure resolver
Closure and Template resolver
Block Routes
With JetFire\Routing
you have the ability to create block routes to better organize your code.
For example , if you have an administration for your website , you can create block only for this section and another block to the public part like this :
Router Configuration
Here are the list of router configuration that you can edit :
Collection Options
Here are the list of options that you can edit for each collection routes :
Named Routes
You can specify a name for each route like this :
And then to get the url of this route you can do like this :
Supported only in JetFire\Routing\Matcher\ArrayMatcher
.
REST Routing
You can specify the request method for each route like this :
Prefix
You can set a prefix for each routes collection like this :
Or :
Middleware
Middlewares are called before and after a route match the current uri. You have to create a middleware config file like this :
Then you have to instantiate the middleware class Middleware
like this :
Let see how to create your Middleware Class. For example we take the Global middleware :
See the API section to learn how to handle your $route in middleware class.
Custom Matcher and Dispatcher
If the default matcher and dispatcher doesn't match your expectation, you can write your own matcher and dispatcher like this :
You can also override the default matcher like this :
Integration with other libraries
If you want to integrate other template engine libraries like twig, smarty ... you have to set the 'templateCallback' in router.
Subdomain
Or if you want to add a subdomain for a bloc, you have to add this line in your route collection options :
API
Below is a list of the public methods and variables in the common classes you will most likely use.
License
The JetFire Routing is released under the MIT public license : http://www.opensource.org/licenses/MIT.