summaryrefslogtreecommitdiff
path: root/lib/request.php
diff options
context:
space:
mode:
authorFrédéric Guillot <contact@fredericguillot.com>2014-01-25 14:56:02 -0500
committerFrédéric Guillot <contact@fredericguillot.com>2014-01-25 14:56:02 -0500
commit9383a15af699ede77142d040b65118e15754a2ca (patch)
treeb550b5adf5bcf8f5a8793c188cc5630f26a27d49 /lib/request.php
First commit
Diffstat (limited to 'lib/request.php')
-rw-r--r--lib/request.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/request.php b/lib/request.php
new file mode 100644
index 00000000..8840e7a4
--- /dev/null
+++ b/lib/request.php
@@ -0,0 +1,44 @@
+<?php
+
+class Request
+{
+ public function getStringParam($name, $default_value = '')
+ {
+ return isset($_GET[$name]) ? $_GET[$name] : $default_value;
+ }
+
+ public function getIntegerParam($name, $default_value = 0)
+ {
+ return isset($_GET[$name]) && ctype_digit($_GET[$name]) ? (int) $_GET[$name] : $default_value;
+ }
+
+ public function getValue($name)
+ {
+ $values = $this->getValues();
+ return isset($values[$name]) ? $values[$name] : null;
+ }
+
+ public function getValues()
+ {
+ if (! empty($_POST)) return $_POST;
+
+ $result = json_decode($this->getBody(), true);
+ if ($result) return $result;
+
+ return array();
+ }
+
+ public function getBody()
+ {
+ return file_get_contents('php://input');
+ }
+
+ public function getFileContent($name)
+ {
+ if (isset($_FILES[$name])) {
+ return file_get_contents($_FILES[$name]['tmp_name']);
+ }
+
+ return '';
+ }
+}