/** * @param Request $appRequest * @param Url $refUrl * @return null|string */ public function constructUrl(Request $appRequest, Url $refUrl) { // one way can't generate link if ($this->options['oneWay']) { return NULL; } $params = $this->clearParameters($appRequest->getParameters()); $action = new Action($appRequest->getPresenterName() . ':' . $appRequest->getParameter('action'), $params); // ISource return NULL, not found url to generate if (($seoUrl = $this->source->toUrl($action)) === NULL) { return NULL; } if (!$seoUrl instanceof Url) { $seoUrl = new Url($seoUrl); } // host if ($seoUrl->getHost()) { $host = $refUrl->getHost(); $parts = ip2long($host) ? [$host] : array_reverse(explode('.', $host)); $host = strtr($seoUrl->getHost(), ['%tld%' => $parts[0], '%domain%' => isset($parts[1]) ? "{$parts['1']}.{$parts['0']}" : $parts[0], '%sld%' => isset($parts[1]) ? $parts[1] : '', '%host%' => $refUrl->getHost()]); } else { $host = $refUrl->getHost(); } // path $path = $seoUrl->getPath(); // query $query = $seoUrl->getQueryParameters() + $params; ksort($query); $seoUrl->setQuery($query); $query = $seoUrl->getQuery(); // fragment $fragment = $seoUrl->getFragment(); return ($this->options['secured'] ? 'https' : 'http') . '://' . $host . $refUrl->getBasePath() . ($path === '/' ? '' : $path) . ($query ? '?' . $query : '') . ($fragment ? '#' . $fragment : ''); }