getFieldName())) { throw new Exception\InvalidArgumentException( 'Invalid header line for "' . $locationHeader->getFieldName() . '" header string' ); } HeaderValue::assertValid($uri); $locationHeader->setUri(trim($uri)); return $locationHeader; } /** * Set the URI/URL for this header, this can be a string or an instance of Zend\Uri\Http * * @param string|UriInterface $uri * @return AbstractLocation * @throws Exception\InvalidArgumentException */ public function setUri($uri) { if (is_string($uri)) { try { $uri = UriFactory::factory($uri); } catch (UriException\InvalidUriPartException $e) { throw new Exception\InvalidArgumentException( sprintf('Invalid URI passed as string (%s)', (string) $uri), $e->getCode(), $e ); } } elseif (!($uri instanceof UriInterface)) { throw new Exception\InvalidArgumentException('URI must be an instance of Zend\Uri\Http or a string'); } $this->uri = $uri; return $this; } /** * Return the URI for this header * * @return string */ public function getUri() { if ($this->uri instanceof UriInterface) { return $this->uri->toString(); } return $this->uri; } /** * Return the URI for this header as an instance of Zend\Uri\Http * * @return UriInterface */ public function uri() { if ($this->uri === null || is_string($this->uri)) { $this->uri = UriFactory::factory($this->uri); } return $this->uri; } /** * Get header value as URI string * * @return string */ public function getFieldValue() { return $this->getUri(); } /** * Output header line * * @return string */ public function toString() { return $this->getFieldName() . ': ' . $this->getUri(); } /** * Allow casting to string * * @return string */ public function __toString() { return $this->toString(); } }