Download the PHP package primal/routing without Composer

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

Primal Routing

Created and Copyright 2013 by Jarvis Badgley, chiper at chipersoft dot com.

Primal Routing is a Clean URL routing class for PHP 5.3 and later, built on four principles:

  1. Every route is a file
  2. The forward-slash is a segment delimiter, not a hierarchy
  3. The route that matches the most segments wins.
  4. Any segment can have a paired value

Route Matching

Lets take the following URL as an example:

http://localhost/alpha/beta/charley/delta

The above request is parsed into a list of arguments. Primal Routing then works backwards, scanning your routes folder for the first file that matches the segments list (delimiting the file names with periods). In this case it will scan for the following files in order:

  1. alpha.beta.charley.delta.php
  2. alpha.beta.charley.php
  3. alpha.beta.php
  4. alpha.php
  5. _catchall.php
  6. _notfound.php

Note that the last two routes can be changed using the ->setNotFound() and ->setCatchAll() functions.

The first match that it finds will be executed. If no routes are found which match the request url then it will look for a catchall route before finally invoking a File Not Found route (if no _notfound handler exists, it will throw an exception).

Route Arguments

All segments which are not part of the route name are passed to the route when it is called, indexed by their order. So if the above url matched to alpha.beta.php, the route would received the following arguments array:

Array
(
    [0] => charley
    [1] => delta
)

Now lets look at principle #4, every segment can have a paired value. Examine the following url:

http://localhost/alpha=1/beta=foo/charley=0/delta=/echo

This url will still match to the same route, but the paired segments will be available as parameters:

Array
(
    [alpha] => 1
    [beta] => foo
    [charley] => 0
    [delta] =>
)

Note, the enableEmptyArgumentInclusion() option will cause all segments to be included as parameters, with empty segments being null.

Site Index

The url / or http://my.domain.com/ is interpreted by Primal Routing as a call to the site index. Primal Routing will attempt to route to "index" (call setSiteIndex() to change this value) before passing to the file not found route ("_notfound"). The site index cannot receive arguments unless the url begins with the site index name. Example:

http://my.domain.com/index/foo=bar

Demo

If you have Composer and PHP 5.4 installed you can see Primal Routing in action by running the following from inside the repo root:

composer dump-autoload
php -S localhost:8000 demo.php

This will create a temporary server on your computer. Try the following urls:

Running Tests

You must have Composer and PHPUnit installed to run the unit tests. Run the following from inside the repo root:

composer dump-autoload
phpunit

Server Forwarding

In a standard configuration, Apache and Nginx will only call the file containing the Primal Routing code if you directly access it. The following configurations expect that index.php contains the Primal Routing initialization code.

Apache

Place the following into the virtualhost Directory definition, or into a .htaccess file at the root of your website.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ index.php    [L]

# forward all requests to /
RewriteRule ^$ index.php [L]

# send all other requests to index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteRule ^/?.*$ index.php [L]
</IfModule>

Note that Apache must be configured with mod_rewrite for this to work.

Nginx

Place the following into the virtualhost server block.

location = / {
    rewrite ^ /index.php last;
}

location / {
    if (!-e $request_filename) {
        rewrite ^ /index.php last;
    }
}

Note that this configuration assumes that you have PHP configured through a FastCGI interface in the traditional method. It may also be necessary to add the following to your PHP location directive:

try_files $uri $uri/ $uri/index.php /index.php;

License

Primal Routing is released under an MIT license. No attribution is required. For details see the enclosed LICENSE file.


All versions of routing with dependencies

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

Loading the files please wait ....