/** * Генерирует URL согласно настройкам или локальному режиму * * @param string $queryString * @param bool|array $mode * * @return string */ public function createUrl($queryString, $mode = false) { if (substr($queryString, 0, 4) === 'http') { return $queryString; } $queryString = trim($queryString, '/'); if (is_array($mode) && !empty($this->config['url_manager'])) { $config = array_merge($this->config['url_manager'], $mode); } elseif (!is_array($mode) && !empty($this->config['url_manager'])) { $config = $this->config['url_manager']; } $protocol = !empty($config['https']) ? 'https://' : 'http://'; $hostName = $this->request->getHostName(); $scriptName = null; if (!empty($config['show_script'])) { $query = trim($_SERVER['PHP_SELF'], '/'); $scriptName = '/' . explode('/', $query)[0]; } if (true === $mode) { $basePath = $protocol . $hostName . $scriptName; } elseif (false === $mode) { $basePath = $scriptName; } else { $basePath = isset($config['absolute']) && true === $config['absolute'] ? $protocol . $hostName . $scriptName : $scriptName; } if (isset($config['pretty']) && false === $config['pretty']) { if ($queryString[0] === '?') { return $basePath . '?' . ltrim($queryString, '?'); } else { $param = $this->parser->parseRoutes($queryString); return $basePath . '?' . http_build_query($param); } } else { if ($queryString[0] !== '?') { return $basePath . '/' . $queryString; } else { mb_parse_str($queryString, $param); $param = $this->router->hashFromParam($param); $queryString = implode('/', $param); return $basePath . '/' . $queryString; } } }