-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.php
92 lines (78 loc) · 1.74 KB
/
utils.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/*
* Check if we are running on PHP 8.0 or later.
*/
function vipgocs_env_check() :void {
if ( version_compare(
phpversion(),
'8.0.0'
) < 0 ) {
echo 'Error: PHP 8.0 is required as a minimum.' . PHP_EOL;
exit( 251 ); /* System problem */
}
}
/*
* Report any errors to the user.
*/
function vipgocs_logging_setup() :void {
ini_set( 'error_log', '' );
error_reporting( E_ALL );
ini_set( 'display_errors', 'on' );
}
/*
* Attempt to load vip-go-ci
*/
function vipgocs_vipgoci_load(
array $options,
string $option_name
) :void {
if ( ! is_dir( $options[ $option_name ] ) ) {
echo 'Path specified in --' . $option_name . ' is invalid, is not a directory' . PHP_EOL;
exit(253);
}
if ( ! is_file( $options[ $option_name ] . '/requires.php' ) ) {
echo 'No requires.php found in --' . $option_name . ' ; is it a valid vip-go-ci installation?' . PHP_EOL;
exit(253);
}
/*
* Include vip-go-ci as a library.
*/
echo 'Attempting to include vip-go-ci...' . PHP_EOL;
require_once(
$options[ $option_name ] . '/requires.php'
);
vipgoci_log(
'Successfully included vip-go-ci'
);
}
/*
* Check if file is empty or only has
* whitespacing.
*/
function vipgocs_file_empty_or_whitespace_only(
string $file_path,
string $whitespacing_chars = " \n\r\t\v\0"
) :?bool {
$file_contents = file_get_contents(
$file_path
);
/*
* In case of error, return null.
*/
if ( false === $file_contents ) {
return null;
}
/*
* Remove all whitespacing from the
* file contents; if there is no content
* left after that the file is only whitespacing.
*/
$file_contents = trim( $file_contents, $whitespacing_chars );
if ( '' === $file_contents ) {
return true;
}
/*
* There is content, so return false.
*/
return false;
}