Exemplo n.º 1
0
 /**
  * Creates new headers collection from server parameters.
  *
  * @todo Think about better way to retrieve HTTP request headers.
  *
  * @param array $server Array with server parameters.
  * This usually comes from $_SERVER superglobal.
  *
  * @return static
  */
 public static function fromServer(array $server)
 {
     $headers = new Headers([]);
     foreach ($server as $key => $value) {
         if (substr($key, 0, 4) === 'HTTP') {
             // Strip the HTTP_ from the beginning of the string.
             $normalizedKey = strtolower(substr_replace($key, '', 0, 5));
             // Replace every underscore with hyphen.
             $normalizedKey = str_replace('_', '-', $normalizedKey);
             // Normalize key case.
             $normalizedKey = ucwords(strtolower($normalizedKey), '-');
             // Add a header to the collection
             $headers->set($normalizedKey, $value);
         }
     }
     return $headers;
 }