Skip to content

Instantly share code, notes, and snippets.

@xTNTx
Last active May 5, 2016 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xTNTx/abfe56a02aeafaea9845b12cb37a8bf4 to your computer and use it in GitHub Desktop.
Save xTNTx/abfe56a02aeafaea9845b12cb37a8bf4 to your computer and use it in GitHub Desktop.
[WS] Request example
<?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