/** * @param string|Uri $uri * @return Rakorium\Okapi */ public function setUri($uri) { $this->uri = Uri::cast($uri); // Auto-set "Host" header $host = $this->uri->getHost(); if ($host && version_compare($this->getVersion(), "1.0", ">=")) { $port = $this->uri->getPort(); if ($port) { $host .= ":{$port}"; } $this->getHeaders()->set("Host", $host); } // Auto-set the parameters $query = $this->uri->getQuery(); if ($query && strtoupper($this->getMethod()) == 'GET') { $this->setParams($this->parseParams($query)); } return $this; }
/** * @param self $base */ protected function completePath(self $base) { $basePath = $base->getPath(); $relPath = $this->getPath(); // if (!$relPath) { $this->setPath($basePath); if (!$this->getQuery()) { $this->setQuery($base->getQuery()); } } else { if (substr($relPath, 0, 1) == '/') { $this->setPath(static::shortPath($relPath)); } else { if ($base->getHost() && !$basePath) { $mergedPath = "/"; } else { $cut = strrpos($basePath, '/'); $mergedPath = $cut !== false ? substr($basePath, 0, $cut + 1) : ''; } $this->setPath(static::shortPath($mergedPath . $relPath)); } } }