Router made with high performance in mind. Apache 2.0 licensed.
- No dependencies
- High performance
- Method condition support
- Domain condition support
- Routes with optional parameters
- Reverse routing
You can easily install Saffron by adding below requirement to your composer.json
{
"require": {
"krzysztof-magosa/saffron": "5.*"
}
}
Please follow to example to see how simply you can use the Saffron in your project :-)
$route->setUri('/');
$route->setUri('/contact-us');
$route->setUri('/contact-with/{name}');
$route->setUri('/contact-with/{name}/by/{method}');
$route->setDomain('www.example.com');
$route->setDomain('www.example.{tld}');
$route->setMethod('GET');
$route->setMethod(['GET', 'POST']);
// Allow only https traffic
$route->setHttps(true);
// Allow only non-https traffic
$route->setHttps(false);
// Https doesn't matter (default setting)
$route->setHttps(null);
If you want to allow only some values to be passed to placeholders, you can restrict their values using regular expressions. Saffron uses PERL compatible expressions (like in preg_match). All requirements are enclosed by ^ and $ internally by Saffron.
$route->setRequirements(
[
'name' => '\w+',
'method' => 'phone|email',
'tld' => 'com|org',
]
);
If you want some placeholder to be optional, you can set default value for it. It makes sense only for one or more placeholders on the end of uri, or one of more on the beggining of domain.
$route->setDefaults(
[
'placeholder1' => 'value1',
]
);
To run controller (using Executor) when route is matched you can set class and method in it. When you omit method it takes default value 'indexAction'
$route->setTarget('HomeController');
$route->setTarget('ContactController', 'emailAction');