Download the PHP package packfire/router without Composer

On this page you can find all versions of the php package packfire/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package router

Packfire Router

Build Status

Fast & clean URL router for PHP 5.3+.

Installing

Use Composer to install "packfire/router": "1.0.*".

  1. Download composer.phar
  2. Add "packfire/router": "1.0.*" under the "require" configuration in composer.json.
  3. Run php composer.phar install to install Packfire Router.

Loading Routes from Config

Simply load your routes from any configuration format you like:

use Packfire\Router\FileLoader;

$loader = new FileLoader('config/routes.yml'); // loading from a YAML file
$loader = new FileLoader('config/routes.json'); // loading from a JSON file
$loader = new FileLoader('config/routes.php'); // or loading from a PHP file that returns an array of configuration

// create the Router object using the configuration
$router = $loader->load();

A sample configuration looks like this (in YAML):

routes:
  home:
    path: /
    method: get
    action: HeartCode\Blog\Controller::index
  post:
    path: /post/:id-:title
    method: get
    params:
      id: i
      title: slug
    action: HeartCode\Blog\Controller:view

Routing Requests

Routing requests is simple:

use Packfire\Router\FileLoader;
use Packfire\Router\CurrentRequest;

$loader = new FileLoader('config/routes.yml');
$router = $loader->load();

// load data from $_SERVER
$request = new CurrentRequest();

// Get the route based on the current request
$route = $router->route($request);

With the $route object in hand, you can easily execute the $route by simply running the callback:

// performs the action that the route needs to
$route->callback();

Generating URLs from Routes

You can perform reverse engineering by putting the route and parameters to form its full working URL:

use Packfire\Router\FileLoader;    

$loader = new FileLoader('config/routes.yml');
$router = $loader->load();

$url = $router->generate('post', array('id' => 412, 'title' => 'maybe-this-works'));

$url will probably equals to /post/412-maybe-this-works


All versions of router with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
packfire/config Version 1.2.*
packfire/fuelblade Version 1.2.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package packfire/router contains the following files

Loading the files please wait ....