project-a / silex-routing
Silex-Routing provides advanced routing for Silex through connecting symfony-cmf/Routing with Silex.
Installs: 1 518
Dependents: 0
Suggesters: 0
Security: 0
Stars: 11
Watchers: 4
Forks: 1
Open Issues: 0
Requires
- php: >=5.5.9
- silex/silex: ^2.0
- symfony-cmf/routing: ^1.0|^2.0
- symfony/routing: ^2.8|^3.0
Requires (Dev)
- phpunit/phpunit: ^5.0
README
Serviceprovider for advanced and dynamic routing in Silex
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": "dev-master"
}
}
Alternatively, you can download the silexrouting.zip
file and extract it.
Upgrade from 1.0 to 2.0
Version 2 is not backward compatible with version 1. Make sure to carefully read the changelog.
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 \ChiliLabs\Silex\Provider\RoutingServiceProvider()); $router2 = new \Acme\Silex\MySpecialRouter(); $app['routers']->add($router); ...
There is a router in this repository named SilexRouter
, that handles the
default routing behavior of Silex. Registering this router ensures, that all
routes added through the main Silex application still work. (This router is not
registered by default.)
Since version 2.0 of project-a/silex-routing the url generation is included in the RoutingServiceProvider
and
no special UrlGeneratorServiceProvider
is needed anymore.
Tests
To run the test suite, you need composer.
$ php composer.phar install --dev
$ phpunit
License
Silex-Routing is licensed under the MIT license.