+fix apache => nginx (getallheaders function) does not exist anymore

This commit is contained in:
xdrm-brackets 2018-02-17 18:51:53 +01:00
parent 6b77c9f3da
commit 1078935256
1 changed files with 35 additions and 3 deletions

View File

@ -42,7 +42,7 @@
/* [2] Define headers
=========================================================*/
$this->headers = \getallheaders();
$this->headers = self::getallheaders_adapter();
/* [3] Define default datasets (GET, POST)
@ -57,7 +57,10 @@
$this->body = \file_get_contents('php://input');
/* (2) Fetch content type */
$this->type = self::getContentType($this->headers['Content-Type']);
if( isset($this->headers['Content-Type']) )
$this->type = self::getContentType($this->headers['Content-Type']);
else
$this->type = self::getContentType();
/* [5] Parse BODY data -> POST
@ -78,7 +81,10 @@
/* [1] Checks argv
=========================================================*/
if( is_null($pContentType) )
$pContentType = $_SERVER['CONTENT_TYPE'];
if( isset($_SERVER['CONTENT_TYPE']) )
$pContentType = $_SERVER['CONTENT_TYPE'];
else
$pContentType = 'text/plain';
/* [2] Checks types
@ -195,4 +201,30 @@
public function HEADERS(){ return $this->headers; }
public function METHOD(){ return $this->method; }
public function URI(){ return $this->uri; }
private static function getallheaders_adapter(){
/* (1) If exists -> use it
---------------------------------------------------------*/
if( function_exists('getallheaders') )
return getallheaders();
/* (2) If does not (php-fpm)
---------------------------------------------------------*/
/* (1) init. variables */
$fetched_headers = [];
/* (2) Get all headers from $_SERVER */
foreach($_SERVER as $hname=>$hvalue ){
// {1} Store only if begins with 'HTTP_' //
if( substr($hname,0,5) == 'HTTP_' )
$fetched_headers[ str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($hname,5)))))] = $hvalue;
}
/* (3) Return created headers */
return $fetched_headers;
}
}