[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 namespace Httpful\Response; 4 5 final class Headers implements \ArrayAccess, \Countable { 6 7 private $headers; 8 9 private function __construct($headers) 10 { 11 $this->headers = $headers; 12 } 13 14 public static function fromString($string) 15 { 16 $lines = preg_split("/(\r|\n)+/", $string, -1, PREG_SPLIT_NO_EMPTY); 17 array_shift($lines); // HTTP HEADER 18 $headers = array(); 19 foreach ($lines as $line) { 20 list($name, $value) = explode(':', $line, 2); 21 $headers[strtolower(trim($name))] = trim($value); 22 } 23 return new self($headers); 24 } 25 26 public function offsetExists($offset) 27 { 28 return isset($this->headers[strtolower($offset)]); 29 } 30 31 public function offsetGet($offset) 32 { 33 if (isset($this->headers[$name = strtolower($offset)])) { 34 return $this->headers[$name]; 35 } 36 } 37 38 public function offsetSet($offset, $value) 39 { 40 throw new \Exception("Headers are read-only."); 41 } 42 43 public function offsetUnset($offset) 44 { 45 throw new \Exception("Headers are read-only."); 46 } 47 48 public function count() 49 { 50 return count($this->headers); 51 } 52 53 public function toArray() 54 { 55 return $this->headers; 56 } 57 58 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |