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
10 namespace Zend\Http\Header
;
15 * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.10
17 class Connection
implements HeaderInterface
19 const CONNECTION_CLOSE
= 'close';
20 const CONNECTION_KEEP_ALIVE
= 'keep-alive';
23 * Value of this header
27 protected $value = self
::CONNECTION_KEEP_ALIVE
;
32 * @throws Exception\InvalidArgumentException
34 public static function fromString($headerLine)
36 $header = new static();
38 list($name, $value) = GenericHeader
::splitHeaderLine($headerLine);
40 // check to ensure proper header type for this factory
41 if (strtolower($name) !== 'connection') {
42 throw new Exception\
InvalidArgumentException('Invalid header line for Connection string: "' . $name . '"');
45 $header->setValue(trim($value));
52 * Set Connection header to define persistent connection
57 public function setPersistent($flag)
59 if ((bool) $flag === true) {
60 $this->value
= self
::CONNECTION_KEEP_ALIVE
;
62 $this->value
= self
::CONNECTION_CLOSE
;
68 * Get whether this connection is persistent
72 public function isPersistent()
74 return ($this->value
=== self
::CONNECTION_KEEP_ALIVE
);
78 * Set arbitrary header value
79 * RFC allows any token as value, 'close' and 'keep-alive' are commonly used
81 * @param string $value
84 public function setValue($value)
86 $this->value
= strtolower($value);
92 * Connection header name
96 public function getFieldName()
102 * Connection header value
106 public function getFieldValue()
116 public function toString()
118 return 'Connection: ' . $this->getFieldValue();