PSR에 맞게 수정
This commit is contained in:
+18
-15
@@ -1,35 +1,38 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
class WebUtil{
|
||||
|
||||
private function __construct(){
|
||||
|
||||
class WebUtil
|
||||
{
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function escapeIPv4($ip){
|
||||
public static function escapeIPv4($ip)
|
||||
{
|
||||
return str_replace('.', '\\.', $ip);
|
||||
}
|
||||
|
||||
public static function setHeaderNoCache(){
|
||||
if(!headers_sent()) {
|
||||
public static function setHeaderNoCache()
|
||||
{
|
||||
if (!headers_sent()) {
|
||||
header('Expires: Wed, 01 Jan 2014 00:00:00 GMT');
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', FALSE);
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
}
|
||||
}
|
||||
|
||||
public static function parseJsonPost(){
|
||||
public static function parseJsonPost()
|
||||
{
|
||||
// http://thisinterestsme.com/receiving-json-post-data-via-php/
|
||||
// http://thisinterestsme.com/php-json-error-handling/
|
||||
if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0){
|
||||
if (strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0) {
|
||||
throw new \Exception('Request method must be POST!');
|
||||
}
|
||||
|
||||
//Make sure that the content type of the POST request has been set to application/json
|
||||
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
|
||||
if(strcasecmp($contentType, 'application/json') != 0){
|
||||
if (strcasecmp($contentType, 'application/json') != 0) {
|
||||
throw new \Exception('Content type must be: application/json');
|
||||
}
|
||||
|
||||
@@ -43,16 +46,16 @@ class WebUtil{
|
||||
$jsonError = json_last_error();
|
||||
|
||||
//In some cases, this will happen.
|
||||
if(is_null($decoded) && $jsonError == JSON_ERROR_NONE){
|
||||
if (is_null($decoded) && $jsonError == JSON_ERROR_NONE) {
|
||||
throw new \Exception('Could not decode JSON!');
|
||||
}
|
||||
|
||||
//If an error exists.
|
||||
if($jsonError != JSON_ERROR_NONE){
|
||||
if ($jsonError != JSON_ERROR_NONE) {
|
||||
$error = 'Could not decode JSON! ';
|
||||
|
||||
//Use a switch statement to figure out the exact error.
|
||||
switch($jsonError){
|
||||
switch ($jsonError) {
|
||||
case JSON_ERROR_DEPTH:
|
||||
$error .= 'Maximum depth exceeded!';
|
||||
break;
|
||||
@@ -77,4 +80,4 @@ class WebUtil{
|
||||
|
||||
return $decoded;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user