7
7
class MailThiefCollection extends Collection
8
8
{
9
9
/**
10
- * Identical to the 5.3 implementation of contains
10
+ * Identical to the 5.4 implementation of contains
11
11
*/
12
12
public function contains ($ key , $ operator = null , $ value = null )
13
13
{
14
- if (func_num_args () == 2 ) {
15
- return $ this ->contains (function ($ item ) use ($ key , $ value ) {
16
- return data_get ($ item , $ key ) == $ value ;
17
- });
14
+ if (func_num_args () == 1 ) {
15
+ if ($ this ->useAsCallable ($ key )) {
16
+ return ! is_null ($ this ->first ($ key ));
17
+ }
18
+
19
+ return in_array ($ key , $ this ->items );
18
20
}
19
21
20
- if ($ this ->useAsCallable ($ key )) {
21
- return ! is_null ($ this ->first ($ key ));
22
+ if (func_num_args () == 2 ) {
23
+ $ value = $ operator ;
24
+
25
+ $ operator = '= ' ;
22
26
}
23
27
24
- return in_array ( $ key , $ this -> items );
28
+ return $ this -> contains ( $ this -> operatorForWhere ( $ key , $ operator , $ value ) );
25
29
}
26
30
27
31
/**
28
- * 5.3 implementation of Arr::first()
32
+ * 5.4 implementation of Arr::first()
29
33
*/
30
34
public function first (callable $ callback = null , $ default = null )
31
35
{
@@ -35,15 +39,18 @@ public function first(callable $callback = null, $default = null)
35
39
if (empty ($ array )) {
36
40
return value ($ default );
37
41
}
42
+
38
43
foreach ($ array as $ item ) {
39
44
return $ item ;
40
45
}
41
46
}
47
+
42
48
foreach ($ array as $ key => $ value ) {
43
49
if (call_user_func ($ callback , $ value , $ key )) {
44
50
return $ value ;
45
51
}
46
52
}
53
+
47
54
return value ($ default );
48
55
}
49
56
}
0 commit comments