Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Route implements IRoute,IRouter {
- private $class = 'Index';
- private $method = 'defaultAction';
- function getControllerId() {
- return $this->getMapClass();
- }
- function getActionId() {
- return $this->getMapMethod();
- }
- function getMapClass() {
- if ( $this->class === null ) {
- throw new Exception('Class not defined');
- }
- return $this->class;
- }
- function getMapMethod() {
- return $this->method;
- }
- function matchMap($path) {
- $this->class = 'Index';
- $this->method = 'defaultAction';
- list($path) = explode('?', $path);
- $path = preg_replace('#^/+#', '', $path);
- $path = preg_replace('#/+$#', '', $path);
- $toks = explode('/', $path);
- if ( $toks[0] ) {
- $this->class = $toks[0];
- }
- if ( sizeof($toks) > 1 && $toks[1] ) {
- $this->method = $toks[1];
- }
- return true;
- }
- function getRoute($request) {
- $route = new self();
- $route->matchMap($request);
- return $route;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement