Add README.md
This commit is contained in:
commit
1474bdcd3a
1 changed files with 31 additions and 0 deletions
31
README.md
Normal file
31
README.md
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
R2
|
||||||
|
================
|
||||||
|
|
||||||
|
libr2 is a DFA URI router library. It compiles your route paths into DFA state
|
||||||
|
table, and you may dispatch the URL based on the transition table in C.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Use case in PHP
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
```php
|
||||||
|
// Here is the paths data structure
|
||||||
|
$paths = [
|
||||||
|
'/blog/post/:id' => [ 'controller' => 'PostController', 'action' => 'item', 'method' => 'GET' ],
|
||||||
|
'/blog/post' => [ 'controller' => 'PostController', 'action' => 'list', 'method' => 'GET' ],
|
||||||
|
'/blog/post' => [ 'controller' => 'PostController', 'action' => 'create', 'method' => 'POST' ],
|
||||||
|
'/blog' => [ 'controller' => 'BlogController', 'action' => 'list', 'method' => 'GET' ],
|
||||||
|
];
|
||||||
|
$rs = r2_compile($paths, 'persisten-table-id');
|
||||||
|
$ret = r2_dispatch($rs, '/blog/post/3' );
|
||||||
|
list($complete, $route, $variables) = $ret;
|
||||||
|
|
||||||
|
list($error, $message) = r2_validate($route); // validate route conditions
|
||||||
|
if ( $error ) {
|
||||||
|
echo $message; // "Method not allowed", "...";
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
Loading…
Reference in a new issue