summaryrefslogtreecommitdiff
path: root/src/functions.php
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2021-05-07 23:39:20 +0300
committerEvgeny Zinoviev <me@ch1p.io>2021-05-07 23:39:30 +0300
commit9a98ac50ff50dda2f2eed1ea825352c50c64440e (patch)
treecc5c7d36eee1ec934f8728e7f9104a9d2d760856 /src/functions.php
initial
Diffstat (limited to 'src/functions.php')
-rw-r--r--src/functions.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/functions.php b/src/functions.php
new file mode 100644
index 0000000..9558dd9
--- /dev/null
+++ b/src/functions.php
@@ -0,0 +1,47 @@
+<?php
+
+function jsonEncode($obj) {
+ return json_encode($obj, JSON_UNESCAPED_UNICODE);
+}
+
+function jsonDecode($json) {
+ return json_decode($json, true);
+}
+
+function toCamelCase(string $input, string $separator = '_'): string {
+ return lcfirst(str_replace($separator, '', ucwords($input, $separator)));
+}
+
+
+/* Connection helpers */
+
+function getMySQL(): mysql {
+ static $link = null;
+ if (is_null($link))
+ $link = new mysql(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DB);
+ return $link;
+}
+
+function getJobdMaster(): jobd\MasterClient {
+ return new jobd\MasterClient(JOBD_PORT, JOBD_HOST, JOBD_PASSWORD);
+}
+
+
+/* Command line helpers */
+
+function green(string $s): string {
+ return "\033[32m$s\033[0m";
+}
+
+function yellow(string $s): string {
+ return "\033[33m$s\033[0m";
+}
+
+function red(string $s): string {
+ return "\033[31m$s\033[0m";
+}
+
+function input(string $prompt): string {
+ echo $prompt;
+ return substr(fgets(STDIN), 0, -1);
+}