78 $pos = strrpos($server[
"SCRIPT_NAME"],
"/");
79 $relativePath = (($pos === FALSE) ?
"" : substr($server[
"SCRIPT_NAME"], 0, $pos));
80 $this->rootPath = $server[
"DOCUMENT_ROOT"] . $relativePath .
"/";
81 $this->rootUrl = $server[
"REQUEST_SCHEME"] .
"://" . $server[
"HTTP_HOST"] . $relativePath .
"/";
82 $this->requestUrl = substr($server[
"REQUEST_URI"], count($this->rootUrl) -1);
83 $this->context = $context;
84 $this->routes = array();
92 public function init($server)
95 if ($siteUrl != $server[
"HTTP_HOST"] && $siteUrl !== null)
97 header(
"location: http://{$siteUrl}{$server['REQUEST_URI']}");
112 $requestParams = explode(
"/", $this->requestUrl);
113 foreach ($this->routes as $i)
115 $routeParams = explode(
"/", $i[0]);
116 $p = $this->routeMatch($requestParams, $routeParams);
119 $controller = $this->createController($i[1], $p);
134 if (!class_exists($className))
138 $this->routeParams = $params;
139 $result =
new $className($this->context, $params);
158 $i = count($request);
160 if ($i != count($route))
165 if ($route[$i] ==
'' && $request[$i] ==
'')
167 if ($route[$i] ==
'' || $request[$i] ==
'')
169 if ($route[$i][0] !=
':' && ($route[$i] != $request[$i]))
171 if ($route[$i][0] ==
':')
172 $params[$route[$i]] = $request[$i];
173 $params[$i -1] = $request[$i];
175 return array_reverse($params);
184 $fetcher = new \Entity\Cms();
185 $pages = $fetcher->selects(null, array(
"order"));
186 foreach ($pages as $i)
187 $this->doRouteAdd($i->shurl, $i->controller);
196 $this->routes[] = array($route, $controller);
211 if (!$this->context->hookManager->isInHook(
"routerSetup"))
212 throw new \
Exception(
"You can only add routes from `routerSetup' hook");
213 $this->doRouteAdd($route, $controller);
223 case "rootPath":
return $this->rootPath;
break;
224 case "rootUrl":
return $this->rootUrl;
break;
225 case "modulesPath":
return $this->rootPath.
"content/modules/";
break;
226 case "modulesUrl":
return $this->rootUrl.
"content/modules/";
break;
227 case "themesPath":
return $this->rootPath.
"content/theme/";
break;
228 case "themesUrl":
return $this->rootUrl.
"content/theme/";
break;
230 throw new \Exception(
"Cannot access attribute {$key}");
static getConfig($lang=null, $key=null, $defaultValue=null)