-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelpers.php
46 lines (35 loc) · 959 Bytes
/
Helpers.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
<?php
namespace CzProject\PhpCli;
class Helpers
{
public function __construct()
{
throw new StaticClassException('This is static class.');
}
/**
* @param string $input
* @return string
*/
public static function normalizeInput($input)
{
return rtrim($input, "\r\n");
}
/**
* @param string|int|float|bool|mixed $value
* @return bool
*/
public static function convertToBool($value)
{
if (is_string($value)) {
$lValue = strtolower($value);
if ($lValue === 'yes' || $lValue === 'y' || $lValue === 'on' || $lValue === 'true' || $lValue === '1') {
return TRUE;
} elseif ($lValue === 'no' || $lValue === 'n' || $lValue === 'off' || $lValue === 'false' || $lValue === '0') {
return FALSE;
}
} elseif (is_bool($value) || is_int($value) || is_float($value)) {
return (bool) $value;
}
throw new \CzProject\PhpCli\InvalidValueException('Invalid boolean value.');
}
}