summaryrefslogtreecommitdiff
path: root/src/functions.php
blob: 9558dd9668efe6acc144e93295473f2588ed442f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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);
}