Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Http / Header / AbstractLocation.php
blob79cfbeb90fcedbe34099be8cbe5114303d25f0e3
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Http\Header;
12 use Zend\Uri\Exception as UriException;
13 use Zend\Uri\Uri;
14 use Zend\Uri\UriFactory;
15 use Zend\Uri\UriInterface;
18 /**
19 * Abstract Location Header
20 * Supports headers that have URI as value
21 * @see Zend\Http\Header\Location
22 * @see Zend\Http\Header\ContentLocation
23 * @see Zend\Http\Header\Referer
25 * Note for 'Location' header:
26 * While RFC 1945 requires an absolute URI, most of the browsers also support relative URI
27 * This class allows relative URIs, and let user retrieve URI instance if strict validation needed
29 abstract class AbstractLocation implements HeaderInterface
31 /**
32 * URI for this header
34 * @var UriInterface
36 protected $uri = null;
38 /**
39 * Create location-based header from string
41 * @param string $headerLine
42 * @return AbstractLocation
43 * @throws Exception\InvalidArgumentException
45 public static function fromString($headerLine)
47 $locationHeader = new static();
49 // ZF-5520 - IIS bug, no space after colon
50 list($name, $uri) = GenericHeader::splitHeaderLine($headerLine);
52 // check to ensure proper header type for this factory
53 if (strtolower($name) !== strtolower($locationHeader->getFieldName())) {
54 throw new Exception\InvalidArgumentException(
55 'Invalid header line for "' . $locationHeader->getFieldName() . '" header string'
59 $locationHeader->setUri(trim($uri));
61 return $locationHeader;
64 /**
65 * Set the URI/URL for this header, this can be a string or an instance of Zend\Uri\Http
67 * @param string|UriInterface $uri
68 * @return AbstractLocation
69 * @throws Exception\InvalidArgumentException
71 public function setUri($uri)
73 if (is_string($uri)) {
74 try {
75 $uri = UriFactory::factory($uri);
76 } catch (UriException\InvalidUriPartException $e) {
77 throw new Exception\InvalidArgumentException(
78 sprintf('Invalid URI passed as string (%s)', (string) $uri),
79 $e->getCode(),
83 } elseif (!($uri instanceof UriInterface)) {
84 throw new Exception\InvalidArgumentException('URI must be an instance of Zend\Uri\Http or a string');
86 $this->uri = $uri;
88 return $this;
91 /**
92 * Return the URI for this header
94 * @return string
96 public function getUri()
98 if ($this->uri instanceof UriInterface) {
99 return $this->uri->toString();
101 return $this->uri;
105 * Return the URI for this header as an instance of Zend\Uri\Http
107 * @return UriInterface
109 public function uri()
111 if ($this->uri === null || is_string($this->uri)) {
112 $this->uri = UriFactory::factory($this->uri);
114 return $this->uri;
118 * Get header value as URI string
120 * @return string
122 public function getFieldValue()
124 return $this->getUri();
128 * Output header line
130 * @return string
132 public function toString()
134 return $this->getFieldName() . ': ' . $this->getUri();
138 * Allow casting to string
140 * @return string
142 public function __toString()
144 return $this->toString();