Httpful\Response\Headers::fromString PHP Method

fromString() public static method

public static fromString ( string $string ) : Headers
$string string
return Headers
    public static function fromString($string)
    {
        $headers = preg_split("/(\r|\n)+/", $string, -1, \PREG_SPLIT_NO_EMPTY);
        $parse_headers = array();
        for ($i = 1; $i < count($headers); $i++) {
            list($key, $raw_value) = explode(':', $headers[$i], 2);
            $key = trim($key);
            $value = trim($raw_value);
            if (array_key_exists($key, $parse_headers)) {
                // See HTTP RFC Sec 4.2 Paragraph 5
                // http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
                // If a header appears more than once, it must also be able to
                // be represented as a single header with a comma-separated
                // list of values.  We transform accordingly.
                $parse_headers[$key] .= ',' . $value;
            } else {
                $parse_headers[$key] = $value;
            }
        }
        return new self($parse_headers);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @param string  $body
  * @param string  $headers
  * @param Request $request
  * @param array   $meta_data
  */
 public function __construct($body, $headers, Request $request, array $meta_data = array())
 {
     $this->request = $request;
     $this->raw_headers = $headers;
     $this->raw_body = $body;
     $this->meta_data = $meta_data;
     $this->code = $this->_parseCode($headers);
     $this->reason = Http::reason($this->code);
     $this->headers = Response\Headers::fromString($headers);
     $this->_interpretHeaders();
     $this->body = $this->_parse($body);
 }
All Usage Examples Of Httpful\Response\Headers::fromString