Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
AccessCondition
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 8
110
0.00% covered (danger)
0.00%
0 / 1
 always
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 equals
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 equals_num
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 subset_keys
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 subset
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 in
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 in_group
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 in_store
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/** Contains methods for validating user/group permissions.  Every method of this class MUST be static and return a boolean value. */
4class AccessCondition {
5
6    /**
7    * Unconditionally grant permission - use carefully!
8    */
9    static function always(){
10        return true;
11    
12    }
13
14    // Check if the specified values are identical to one another (strict comparison).
15    static function equals($val1, $val2){
16        return ($val1 === $val2);
17    }    
18
19    // Check if the specified values are numeric, and if so, if they are equal to each other.
20    static function equals_num($val1, $val2){
21        if (!is_numeric($val1))
22            return false;
23        if (!is_numeric($val2))
24            return false;
25            
26        return ($val1 == $val2);
27    }
28    
29    // Check if all keys of the array $needle are present in the values of $haystack
30    static function subset_keys($needle, $haystack){
31        return count($needle) == count(array_intersect(array_keys($needle), $haystack));
32    }
33
34    // Check if all values in the array $needle are present in the values of $haystack
35    static function subset($needle, $haystack){
36        return count($needle) == count(array_intersect($needle, $haystack));
37    }
38    
39    // Check if the specified value $needle is in the values of $haystack
40    static function in($needle, $haystack){
41        return in_array($needle, $haystack);
42    }
43    
44    // Check if the specified user (by user_id) is in a particular group
45    static function in_group($user_id, $group_id){
46        $user = \UserFrosting\UserLoader::fetch($user_id);
47        $groups = $user->getGroups();
48        return isset($groups[$group_id]);
49    }
50    static function in_store($user_id, $store_id) {
51        $user = \UserFrosting\UserLoader::fetch($user_id);
52        $stores = $user->getStores();
53        return in_array($store_id, $stores);
54    }
55}