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']}");
122 $requestParams = explode(
"/", $this->requestUrl);
123 foreach ($this->routes as $i)
125 $routeParams = explode(
"/", $i[0]);
126 $p = $this->routeMatch($requestParams, $routeParams);
129 $controller = $this->createController($i[1], $p);
144 if (!class_exists($className))
146 $this->routeParams = $params;
150 $result =
new $className($this->context, $params);
169 $i = count($request);
171 if ($i != count($route))
176 if ($route[$i] ==
'' && $request[$i] ==
'')
178 if ($route[$i] ==
'' || $request[$i] ==
'')
180 if ($route[$i][0] !=
':' && ($route[$i] != $request[$i]))
182 if ($route[$i][0] ==
':')
183 $params[$route[$i]] = $request[$i];
184 $params[$i -1] = $request[$i];
186 return array_reverse($params);
195 $fetcher = new \Entity\Cms();
196 $pages = $fetcher->selects(null, array(
"order"));
197 foreach ($pages as $i)
198 $this->doRouteAdd($i->shurl, $i->controller);
207 $this->routes[] = array($route, $controller);
222 if (!$this->context->hookManager->isInHook(
"routerSetup"))
223 throw new \
Exception(
"You can only add routes from `routerSetup' hook");
224 $this->doRouteAdd($route, $controller);
237 if (!$this->context->isTestingEnvironment())
239 $this->overridden[$type] = $value;
248 if (isset($this->overridden) && in_array($key, array(
"modulesPath")))
249 return $this->overridden[$key];
252 case "rootPath":
return $this->rootPath;
break;
253 case "rootUrl":
return $this->rootUrl;
break;
254 case "modulesPath":
return $this->rootPath.
"content/modules/";
break;
255 case "modulesUrl":
return $this->rootUrl.
"content/modules/";
break;
256 case "themesPath":
return $this->rootPath.
"content/theme/";
break;
257 case "themesUrl":
return $this->rootUrl.
"content/theme/";
break;
259 throw new \Exception(
"Cannot access attribute {$key}");
static getConfig($lang=null, $key=null, $defaultValue=null)