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
12 use Zend\Stdlib\Message
;
15 * HTTP standard message (Request/Response)
17 * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4
19 abstract class AbstractMessage
extends Message
22 * @const string Version constant numbers
24 const VERSION_10
= '1.0';
25 const VERSION_11
= '1.1';
31 protected $version = self
::VERSION_11
;
36 protected $headers = null;
39 * Set the HTTP version for this object, one of 1.0 or 1.1
40 * (AbstractMessage::VERSION_10, AbstractMessage::VERSION_11)
42 * @param string $version (Must be 1.0 or 1.1)
43 * @return AbstractMessage
44 * @throws Exception\InvalidArgumentException
46 public function setVersion($version)
48 if ($version != self
::VERSION_10
&& $version != self
::VERSION_11
) {
49 throw new Exception\
InvalidArgumentException(
50 'Not valid or not supported HTTP version: ' . $version
53 $this->version
= $version;
58 * Return the HTTP version for this request
62 public function getVersion()
64 return $this->version
;
68 * Provide an alternate Parameter Container implementation for headers in this object,
69 * (this is NOT the primary API for value setting, for that see getHeaders())
72 * @param Headers $headers
73 * @return AbstractMessage
75 public function setHeaders(Headers
$headers)
77 $this->headers
= $headers;
82 * Return the header container responsible for headers
86 public function getHeaders()
88 if ($this->headers
=== null ||
is_string($this->headers
)) {
89 // this is only here for fromString lazy loading
90 $this->headers
= (is_string($this->headers
)) ? Headers
::fromString($this->headers
) : new Headers();
93 return $this->headers
;
97 * Allow PHP casting of this object
101 public function __toString()
103 return $this->toString();