public function match($uri) { if (parent::match($uri)) { if (!strstr($this->newUrl, ':')) { $redirectUri = $this->newUrl; } else { $uriArr = explode('/', $uri); $newUrlArr = explode('/', $this->newUrl); foreach ($newUrlArr as $key => $item) { if (strstr($item, ':')) { $newUrlArr[$key] = $uriArr[$key]; } } $redirectUri = implode('/', $newUrlArr); } throw new RedirectException(OW_URL_HOME . $redirectUri); } }
public function getDispatchAttrs() { $attrs = parent::getDispatchAttrs(); $str = urldecode($attrs[OW_Route::DISPATCH_ATTRS_VARLIST][$this->pathProperty]); /* @var $slug OASEO_BOL_Slug */ $slug = $this->seoService->getSlugForString($this->entityType, $str); if ($slug === null) { $rnSlug = $this->seoService->findActiveSlugForInactiveOne($this->entityType, $str); if ($rnSlug !== null) { $generatedUri = ''; foreach ($this->pathArray as $value) { if (mb_substr($value, 0, 1) !== ':') { $generatedUri .= $value . '/'; } else { $varName = mb_substr($value, 1); $generatedUri .= urlencode($varName == $this->pathProperty ? $rnSlug->getString() : $attrs[OW_Route::DISPATCH_ATTRS_VARLIST][$varName]) . '/'; } } throw new RedirectException(OW_URL_HOME . mb_substr($generatedUri, 0, -1)); } else { if (is_numeric($str)) { $slug = $this->seoService->findActiveSlugForEntityItem($this->entityType, $str); if ($slug !== null) { $key = array_search(':' . $this->pathProperty, $this->pathArray); if ($key) { $pathArray = explode('/', OW::getRequest()->getRequestUri()); $pathArray[$key] = $slug->getString(); $redirectUri = implode('/', $pathArray); OW::getApplication()->redirect(OW_URL_HOME . $redirectUri); } } } } } if ($slug !== null) { $attrs[OW_Route::DISPATCH_ATTRS_VARLIST][$this->pathProperty] = $slug->getEntityId(); if (!$this->slugChecked) { $this->seoService->checkEntityUpdate($this->entityType, $slug->getEntityId(), $this->serviceCallback, $this->dtoProperty); $this->slugChecked = true; } } return $attrs; }
/** * Adds route object to router. * All routes should by added before routing process starts. * If route with provided name exists exception will be thrown. * * @throws LogicException * @param OW_RouteAbstract $route * @return OW_Router */ public function addRoute(OW_Route $route) { $routeName = $route->getRouteName(); if (isset($this->staticRoutes[$routeName]) || isset($this->routes[$routeName])) { //throw new LogicException( "Can't add route! Route `" . $routeName . "` already exists!"); trigger_error("Can't add route! Route `" . $routeName . "` already added!", E_USER_WARNING); } else { if ($route->isStatic()) { $this->staticRoutes[$routeName] = $route; } else { $this->routes[$routeName] = $route; } } return $this; }