Last active
August 29, 2015 14:01
-
-
Save anoxic/29cb16876f063f5eeb73 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
| These things: | |
| * A list of named routes readable a little like a table of contents | |
| * Specifying a handler is extra - the name is enough | |
| * Reverse routing | |
| * Simplified regex patterns allowing for strange url matching | |
| * Easy handling of errors | |
| But also this would be nice: | |
| * Guards/middleware (not sure which one) | |
| <?php | |
| map::list('/([^/]+/)'); | |
| map::view('/([^~]+)(~\d)?'); | |
| map::edit('/:(.+)'); | |
| error::not_found(404); | |
| error::unauthorized(501); | |
| class List { | |
| function get($n) {} | |
| } | |
| class View { | |
| // For use within handlers, reverse routing can be achieved with locate::[route_name] | |
| // And halting to a specific error with halt([error_code]) | |
| function get($n) { | |
| if (file_exists($n)) | |
| render('page', [ | |
| 'edit_link' => locate::edit('My Page'), | |
| 'page'=>file_get_contents($n) | |
| ]); | |
| else | |
| halt(404); | |
| } | |
| } | |
| class Edit { | |
| function post($n) {} | |
| function get($n) {} | |
| } | |
| class Error { | |
| function not_found() {} | |
| function unauthorized() {} | |
| } | |
| dispatch(); | |
| ?> | |
| Some other things that are important: | |
| * CSRF prevention | |
| * Secure session storage | |
| * "Flash" messages | |
| * Escaping HTML | |
| * Template rendering - with "block" rendering/"extends" syntax | |
| * Non-SSL TLS for transfer of passwords and other confidential information | |
| And, just a thought, what if routing was broader and also included things like request parameters. What if we broadened to looking at the whole request, not just a little chunk of it? | |
| I think just honing on the router is a false path. There is more than that, to making organized, fault-tolerant systems. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment