summaryrefslogtreecommitdiff
path: root/app/Core/Request.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-05-23 11:59:23 -0400
committerFrédéric Guillot <fred@kanboard.net>2014-05-23 11:59:23 -0400
commit14c2998c4ac0a56857014fb8b4d403b52dbc686e (patch)
tree0a31a1941f71b1db0863404243b101528058cfa9 /app/Core/Request.php
parentdb76bcb593e34948dab2709bcb7b6c1139a37c72 (diff)
Improve css and phpdoc comments
Diffstat (limited to 'app/Core/Request.php')
-rw-r--r--app/Core/Request.php69
1 files changed, 67 insertions, 2 deletions
diff --git a/app/Core/Request.php b/app/Core/Request.php
index df8ea41a..7e9f24ac 100644
--- a/app/Core/Request.php
+++ b/app/Core/Request.php
@@ -2,39 +2,92 @@
namespace Core;
+/**
+ * Request class
+ *
+ * @package core
+ * @author Frederic Guillot
+ */
class Request
{
+ /**
+ * Get URL string parameter
+ *
+ * @access public
+ * @param string $name Parameter name
+ * @param string $default_value Default value
+ * @return string
+ */
public function getStringParam($name, $default_value = '')
{
return isset($_GET[$name]) ? $_GET[$name] : $default_value;
}
+ /**
+ * Get URL integer parameter
+ *
+ * @access public
+ * @param string $name Parameter name
+ * @param integer $default_value Default value
+ * @return integer
+ */
public function getIntegerParam($name, $default_value = 0)
{
return isset($_GET[$name]) && ctype_digit($_GET[$name]) ? (int) $_GET[$name] : $default_value;
}
+ /**
+ * Get a form value
+ *
+ * @access public
+ * @param string $name Form field name
+ * @return string|null
+ */
public function getValue($name)
{
$values = $this->getValues();
return isset($values[$name]) ? $values[$name] : null;
}
+ /**
+ * Get form values or unserialized json request
+ *
+ * @access public
+ * @return array
+ */
public function getValues()
{
- if (! empty($_POST)) return $_POST;
+ if (! empty($_POST)) {
+ return $_POST;
+ }
$result = json_decode($this->getBody(), true);
- if ($result) return $result;
+
+ if ($result) {
+ return $result;
+ }
return array();
}
+ /**
+ * Get the raw body of the HTTP request
+ *
+ * @access public
+ * @return string
+ */
public function getBody()
{
return file_get_contents('php://input');
}
+ /**
+ * Get the content of an uploaded file
+ *
+ * @access public
+ * @param string $name Form file name
+ * @return string
+ */
public function getFileContent($name)
{
if (isset($_FILES[$name])) {
@@ -44,11 +97,23 @@ class Request
return '';
}
+ /**
+ * Return true if the HTTP request is sent with the POST method
+ *
+ * @access public
+ * @return bool
+ */
public function isPost()
{
return isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST';
}
+ /**
+ * Return true if the HTTP request is an Ajax request
+ *
+ * @access public
+ * @return bool
+ */
public function isAjax()
{
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest';