/** * */ public function testCompletion() { // $base = "ABC"; $base = "content/article/view.html"; $uri = new Uri("../edit.html"); $uri->complete($base); $this->assertEquals($uri->toString(), "content/edit.html"); }
/** * @param Destination $destination * @param Uri $context * @return Uri */ public function assemble(Destination $destination, $context = null) { $base = Uri::cast($context); $params = $destination->getParams(); $path = $this->resolvePattern($params->core()); $uri = new Uri(); $uri->setPath($base->getPath() . $path); return $uri; }
/** * @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 Uri $uri * @return int */ protected function checkUrl(Uri $uri) { if ($uri->getHost()) { $status = 1; } elseif ($uri->getScheme() != '' && $uri->getScheme() != 'file') { $status = 2; } elseif (!$uri->getPath()) { $status = 3; } else { $status = 0; } return $status; }
/** * @param Destination $destination * @param Uri $context * @return Uri */ public function assemble(Destination $destination, $context = null) { $needle = $this->getNeedle(); $source = $this->getSource(); $uri = Uri::fresh($context); if ($source == 'host') { $uri->setHost($needle . $uri->getHost()); } else { $uri->setPath($uri->getPath() . $needle); } return $uri; }
/** * @param Destination $destination * @param Uri $context */ public function assemble(Destination $destination, $context = null) { $base = Uri::cast($context); $model = clone $destination->getParams(); $model->set('~', $base->getPath()); $path = $model->render($this->getTemplate()); $uri = new Uri(); $uri->setPath($path); return $uri; }
/** * @param string|Uri $path * @return static */ public function setPath($path) { $this->path = Uri::cast($path); return $this; }
/** * @param string|Uri $base * @return self */ public function setBase($base = null) { $this->base = $base === null ? null : Uri::cast($base); 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)); } } }