Last active
May 5, 2016 17:15
-
-
Save xTNTx/abfe56a02aeafaea9845b12cb37a8bf4 to your computer and use it in GitHub Desktop.
[WS] Request example
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 | |
class Request | |
{ | |
public $method; | |
public $postData; | |
public function __construct(argument) | |
{ | |
$this->setMethod(); | |
$this->setPostData(); | |
} | |
public function setMethod() { | |
$this->method = $_SERVER['REQUEST_METHOD']; | |
} | |
public function setPostData() { | |
$this->postData = $this->cleanData($_POST); | |
} | |
public function hasMethod($method) { | |
return $this->method === $method; | |
} | |
private function cleanData($data) { | |
foreach ($data as $key => $field) { | |
$data[$key] = trim($field); | |
} | |
return $data; | |
} | |
} | |
// Usage | |
$request = new Request(); | |
var_dump($request->postData); | |
var_dump($request->hasMethod('POST')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment