summaryrefslogtreecommitdiff
path: root/app/Core
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
parentdb76bcb593e34948dab2709bcb7b6c1139a37c72 (diff)
Improve css and phpdoc comments
Diffstat (limited to 'app/Core')
-rw-r--r--app/Core/Listener.php4
-rw-r--r--app/Core/Request.php69
-rw-r--r--app/Core/Response.php99
-rw-r--r--app/Core/Router.php2
-rw-r--r--app/Core/Session.php39
-rw-r--r--app/Core/Translator.php2
6 files changed, 209 insertions, 6 deletions
diff --git a/app/Core/Listener.php b/app/Core/Listener.php
index b8bdd680..0df641ba 100644
--- a/app/Core/Listener.php
+++ b/app/Core/Listener.php
@@ -11,6 +11,10 @@ namespace Core;
interface Listener {
/**
+ * Execute the listener
+ *
+ * @access public
+ * @param array $data Event data
* @return boolean
*/
public function execute(array $data);
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';
diff --git a/app/Core/Response.php b/app/Core/Response.php
index ee98c9ed..87d2fa4a 100644
--- a/app/Core/Response.php
+++ b/app/Core/Response.php
@@ -2,20 +2,41 @@
namespace Core;
+/**
+ * Response class
+ *
+ * @package core
+ * @author Frederic Guillot
+ */
class Response
{
+ /**
+ * Send a custom Content-Type header
+ *
+ * @access public
+ * @param string $mimetype Mime-type
+ */
public function contentType($mimetype)
{
header('Content-Type: '.$mimetype);
}
+ /**
+ * Force the browser to download an attachment
+ *
+ * @access public
+ * @param string $filename File name
+ */
public function forceDownload($filename)
{
header('Content-Disposition: attachment; filename="'.$filename.'"');
}
/**
- * @param integer $status_code
+ * Send a custom HTTP status code
+ *
+ * @access public
+ * @param integer $status_code HTTP status code
*/
public function status($status_code)
{
@@ -23,12 +44,25 @@ class Response
header($_SERVER['SERVER_PROTOCOL'].' '.$status_code);
}
+ /**
+ * Redirect to another URL
+ *
+ * @access public
+ * @param string $url Redirection URL
+ */
public function redirect($url)
{
header('Location: '.$url);
exit;
}
+ /**
+ * Send a Json response
+ *
+ * @access public
+ * @param array $data Data to serialize in json
+ * @param integer $status_code HTTP status code
+ */
public function json(array $data, $status_code = 200)
{
$this->status($status_code);
@@ -39,6 +73,13 @@ class Response
exit;
}
+ /**
+ * Send a text response
+ *
+ * @access public
+ * @param string $data Raw data
+ * @param integer $status_code HTTP status code
+ */
public function text($data, $status_code = 200)
{
$this->status($status_code);
@@ -49,6 +90,13 @@ class Response
exit;
}
+ /**
+ * Send a HTML response
+ *
+ * @access public
+ * @param string $data Raw data
+ * @param integer $status_code HTTP status code
+ */
public function html($data, $status_code = 200)
{
$this->status($status_code);
@@ -59,6 +107,13 @@ class Response
exit;
}
+ /**
+ * Send a XML response
+ *
+ * @access public
+ * @param string $data Raw data
+ * @param integer $status_code HTTP status code
+ */
public function xml($data, $status_code = 200)
{
$this->status($status_code);
@@ -69,6 +124,13 @@ class Response
exit;
}
+ /**
+ * Send a javascript response
+ *
+ * @access public
+ * @param string $data Raw data
+ * @param integer $status_code HTTP status code
+ */
public function js($data, $status_code = 200)
{
$this->status($status_code);
@@ -79,6 +141,13 @@ class Response
exit;
}
+ /**
+ * Send a binary response
+ *
+ * @access public
+ * @param string $data Raw data
+ * @param integer $status_code HTTP status code
+ */
public function binary($data, $status_code = 200)
{
$this->status($status_code);
@@ -90,6 +159,12 @@ class Response
exit;
}
+ /**
+ * Send the security header: Content-Security-Policy
+ *
+ * @access public
+ * @param array $policies CSP rules
+ */
public function csp(array $policies = array())
{
$policies['default-src'] = "'self'";
@@ -119,16 +194,31 @@ class Response
header('Content-Security-Policy: '.$values);
}
+ /**
+ * Send the security header: X-Content-Type-Options
+ *
+ * @access public
+ */
public function nosniff()
{
header('X-Content-Type-Options: nosniff');
}
+ /**
+ * Send the security header: X-XSS-Protection
+ *
+ * @access public
+ */
public function xss()
{
header('X-XSS-Protection: 1; mode=block');
}
+ /**
+ * Send the security header: Strict-Transport-Security (only if we use HTTPS)
+ *
+ * @access public
+ */
public function hsts()
{
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
@@ -136,6 +226,13 @@ class Response
}
}
+ /**
+ * Send the security header: X-Frame-Options (deny by default)
+ *
+ * @access public
+ * @param string $mode Frame option mode
+ * @param array $urls Allowed urls for the given mode
+ */
public function xframe($mode = 'DENY', array $urls = array())
{
header('X-Frame-Options: '.$mode.' '.implode(' ', $urls));
diff --git a/app/Core/Router.php b/app/Core/Router.php
index a7c9764c..40610996 100644
--- a/app/Core/Router.php
+++ b/app/Core/Router.php
@@ -38,7 +38,7 @@ class Router
* Constructor
*
* @access public
- * @param Core\Registry $registry Registry instance
+ * @param Registry $registry Registry instance
* @param string $controller Controller name
* @param string $action Action name
*/
diff --git a/app/Core/Session.php b/app/Core/Session.php
index 0c3ec2d9..6ce1bd40 100644
--- a/app/Core/Session.php
+++ b/app/Core/Session.php
@@ -2,13 +2,33 @@
namespace Core;
+/**
+ * Session class
+ *
+ * @package core
+ * @author Frederic Guillot
+ */
class Session
{
+ /**
+ * Sesion lifetime
+ *
+ * @var integer
+ */
const SESSION_LIFETIME = 86400; // 1 day
+ /**
+ * Open a session
+ *
+ * @access public
+ * @param string $base_path Cookie path
+ * @param string $save_path Custom session save path
+ */
public function open($base_path = '/', $save_path = '')
{
- if ($save_path !== '') session_save_path($save_path);
+ if ($save_path !== '') {
+ session_save_path($save_path);
+ }
// HttpOnly and secure flags for session cookie
session_set_cookie_params(
@@ -39,16 +59,33 @@ class Session
}
}
+ /**
+ * Destroy the session
+ *
+ * @access public
+ */
public function close()
{
session_destroy();
}
+ /**
+ * Register a flash message (success notification)
+ *
+ * @access public
+ * @param string $message Message
+ */
public function flash($message)
{
$_SESSION['flash_message'] = $message;
}
+ /**
+ * Register a flash error message (error notification)
+ *
+ * @access public
+ * @param string $message Message
+ */
public function flashError($message)
{
$_SESSION['flash_error_message'] = $message;
diff --git a/app/Core/Translator.php b/app/Core/Translator.php
index be0be66a..015a76cb 100644
--- a/app/Core/Translator.php
+++ b/app/Core/Translator.php
@@ -121,7 +121,7 @@ class Translator
* Get an identifier from the translations or return the default
*
* @access public
- * @param string $idendifier Locale identifier
+ * @param string $identifier Locale identifier
* @param string $default Default value
* @return string
*/