Creates a URL according to the given route and parameters.
public function createUrl($manager, $route, $params)
{
if ($this->mode === self::PARSING_ONLY) {
$this->createStatus = self::CREATE_STATUS_PARSING_ONLY;
return false;
}
$tr = [];
if ($route !== $this->route) {
if ($this->_routeRule !== null && preg_match($this->_routeRule, $route, $matches)) {
$matches = $this->substitutePlaceholderNames($matches);
foreach ($this->_routeParams as $name => $token) {
if (isset($this->defaults[$name]) && strcmp($this->defaults[$name], $matches[$name]) === 0) {
$tr[$token] = '';
} else {
$tr[$token] = $matches[$name];
}
}
} else {
$this->createStatus = self::CREATE_STATUS_ROUTE_MISMATCH;
return false;
}
}
foreach ($this->defaults as $name => $value) {
if (isset($this->_routeParams[$name])) {
continue;
}
if (!isset($params[$name])) {
if (in_array($name, $this->placeholders) && strcmp($value, '') === 0) {
$params[$name] = '';
} else {
$this->createStatus = self::CREATE_STATUS_PARAMS_MISMATCH;
return false;
}
}
if (strcmp($params[$name], $value) === 0) {
unset($params[$name]);
if (isset($this->_paramRules[$name])) {
$tr["<$name>"] = '';
}
} elseif (!isset($this->_paramRules[$name])) {
$this->createStatus = self::CREATE_STATUS_PARAMS_MISMATCH;
return false;
}
}
foreach ($this->_paramRules as $name => $rule) {
if (isset($params[$name]) && !is_array($params[$name]) && ($rule === '' || preg_match($rule, $params[$name]))) {
$tr["<$name>"] = $this->encodeParams ? urlencode($params[$name]) : $params[$name];
unset($params[$name]);
} elseif (!isset($this->defaults[$name]) || isset($params[$name])) {
$this->createStatus = self::CREATE_STATUS_PARAMS_MISMATCH;
return false;
}
}
$url = $this->trimSlashes(strtr($this->_template, $tr));
if ($this->host !== null) {
$pos = strpos($url, '/', 8);
if ($pos !== false) {
$url = substr($url, 0, $pos) . preg_replace('#/+#', '/', substr($url, $pos));
}
} elseif (strpos($url, '//') !== false) {
$url = preg_replace('#/+#', '/', trim($url, '/'));
}
if ($url !== '') {
$url .= ($this->suffix === null ? $manager->suffix : $this->suffix);
}
if (!empty($params) && ($query = http_build_query($params)) !== '') {
$url .= '?' . $query;
}
$this->createStatus = self::CREATE_STATUS_SUCCESS;
return $url;
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4