vendor/nategood/httpful/src/Httpful/Response/Headers.php line 75

Open in your IDE?
  1. <?php
  2. namespace Httpful\Response;
  3. final class Headers implements \ArrayAccess\Countable {
  4.     private $headers;
  5.     /**
  6.      * @param array $headers
  7.      */
  8.     private function __construct($headers)
  9.     {
  10.         $this->headers $headers;
  11.     }
  12.     /**
  13.      * @param string $string
  14.      * @return Headers
  15.      */
  16.     public static function fromString($string)
  17.     {
  18.         $lines preg_split("/(\r|\n)+/"$string, -1PREG_SPLIT_NO_EMPTY);
  19.         array_shift($lines); // HTTP HEADER
  20.         $headers = array();
  21.         foreach ($lines as $line) {
  22.             list($name$value) = explode(':'$line2);
  23.             $headers[strtolower(trim($name))] = trim($value);
  24.         }
  25.         return new self($headers);
  26.     }
  27.     /**
  28.      * @param string $offset
  29.      * @return bool
  30.      */
  31.     public function offsetExists($offset)
  32.     {
  33.         return isset($this->headers[strtolower($offset)]);
  34.     }
  35.     /**
  36.      * @param string $offset
  37.      * @return mixed
  38.      */
  39.     public function offsetGet($offset)
  40.     {
  41.         if (isset($this->headers[$name strtolower($offset)])) {
  42.             return $this->headers[$name];
  43.         }
  44.     }
  45.     /**
  46.      * @param string $offset
  47.      * @param string $value
  48.      * @throws \Exception
  49.      */
  50.     public function offsetSet($offset$value)
  51.     {
  52.         throw new \Exception("Headers are read-only.");
  53.     }
  54.     /**
  55.      * @param string $offset
  56.      * @throws \Exception
  57.      */
  58.     public function offsetUnset($offset)
  59.     {
  60.         throw new \Exception("Headers are read-only.");
  61.     }
  62.     /**
  63.      * @return int
  64.      */
  65.     public function count()
  66.     {
  67.         return count($this->headers);
  68.     }
  69.     /**
  70.      * @return array
  71.      */
  72.     public function toArray()
  73.     {
  74.         return $this->headers;
  75.     }
  76. }