Created
July 6, 2020 02:36
-
-
Save harryWonder/c6fe6e0d1ce31bc3452ad48f0fcc6ac5 to your computer and use it in GitHub Desktop.
A middleware for checking and validating the headers of incoming requests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
/** | |
* RequestMiddleware - The RequestMiddleware. This Controller makes use of a few Models, Classes and packages for authenticating requests.... | |
* | |
* @author Ilori Stephen A <stephenilori458@gmail.com> | |
* @link https://github.com/learningdollars/php-rest-api/App/Middleware/RequestMiddleware.php | |
* @license MIT | |
*/ | |
class RequestMiddleware { | |
protected static $Request; | |
/** | |
* __construct | |
* | |
* Initializes the middleware | |
* | |
* @param void | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
Self::$Request = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : ''; | |
return; | |
} | |
/** | |
* acceptsJson | |
* | |
* Determines if the request is of a JSON Content type | |
* | |
* @param void | |
* @return boolean | |
*/ | |
public static function acceptsJson() | |
{ | |
if (strtolower(Self::$Request) == 'application/json') { | |
return true; | |
} | |
return false; | |
} | |
/** | |
* acceptsFormData | |
* | |
* Determines if the request is of a Form Data Content type | |
* | |
* @param void | |
* @return boolean | |
*/ | |
public static function acceptsFormData() | |
{ | |
Self::$Request = explode(';', Self::$Request)[0]; | |
if (strtolower(Self::$Request) == 'multipart/form-data') { | |
return true; | |
} | |
return false; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment