|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the m1\env library |
|
5
|
|
|
* |
|
6
|
|
|
* (c) m1 <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* @package m1/env |
|
12
|
|
|
* @version 1.0.0 |
|
13
|
|
|
* @author Miles Croxford <[email protected]> |
|
14
|
|
|
* @copyright Copyright (c) Miles Croxford <[email protected]> |
|
15
|
|
|
* @license http://github.com/m1/env/blob/master/LICENSE.md |
|
16
|
|
|
* @link http://github.com/m1/env/blob/master/README.md Documentation |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace M1\Env\Traits; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The trait for checking types |
|
23
|
|
|
* |
|
24
|
|
|
* @since 0.2.0 |
|
25
|
|
|
*/ |
|
26
|
|
|
trait ValueTypeCheckable |
|
27
|
|
|
{ |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Returns if value is a string |
|
31
|
|
|
* |
|
32
|
|
|
* @param string $value The value to test |
|
33
|
|
|
* |
|
34
|
|
|
* @return bool Is a value a string |
|
35
|
|
|
*/ |
|
36
|
30 |
|
private function isString($value) |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
30 |
|
return $this->startsWith('\'', $value) || $this->startsWith('"', $value); |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Returns if value is a bool |
|
43
|
|
|
* |
|
44
|
|
|
* @param string $value The value to test |
|
45
|
|
|
* |
|
46
|
|
|
* @return bool Is a value a bool |
|
47
|
|
|
*/ |
|
48
|
27 |
|
private function isBool($value) |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
27 |
|
return in_array(strtolower($value), self::$bool_variants); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Returns if the bool is in a string |
|
55
|
|
|
* |
|
56
|
|
|
* @param string $value The value to test |
|
57
|
|
|
* @param bool $quoted_string Is the context a quoted string |
|
58
|
|
|
* @param int $word_count The amount of words in the sentence |
|
59
|
|
|
* |
|
60
|
|
|
* @return bool Is a value a bool in a string |
|
61
|
|
|
*/ |
|
62
|
3 |
|
private function isBoolInString($value, $quoted_string, $word_count) |
|
63
|
|
|
{ |
|
64
|
3 |
|
return (is_bool($value)) && ($quoted_string || $word_count >= 2); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Returns if value is number |
|
69
|
|
|
* |
|
70
|
|
|
* @param string $value The value to test |
|
71
|
|
|
* |
|
72
|
|
|
* @return bool Is a value a number |
|
73
|
|
|
*/ |
|
74
|
24 |
|
private function isNumber($value) |
|
|
|
|
|
|
75
|
|
|
{ |
|
76
|
24 |
|
return is_numeric($value); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Returns if value is null |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $value The value to test |
|
83
|
|
|
* |
|
84
|
|
|
* @return bool Is a value null |
|
85
|
|
|
*/ |
|
86
|
24 |
|
private function isNull($value) |
|
|
|
|
|
|
87
|
|
|
{ |
|
88
|
24 |
|
return $value === 'null'; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Returns if variable value is a clone, e.g. BOOL = $(BOOL_1) |
|
93
|
|
|
* |
|
94
|
|
|
* @param string $value The value to test |
|
95
|
|
|
* @param array $matches The matches of the variables |
|
96
|
|
|
* @param bool $quoted_string If the value is in a quoted string |
|
97
|
|
|
* |
|
98
|
|
|
* @return bool Is a value null |
|
99
|
|
|
*/ |
|
100
|
6 |
|
private function isVariableClone($value, $matches, $quoted_string) |
|
101
|
|
|
{ |
|
102
|
6 |
|
return count($matches[0] === 1) && $value == $matches[0][0] && !$quoted_string; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|