-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathcodeigniter_websocket_helper.php
71 lines (63 loc) · 1.46 KB
/
codeigniter_websocket_helper.php
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* Author: takielias
* Github Repo : https://github.com/takielias/codeigniter-websocket
* Date: 04/05/2019
* Time: 09:04 PM
*/
/**
* Inspired By
* Ratchet Websocket Library: helper file
* @author Romain GALLIEN <romaingallien.rg@gmail.com>
*/
defined('BASEPATH') or exit('No direct script access allowed');
if (!function_exists('valid_json')) {
/**
* Check JSON validity
* @method valid_json
* @param mixed $var Variable to check
* @return bool
*/
function valid_json($var)
{
return (is_string($var)) && (is_array(json_decode($var,
true))) && (json_last_error() == JSON_ERROR_NONE) ? true : false;
}
}
if (!function_exists('valid_jwt')) {
/**
* Check JWT validity
* @method valid_jwt
* @param mixed $token Variable to check
* @return Object/false
*/
function valid_jwt($token)
{
return AUTHORIZATION::validateToken($token);
}
}
/**
* Codeigniter Websocket Library: helper file
*/
if (!function_exists('output')) {
/**
* Output valid or invalid logs
* @method output
* @param string $type Log type
* @param string $var String
* @return string
*/
function output($type = 'success', $output = null)
{
if ($type == 'success') {
echo "\033[32m" . $output . "\033[0m" . PHP_EOL;
} elseif ($type == 'error') {
echo "\033[31m" . $output . "\033[0m" . PHP_EOL;
} elseif ($type == 'fatal') {
echo "\033[31m" . $output . "\033[0m" . PHP_EOL;
exit(EXIT_ERROR);
} else {
echo $output . PHP_EOL;
}
}
}