1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Functions for receiving input from User. |
4
|
|
|
* |
5
|
|
|
* @author Adam "Saibamen" Stachowicz <[email protected]> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Includes\Input; |
9
|
|
|
|
10
|
|
|
use Includes\Text; |
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Get number from User. |
14
|
|
|
* |
15
|
|
|
* @param string $message Message for User what he must type |
16
|
|
|
* @param int|float $default Default number for empty input. Default is 0 |
17
|
|
|
* |
18
|
|
|
* @return float Inserted number |
19
|
|
|
*/ |
20
|
|
|
function getNumberInput($message, $default = 0) |
21
|
|
|
{ |
22
|
|
|
echo $message.' [Default: '.$default.']: '; |
23
|
|
|
|
24
|
|
|
do { |
25
|
|
|
$input = trim(fgets(STDIN)); |
|
|
|
|
26
|
|
|
Text\debug('User input: '.$input); |
27
|
|
|
|
28
|
|
|
if (is_null($input) || empty($input)) { |
29
|
|
|
Text\debug('Using default input: '.$default); |
30
|
|
|
$input = $default; |
31
|
|
|
} elseif (!is_numeric($input)) { |
32
|
|
|
echo 'Please input number: '; |
33
|
|
|
} |
34
|
|
|
} while (!is_numeric($input)); |
35
|
|
|
|
36
|
|
|
return (float) $input; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Get filename from User. |
41
|
|
|
* |
42
|
|
|
* @param string $message Message for User what he must type |
43
|
|
|
* |
44
|
|
|
* @return string Inserted filename |
45
|
|
|
*/ |
46
|
|
|
function getFilenameInput($message) |
47
|
|
|
{ |
48
|
|
|
echo $message.': '; |
49
|
|
|
|
50
|
|
|
do { |
51
|
|
|
$input = trim(fgets(STDIN)); |
|
|
|
|
52
|
|
|
Text\debug('User input: '.$input); |
53
|
|
|
|
54
|
|
|
/* |
55
|
|
|
* TODO: Invalid characters: |
56
|
|
|
* (Windows) \/:*?"<>| (check \ and / only at the end of string - need to test) |
57
|
|
|
* (Linux) / |
58
|
|
|
*/ |
59
|
|
|
$isInputWrong = is_null($input) || empty($input); |
60
|
|
|
|
61
|
|
|
if ($isInputWrong) { |
62
|
|
|
echo 'Please input filename: '; |
63
|
|
|
} |
64
|
|
|
} while ($isInputWrong); |
65
|
|
|
|
66
|
|
|
return $input; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Terminate script if User denied on confirmation. |
71
|
|
|
*/ |
72
|
|
|
function dieOnDenyUserConfirm() |
73
|
|
|
{ |
74
|
|
|
if (!getUserConfirm()) { |
75
|
|
|
die('Script terminated by user.'); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get User confirmation. Default is YES. |
81
|
|
|
* |
82
|
|
|
* @return bool Confirmation result |
83
|
|
|
*/ |
84
|
|
|
function getUserConfirm() |
85
|
|
|
{ |
86
|
|
|
while (1) { |
87
|
|
|
echo 'Do you really want to continue? [Y/n]: '; |
88
|
|
|
|
89
|
|
|
$input = trim(fgets(STDIN)); |
|
|
|
|
90
|
|
|
|
91
|
|
|
// Default is YES |
92
|
|
|
if (is_null($input) || empty($input) || strtolower($input) == 'y' || strtolower($input) == 'yes') { |
93
|
|
|
return true; |
94
|
|
|
} elseif (strtolower($input) == 'n' || strtolower($input) == 'no') { |
95
|
|
|
return false; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
// Fix missing return statement warning. Return true... |
100
|
|
|
return true; |
101
|
|
|
} |
102
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths