|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CodexShaper\DBM\Database\Drivers\MongoDB; |
|
4
|
|
|
|
|
5
|
|
|
use MongoDB\BSON\Binary; |
|
6
|
|
|
use MongoDB\BSON\Decimal128 as Decimal; |
|
7
|
|
|
use MongoDB\BSON\Javascript; |
|
8
|
|
|
use MongoDB\BSON\MaxKey; |
|
9
|
|
|
use MongoDB\BSON\MinKey; |
|
10
|
|
|
use MongoDB\BSON\ObjectId; |
|
11
|
|
|
use MongoDB\BSON\Regex; |
|
12
|
|
|
use MongoDB\BSON\Timestamp; |
|
13
|
|
|
use MongoDB\BSON\UTCDateTime; |
|
14
|
|
|
|
|
15
|
|
|
class Type |
|
16
|
|
|
{ |
|
17
|
|
|
protected static $types = [ |
|
18
|
|
|
'binary', |
|
19
|
|
|
'decimal', |
|
20
|
|
|
'javascript', |
|
21
|
|
|
'maxKey', |
|
22
|
|
|
'minKey', |
|
23
|
|
|
'objectId', |
|
24
|
|
|
'regex', |
|
25
|
|
|
'timestamp', |
|
26
|
|
|
'dateTime', |
|
27
|
|
|
'string', |
|
28
|
|
|
'arrayType', |
|
29
|
|
|
'object', |
|
30
|
|
|
'boolean', |
|
31
|
|
|
'double', |
|
32
|
|
|
'null', |
|
33
|
|
|
'integer', |
|
34
|
|
|
'longInteger', |
|
35
|
|
|
'relationship', |
|
36
|
|
|
]; |
|
37
|
|
|
public static function binary(string $value, int $type = Binary::TYPE_GENERIC) |
|
38
|
|
|
{ |
|
39
|
|
|
return new Binary($value, $type); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public static function decimal(string $value) |
|
43
|
|
|
{ |
|
44
|
|
|
return new Decimal($value); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public static function javascript(string $code, $scope = []) |
|
48
|
|
|
{ |
|
49
|
|
|
if (!is_array($scope) || !is_array()) { |
|
|
|
|
|
|
50
|
|
|
throw new \Exception($scope . " should be array or object"); |
|
51
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return new Javascript($code, $scope); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public static function maxKey() |
|
58
|
|
|
{ |
|
59
|
|
|
return new MaxKey(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public static function minKey() |
|
63
|
|
|
{ |
|
64
|
|
|
return new MinKey(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public static function objectId(string $value) |
|
68
|
|
|
{ |
|
69
|
|
|
return new ObjectId($value); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public static function regex(string $pattern, string $flags) |
|
|
|
|
|
|
73
|
|
|
{ |
|
74
|
|
|
return new Regex($value); |
|
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public static function timestamp(int $increment, int $timestamp) |
|
78
|
|
|
{ |
|
79
|
|
|
return new Timestamp($increment, $timestamp); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public static function dateTime($milliseconds = null) |
|
83
|
|
|
{ |
|
84
|
|
|
if (!is_int($milliseconds) || !is_float($milliseconds) || !is_string($milliseconds) || !$milliseconds instanceof \DateTimeInterface) { |
|
|
|
|
|
|
85
|
|
|
throw new \Exception($milliseconds . " integer or float or string or instance of DateTimeInterface"); |
|
86
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
return new UTCDateTime($milliseconds); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/* |
|
92
|
|
|
* Custom Types |
|
93
|
|
|
*/ |
|
94
|
|
|
|
|
95
|
|
|
public static function string($value) |
|
96
|
|
|
{ |
|
97
|
|
|
return (string) $value; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public static function arrayType($value) |
|
101
|
|
|
{ |
|
102
|
|
|
return (array) $value; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public static function object($value) |
|
106
|
|
|
{ |
|
107
|
|
|
return (object) $value; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public static function boolean($value) |
|
111
|
|
|
{ |
|
112
|
|
|
return (boolean) $value; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public static function double($value) |
|
116
|
|
|
{ |
|
117
|
|
|
return (double) $value; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public static function null() |
|
121
|
|
|
{ |
|
122
|
|
|
return null; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public static function integer($value) |
|
126
|
|
|
{ |
|
127
|
|
|
return (int) $value; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public static function longInteger($value) |
|
131
|
|
|
{ |
|
132
|
|
|
return (int) $value; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
public static function relationship($value) |
|
136
|
|
|
{ |
|
137
|
|
|
return $value; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public static function getTypes() |
|
141
|
|
|
{ |
|
142
|
|
|
return (array) self::$types; |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.