summaryrefslogtreecommitdiff
path: root/static/classes/Response.class.php
diff options
context:
space:
mode:
Diffstat (limited to 'static/classes/Response.class.php')
-rwxr-xr-xstatic/classes/Response.class.php99
1 files changed, 97 insertions, 2 deletions
diff --git a/static/classes/Response.class.php b/static/classes/Response.class.php
index eed8ce7..48b9b58 100755
--- a/static/classes/Response.class.php
+++ b/static/classes/Response.class.php
@@ -1,8 +1,11 @@
<?php
/**
- * Copyright (c) 2015 cenci0 <alchimist94@gmail.com>
- * Copyright (c) 2015, 2016 the Pantsu.cat developers <hostmaster@pantsu.cat>
+ * Prints file upload API responses depending on desired response type format.
+ *
+ * @copyright Copyright (c) 2015 cenci0 <alchimist94@gmail.com>
+ * @copyright Copyright (c) 2015, 2016 the Pantsu.cat developers
+ * <hostmaster@pantsu.cat>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,10 +26,30 @@
* SOFTWARE.
*/
+/**
+ * The Response class is a do-it-all for getting responses out in different
+ * formats.
+ *
+ * @todo Create sub-classes to split and extend this god object.
+ */
class Response
{
+ /**
+ * Indicates response type used for routing.
+ *
+ * Valid strings are 'csv', 'html', 'json' and 'text'.
+ *
+ * @var string $type Response type
+ */
private $type;
+ /**
+ * Indicates requested response type.
+ *
+ * Valid strings are 'csv', 'html', 'json', 'gyazo' and 'text'.
+ *
+ * @param string|null $response_type Response type
+ */
public function __construct($response_type = null)
{
switch ($response_type) {
@@ -59,6 +82,13 @@ class Response
}
}
+ /**
+ * Routes error messages depending on response type.
+ *
+ * @param int $code HTTP status code number.
+ * @param int $desc Descriptive error message.
+ * @return void
+ */
public function error($code, $desc)
{
$response = null;
@@ -82,6 +112,12 @@ class Response
echo $response;
}
+ /**
+ * Routes success messages depending on response type.
+ *
+ * @param mixed[] $files
+ * @return void
+ */
public function send($files)
{
$response = null;
@@ -105,11 +141,25 @@ class Response
echo $response;
}
+ /**
+ * Indicates with CSV body the request was invalid.
+ *
+ * @deprecated 2.1.0 Will be renamed to camelCase format.
+ * @param int $description Descriptive error message.
+ * @return string Error message in CSV format.
+ */
private static function csv_error($description)
{
return '"error"'."\r\n"."\"$description\""."\r\n";
}
+ /**
+ * Indicates with CSV body the request was successful.
+ *
+ * @deprecated 2.1.0 Will be renamed to camelCase format.
+ * @param mixed[] $files
+ * @return string Success message in CSV format.
+ */
private static function csv_success($files)
{
$result = '"name","url","hash","size"'."\r\n";
@@ -123,11 +173,26 @@ class Response
return $result;
}
+ /**
+ * Indicates with HTML body the request was invalid.
+ *
+ * @deprecated 2.1.0 Will be renamed to camelCase format.
+ * @param int $code HTTP status code number.
+ * @param int $description Descriptive error message.
+ * @return string Error message in HTML format.
+ */
private static function html_error($code, $description)
{
return '<p>ERROR: ('.$code.') '.$description.'</p>';
}
+ /**
+ * Indicates with HTML body the request was successful.
+ *
+ * @deprecated 2.1.0 Will be renamed to camelCase format.
+ * @param mixed[] $files
+ * @return string Success message in HTML format.
+ */
private static function html_success($files)
{
$result = '';
@@ -139,6 +204,14 @@ class Response
return $result;
}
+ /**
+ * Indicates with JSON body the request was invalid.
+ *
+ * @deprecated 2.1.0 Will be renamed to camelCase format.
+ * @param int $code HTTP status code number.
+ * @param int $description Descriptive error message.
+ * @return string Error message in pretty-printed JSON format.
+ */
private static function json_error($code, $description)
{
return json_encode(array(
@@ -148,6 +221,13 @@ class Response
), JSON_PRETTY_PRINT);
}
+ /**
+ * Indicates with JSON body the request was successful.
+ *
+ * @deprecated 2.1.0 Will be renamed to camelCase format.
+ * @param mixed[] $files
+ * @return string Success message in pretty-printed JSON format.
+ */
private static function json_success($files)
{
return json_encode(array(
@@ -156,11 +236,26 @@ class Response
), JSON_PRETTY_PRINT);
}
+ /**
+ * Indicates with plain text body the request was invalid.
+ *
+ * @deprecated 2.1.0 Will be renamed to camelCase format.
+ * @param int $code HTTP status code number.
+ * @param int $description Descriptive error message.
+ * @return string Error message in plain text format.
+ */
private static function text_error($code, $description)
{
return 'ERROR: ('.$code.') '.$description;
}
+ /**
+ * Indicates with plain text body the request was successful.
+ *
+ * @deprecated 2.1.0 Will be renamed to camelCase format.
+ * @param mixed[] $files
+ * @return string Success message in plain text format.
+ */
private static function text_success($files)
{
$result = '';