Download the PHP package itlessons/php-routing without Composer

On this page you can find all versions of the php package itlessons/php-routing. 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 php-routing

PHP Routing Library

Routing associates a request with the code that will convert it to a response.

The example below demonstrates how you can set up a fully working routing system:

use Routing\Router;

$host = 'http://domain.tld';

$router = new Router($host);

$router->add('home', '/', 'controller:action');
$router->add('hello', '/hello', 'static:welcome', 'GET');
$router->add('profile', '/user(id:num)', 'profile:index', 'GET|POST');

$route = $router->match('GET', '/user777');
// $route->getController() => 'static:welcome'
// $route->getParameters() => [id:777]

$url = $router->generate('profile', array('id' => 777));
// $url => /user777

$url = $router->generate('profile', array('id' => 777), true);
// $url => http://domain.tld/user777

URL Matching Only

You can use url matcher standalone:

use Routing\UrlMatcher;

$matcher = new UrlMatcher();
$matcher->register('GET', '/', 'controller:action');
$matcher->register('GET', '/hello', 'static:welcome');
$matcher->register('GET|POST', '/user(id:num)', 'profile:index');

$route = $router->match('GET', '/hello');

URL Generating Only

You can use url generator standalone:

use Routing\UrlGenerator;

$generator = new UrlGenerator('http://domain.tld');
$generator->add('home', '/');
$generator->add('hello', '/hello');
$generator->add('profile', '/user(:id)');

$url = $generator->generate('profile', array('id' => 888), true);

Optional Last Placeholder

You can specify optional placeholder in the end of pattern:

use Routing\Router;

$host = 'http://domain.tld';

$router = new Router($host);
$router->add('blog', '/blog/(page:num:?)', 'controller:action');

// match
$route = $router->match('GET', '/blog');
$route = $router->match('GET', '/blog/1');

// generate
$router->generate('blog'); => /blog
$router->generate('blog',  array('page' => 1)); => /blog/1

Similar Routes

You can use redirect on similar route (e.g /blog -> /blog/ if /blog/ exists):

use Routing\Router;

$host = 'http://domain.tld';

$router = new Router($host);
$router->add('home', '/', 'controller:action');
$router->add('hello', '/hello', 'static:welcome');
$router->add('profile', '/blog/', 'profile:index');

$route = $router->match('GET', '/hello/');
if($router->getMatcher()->isNeedRedirect()){
    // need redirect to /hello
    redirect($router->getMatcher()->getRedirectUrl(), 302);
}

$route = $router->match('GET', '/blog');
if($router->getMatcher()->isNeedRedirect()){
    // need redirect to /blog/
    redirect($router->getMatcher()->getRedirectUrl(), 302);
}

Cache Compiled Data

You can cache compiled rules to files for performance:

use Routing\Router;
use Routing\Request;

$request = new Request();

$router = new Router($request->getHTTPHost());
$router->useCache(__DIR__.'/matcher.cache.php', __DIR__.'/generator.cache.php');
$router->add('home', '/', 'controller:action');
// ...
$route = $router->match($request->getMethod(), $request->getPathInfo());

Request Class Helper

You can use simple request class to find pathInfo:

use Routing\Router;
use Routing\Request;

$request = new Request();

$router = new Router($request->getHTTPHost());

$router->add('home', '/', 'controller:action');
$router->add('hello', '/hello', 'static:welcome', 'GET');
$router->add('profile', '/user(id:num)', 'profile:index', 'GET|POST');

$route = $router->match($request->getMethod(), $request->getPathInfo());

Resources

You can run the unit tests with the following command:

$ cd path/to/php-routing/
$ composer.phar install
$ phpunit

Links


All versions of php-routing with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.3
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 itlessons/php-routing contains the following files

Loading the files please wait ....