Download the PHP package slabphp/router without Composer

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

SlabPHP Router

This router library will take specially crafted XML files, build a routing table, and determine if a route can be matched to the current REQUEST_URI parameters.

This router probably pales in comparison to many other modern open source routers. We're well aware XML is in many cases frowned upon. This library was written many years ago. Please see the main SlabPHP documentation for more information about this and all SlabPHP libraries.

Router Setup and Usage

First import the library

composer require slabphp/router

Then configure and instantiate your router.

$configuration = new \Slab\Router\Configuration();

$configuration
    ->setConfigurationPaths('/framework/configs','/site/configs'])
    ->addRouteFile('default.xml');

$router = new \Slab\Router($configuration);

Next write your route files and resolve some routes!

$router->determineSelectedRoute();
$route = $router->getSelectedRoute();

Based on the values of $_SERVER['REQUEST_URI'] and the routes in /framework/configs/default.xml and /site/configs/default.xml, you will either get false (a 404 condition) or a \Slab\Router\Route object.

Route Creation

Static Routes

Depending on how you configure the router, a route file may be anywhere. But here is an example of a route file:

<?xml version="1.0" encoding="UTF-8" ?>
<routes>
    <route>
        <path>/</path>
        <name>Homepage</name>
        <class>\Namespace\Path\To\Your\Controller</class>
        <parameters>
            <someRouteParameter><![CDATA[This could be anything really. Maybe a page title?]]></testValue>
        </parameters>
    </route>
</routes>

Dynamic Routes (Pattern Validation)

You can also have dynamic routes that use pattern validators. For example:

<route>
    <path>/something</path>
    <name>A Dynamic URL Path</name>
    <class>\Some\Controller</class>
    <pattern>/value/{string:someVar}/thing/{numeric:intVar}</pattern>
    <parameters>
        <testValue>1</testValue>
        <testString>string</testString>
    </parameters>
</route>

This would match a URL that comes in looking like /something/value/my-first-string/thing/32 Notice the {string:someVar} and {numeric:intVar}. These are mechanisms that tell the SlabPHP router to use a specific validator class and the variable name to store it in. You can create your own custom validators and simply specify their entire classname. For example, a blog post may have something like this:

<route>
    <name>Blog URL</name>
    <class>\Some\Controller</class>
    <path>/</path>
    <pattern>/{numeric:year}}/{numeric:month}/{\My\Blog\Router\Validators\PostSlug:postSlug}</pattern>
    <parameters>
        <testValue>1</testValue>
        <testString>string</testString>
    </parameters>
</route>

As long as \My\Blog\Router\Validators\PostSlug implements the correct interface, and returns true/false, you can fail this route if the post slug is wrong.

There are some built-in validators but many are application specific.


All versions of router with dependencies

PHP Build Version
Package Version
Requires slabphp/component-interfaces Version ^0.2
psr/log Version ^1.0
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 slabphp/router contains the following files

Loading the files please wait ....