dev-master
9999999-dev https://github.com/jongpak/prob-routerA simple http request router library
MIT
The Requires
The Development Requires
url dispatcher router path dispatch
A simple http request router library
A simple http request router library, (*1)
url.mapping.php, (*3)
<?php use Prob\Router\Map; $map = new Map(); $map->setNamespace('app\\controller'); $map->get('/', function ($url) { echo 'Hello main!'; }); $map->get('/test', 'Test.hello'); $map->get('/post/{post:int}', 'Post.view'); return $map;
app/controller/Test.php, (*4)
<?php namespace app\controller; class Test { public function hello() { echo 'Test page!'; } }
app/controller/Post.php, (*5)
<?php namespace app\controller; class Post { public function hello($req) { echo 'Post ID: ' . $req['post']; } }
index.php, (*6)
<?php use Prob\Router\Dispatcher; use Prob\Rewrite\Request; // use zend-diactoros package (for PSR-7) use Zend\Diactoros\Request; use Zend\Diactoros\Uri; $dispatcher = new Dispatcher(require 'url.mapping.php');
// print 'Hello main' $dispatcher->dispatch( (new Request()) ->withUri(new Uri('http://test.com/')) ->withMethod('GET') );
// print 'Test page!' $dispatcher->dispatch( (new Request()) ->withUri(new Uri('http://test.com/test')) ->withMethod('GET') );
// print 'Post ID: 5' $dispatcher->dispatch( (new Request()) ->withUri(new Uri('http://test.com/post/5')) ->withMethod('GET') );
A simple http request router library
MIT
url dispatcher router path dispatch