public function __construct($options = [])
{
$selfPath = str_replace('\\', '/', dirname($_SERVER['PHP_SELF']));
if ($selfPath !== '/' && preg_match('#(.*)/public$#i', $selfPath, $match) === 1) {
$selfPath = $match[1];
} else {
$selfPath = rtrim($selfPath, '/');
}
if (isset($options['baseUrls'])) {
/** @noinspection ForeachSourceInspection */
foreach ($options['baseUrls'] as $module => $baseUrl) {
$this->_baseUrls[$module] = rtrim($baseUrl, '/');
}
} else {
$host = $this->request->getServer('HTTP_HOST');
$scheme = $this->request->getScheme();
foreach ($this->router->getModules() as $module => $path) {
if ($path[0] === '/') {
$baseUrl = $scheme . '://' . $host . $selfPath . ($path === '/' ? '' : $path);
} else {
$baseUrl = (strpos($path, '://') ? '' : $scheme . '://') . $path;
}
$this->_baseUrls[$module] = $baseUrl;
}
if (!isset($this->_baseUrls[''])) {
$this->_baseUrls[''] = $this->_baseUrls[$this->dispatcher->getModuleName()];
}
}
if (isset($options['assets'])) {
$this->_assets = rtrim($options['assets'], '/');
} else {
$this->_assets = $selfPath;
}
}