project-a/silex-routing

Silex-Routing provides advanced routing for Silex through connecting symfony-cmf/Routing with Silex.

Installs: 1 028

Dependents: 0

Stars: 7

Watchers: 6

Forks: 1

Language: PHP

v1.0.6 2014-12-10 11:11 UTC

README

Serviceprovider for advanced and dynamic routing in Silex

Latest Stable Version Total Downloads License Build Status Coverage Status SensioLabsInsight

Description

Silex-Routing allows you to define custom and multiple routers for Silex. This is especially useful when working with dynamic routes, which are not known while writing the code (e.g. URLs stored in database).

This implementation works for both, matching and generating of URLs.

The advanced routing is achieved by connecting Silex with symfony-cmf/Routing.

Installation

The recommended way to install Silex-Routing is through composer. Just create a composer.json file and run the php composer.phar install command to install it:

{
    "require": {
        "project-a/silex-routing": "~1.0"
    }
}

Alternatively, you can download the silexrouting.zip file and extract it.

Usage

Using Silex-Routing is very simple. All you need to do is register the provided RoutingServiceProvider and afterwards add all your custom routers (RouterInterface).

$app = new Silex\Application();

$app->register(new SilexRouting\Provider\RoutingServiceProvider());

$router = new SilexRouting\SilexRouter($app); // e.g. The default Silex router

$app['routers']->add($router);
$app['routers']->add($router2);
...

If you want to use url generation simple register the UrlGeneratorServiceProvider from this package and use generation as before.

$app->register(new SilexRouting\Provider\UrlGeneratorServiceProvider());

Do not use the Silex\Provider\UrlGeneratorServiceProvider together with Silex-Routing. Your custom routers will not be used!

Tests

To run the test suite, you need composer.

$ php composer.phar install --dev
$ phpunit

License

Silex-Routing is licensed under the MIT license.