Skip to content

Instantly share code, notes, and snippets.

@john555
Last active March 4, 2020 07:04
Show Gist options
  • Save john555/62001aca8d24e13714e1d29decdd57e0 to your computer and use it in GitHub Desktop.
Save john555/62001aca8d24e13714e1d29decdd57e0 to your computer and use it in GitHub Desktop.
<?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;
}
}
}
@DigiLive
Copy link

DigiLive commented Nov 28, 2018

public function getBody() return either null, $result or $body, but $body is never defined in this method.
What is it supposed to contain?

@john555
Copy link
Author

john555 commented Feb 28, 2019

It's a bug. I have to fix it.

@mqnoy
Copy link

mqnoy commented Jul 12, 2019

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