Last active
March 4, 2020 07:04
-
-
Save john555/62001aca8d24e13714e1d29decdd57e0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
include_once 'IRequest.php'; | |
class Request implements IRequest | |
{ | |
function __construct() | |
{ | |
$this->bootstrapSelf(); | |
} | |
private function bootstrapSelf() | |
{ | |
foreach($_SERVER as $key => $value) | |
{ | |
$this->{$this->toCamelCase($key)} = $value; | |
} | |
} | |
private function toCamelCase($string) | |
{ | |
$result = strtolower($string); | |
preg_match_all('/_[a-z]/', $result, $matches); | |
foreach($matches[0] as $match) | |
{ | |
$c = str_replace('_', '', strtoupper($match)); | |
$result = str_replace($match, $c, $result); | |
} | |
return $result; | |
} | |
public function getBody() | |
{ | |
if($this->requestMethod === "GET") | |
{ | |
return; | |
} | |
if ($this->requestMethod == "POST") | |
{ | |
$body = array(); | |
foreach($_POST as $key => $value) | |
{ | |
$body[$key] = filter_input(INPUT_POST, $key, FILTER_SANITIZE_SPECIAL_CHARS); | |
} | |
return $body; | |
} | |
} | |
} |
It's a bug. I have to fix it.
I found an error ,
Warning: Invalid argument supplied for foreach() in line 25
I tried to change
foreach ($matches as $match) {
its solve my problem
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
public function getBody() return either null, $result or $body, but $body is never defined in this method.
What is it supposed to contain?