84 $pos = strrpos($server[
"SCRIPT_NAME"],
"/");
85 $relativePath = (($pos === FALSE) ?
"" : substr($server[
"SCRIPT_NAME"], 0, $pos));
86 $this->rootPath = $server[
"DOCUMENT_ROOT"] . $relativePath .
"/";
87 $this->rootUrl = $server[
"REQUEST_SCHEME"] .
"://" . $server[
"HTTP_HOST"] . $relativePath .
"/";
88 $this->requestUrl = substr($server[
"REQUEST_URI"], count($this->rootUrl) -1);
89 $this->context = $context;
90 $this->routes = array();
91 $this->overridden = null;
99 public function init($server)
104 if ($siteUrl != $server[
"HTTP_HOST"] && $siteUrl !== null)
106 header(
"location: http://{$siteUrl}{$server['REQUEST_URI']}");
121 $requestParams = explode(
"/", $this->requestUrl);
122 foreach ($this->routes as $i)
124 $routeParams = explode(
"/", $i[0]);
125 $p = $this->routeMatch($requestParams, $routeParams);
128 $controller = $this->createController($i[1], $p);
143 if (!class_exists($className))
145 $this->routeParams = $params;
149 $result =
new $className($this->context, $params);
168 $i = count($request);
170 if ($i != count($route))
175 if ($route[$i] ==
'' && $request[$i] ==
'')
177 if ($route[$i] ==
'' || $request[$i] ==
'')
179 if ($route[$i][0] !=
':' && ($route[$i] != $request[$i]))
181 if ($route[$i][0] ==
':')
182 $params[$route[$i]] = $request[$i];
183 $params[$i -1] = $request[$i];
185 return array_reverse($params);
194 $fetcher = new \Entity\Cms();
195 $pages = $fetcher->selects(null, array(
"order"));
196 foreach ($pages as $i)
197 $this->doRouteAdd($i->shurl, $i->controller);
206 $this->routes[] = array($route, $controller);
221 if (!$this->context->hookManager->isInHook(
"routerSetup"))
222 throw new \
Exception(
"You can only add routes from `routerSetup' hook");
223 $this->doRouteAdd($route, $controller);
236 if (!$this->context->isTestingEnvironment())
238 $this->overridden[$type] = $value;
247 if (isset($this->overridden) && in_array($key, array(
"modulesPath")))
248 return $this->overridden[$key];
251 case "rootPath":
return $this->rootPath;
break;
252 case "rootUrl":
return $this->rootUrl;
break;
253 case "modulesPath":
return $this->rootPath.
"content/modules/";
break;
254 case "modulesUrl":
return $this->rootUrl.
"content/modules/";
break;
255 case "themesPath":
return $this->rootPath.
"content/theme/";
break;
256 case "themesUrl":
return $this->rootUrl.
"content/theme/";
break;
258 throw new \Exception(
"Cannot access attribute {$key}");
static getConfig($lang=null, $key=null, $defaultValue=null)