Last active
August 29, 2015 13:59
-
-
Save anoxic/10578037 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Features: | |
| * Named routes | |
| * Reverse routing (to get the URL for a named route) | |
| * Multiple patterns | |
| * Guards | |
| * Separate HTTP Verb/Method checking | |
| * Error handling / Halting | |
| Helpers: | |
| * CSRF prevention | |
| * Flash session variables | |
| * Escaping | |
| * Template rendering | |
| <?php | |
| # routing (via any method) | |
| map::edit('/:lang/edit/:page', function($lang, $pagename) {}); | |
| map::list_users('/:lang/users', function($lang) {}); | |
| # -- or | |
| map::edit('/:lang/edit/:page'); | |
| class Edit { | |
| function __construct($l,$p) { | |
| page::exist($p); | |
| auth(); | |
| } | |
| function post($lang,$page) {} | |
| } | |
| # -- or | |
| map::edit('/:lang/edit/:page')->guards(['Page::exist','page'], ['auth']); | |
| map::edit('/:lang/edit/:page')->when(function($p){Page::exit($p);}); | |
| # multiple routes | |
| map::view('/:lang/view/:page', '/:lang/view/:page~:version'); | |
| # middleware | |
| map::before(['edit','delete','view'], function() { | |
| }); | |
| # get the route for a page | |
| locate::edit('en', 'My Page'); #-> '/en/edit/my-page' | |
| locate::list_users('en'); #-> '/en/users' | |
| # checking request method | |
| if (verb('get')); | |
| if (verb('post')); | |
| # route an error | |
| map::error(404, function($message = null){}); | |
| map::error('database', function($message = null){}); | |
| # halt, getting handled by a mapped handled, or the default | |
| halt(404, 'My Page'); | |
| halt('database'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment