https://github.com/lemmon/router
Lightweight standalone routing library for PHP
https://github.com/lemmon/router
Last synced: 11 months ago
JSON representation
Lightweight standalone routing library for PHP
- Host: GitHub
- URL: https://github.com/lemmon/router
- Owner: lemmon
- License: other
- Created: 2016-02-14T10:38:55.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-04-26T18:42:02.000Z (about 10 years ago)
- Last Synced: 2025-02-13T00:44:10.686Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Lemmon Router
**Lemmon Router** is a lightweight standalone routing library for PHP 7.
* Flexible regular expression routing
* Simple and lightweight
* RESTful routing
* Fast (100k requests/second)
* Mod_Rewrite is not required, although supported; extreme portability for rapid development
## Getting started
1. PHP 7.x is required
2. Install Lemmon Router using [Composer](#composer-installation) (recommended) or manually
## Composer Installation
1. Get [Composer](http://getcomposer.org/)
2. Require Lemmon Router with `php composer.phar require lemmon/router`
3. Add the following to your application's main PHP file: `require 'vendor/autoload.php';`
## Examples
```php
match('hello-world', function() {
echo 'Hello World!';
});
$r->dispatch();
```
*Example 1* - Respond to all requests
```php
$r->match(function() {
# matches everything
});
```
*Example 2* - Match parameters
```php
$r->match('{controller}/{action}', function($r) {
# $r->controller;
# $r->action;
});
```
*Example 3* - RESTful routing
```php
$r->match(['GET', 'PUT'], '{controller}(/(?{action:read|write}/{id:num:1,3=1})!)', ['controller' => '\w+'], function($r) {
# matches only GET and PUT requests
# matches either 'controller' or 'controller/action/id' when route conditions are met
# controller can be any word
# action is either read or write
# id must be numeric of length 1 to 3, default is 1
});
```