10 defined(
'JPATH_PLATFORM') or die;
26 protected $maps = array();
38 public function addMap($pattern, $controller)
41 $pattern = explode(
'/', trim(parse_url((
string) $pattern, PHP_URL_PATH),
' /'));
50 foreach ($pattern as $segment)
58 elseif ($segment[0] ==
'*')
60 $vars[] = substr($segment, 1);
64 elseif ($segment[0] ==
'\\' && $segment[1] ==
'*')
66 $regex[] =
'\*' . preg_quote(substr($segment, 2));
69 elseif ($segment ==
':')
74 elseif ($segment[0] ==
':')
76 $vars[] = substr($segment, 1);
80 elseif ($segment[0] ==
'\\' && $segment[1] ==
':')
82 $regex[] = preg_quote(substr($segment, 1));
87 $regex[] = preg_quote($segment);
91 $this->maps[] = array(
92 'regex' => chr(1) .
'^' . implode(
'/', $regex) .
'$' . chr(1),
94 'controller' => (
string) $controller
109 public function addMaps($maps)
111 foreach ($maps as $pattern => $controller)
113 $this->addMap($pattern, $controller);
129 protected function parseRoute($route)
134 $route = preg_replace(
'/([^?]*).*/u',
'\1', $route);
137 $route = trim(parse_url($route, PHP_URL_PATH),
' /');
142 return $this->default;
146 foreach ($this->maps as $rule)
148 if (preg_match($rule[
'regex'], $route, $matches))
151 $controller = $rule[
'controller'];
155 foreach ($rule[
'vars'] as $i => $var)
157 $this->input->def($var, $matches[$i + 1]);
160 $this->input->get->def($var, $matches[$i + 1]);
163 $this->input->def(
'_rawRoute', $route);
172 throw new InvalidArgumentException(sprintf(
'Unable to handle request for route `%s`.', $route), 404);