aboutsummaryrefslogtreecommitdiffstats
path: root/inc/messages.inc
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2016-05-10 22:24:50 +0200
committerpiernov <piernov@piernov.org>2016-05-10 22:24:50 +0200
commit9ad61ab6a23bd6fd51e67b85d743b4a7664ec637 (patch)
tree04c4ef3158c9848db91e56f9318162431a6040b4 /inc/messages.inc
parent204e838a7794bbce0d44fc35efb367abb052d02f (diff)
parent1e52affe15fb13e920f8942de998073238be6d01 (diff)
downloadcandybox-9ad61ab6a23bd6fd51e67b85d743b4a7664ec637.tar.gz
candybox-9ad61ab6a23bd6fd51e67b85d743b4a7664ec637.tar.bz2
candybox-9ad61ab6a23bd6fd51e67b85d743b4a7664ec637.tar.xz
candybox-9ad61ab6a23bd6fd51e67b85d743b4a7664ec637.zip
Merge branch 'phpdoc' into piernov
Diffstat (limited to 'inc/messages.inc')
-rw-r--r--inc/messages.inc34
1 files changed, 34 insertions, 0 deletions
diff --git a/inc/messages.inc b/inc/messages.inc
index 3a7d9b1..8583dc0 100644
--- a/inc/messages.inc
+++ b/inc/messages.inc
@@ -1,5 +1,15 @@
<?php
+/**
+ * Server to client error/info messages list and helpers.
+ *
+ * @package inc\messages.inc
+ * @author Alexandre Renoux
+ * @author Pierre-Emmanuel Novac
+ */
+/**
+ * Messages list.
+ */
$messages = array(
"shop_already_built" => "You have already built a shop.",
"gold_insufficient" => "You don't have enough gold.",
@@ -18,6 +28,14 @@ $messages = array(
"upload_success" => "Save file uploaded successfully: %s",
);
+/**
+ * Sends a message to the client.
+ *
+ * @param string $type message type, for example "info" or "error"
+ * @param string $msg message content
+ * @param string $fmt optional parameters to apply when formating message string
+ * @return void
+ */
function sendMessage($type, $msg, $fmt = null) {
global $messages;
$text = $messages[$msg];
@@ -25,10 +43,26 @@ function sendMessage($type, $msg, $fmt = null) {
echo json_encode(array($type => $text));
}
+/**
+ * Sends an error message to the client.
+ * Simple wrapper calling sendMessage with "error" as $type.
+ *
+ * @param string $msg message content
+ * @param string $fmt optional parameters to apply when formating message string
+ * @return void
+ */
function sendError($msg, $fmt = null) {
sendMessage("error", $msg, $fmt);
}
+/**
+ * Sends an info message to the client.
+ * Simple wrapper calling sendMessage with "info" as $type.
+ *
+ * @param string $msg message content
+ * @param string $fmt optional parameters to apply when formating message string
+ * @return void
+ */
function sendInfo($msg, $fmt = null) {
sendMessage("info", $msg, $fmt);
}