-
Notifications
You must be signed in to change notification settings - Fork 0
/
Zooomr.Static.Functions.php
60 lines (49 loc) · 2.04 KB
/
Zooomr.Static.Functions.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
// Internal method for checking if the passed hash of params is acceptable to a given methods parameter list
function static_params_are_valid($a_array_of_required_params, $a_array_of_extra_allowed_param_names, $a_hash_of_params_and_values)
{
if ( null == $a_array_of_required_params )
{
$a_array_of_required_params = array();
}
# get the keys
$array_of_passed_params = array();
if( null != $a_hash_of_params_and_values )
{
$array_of_passed_params = array_keys($a_hash_of_params_and_values);
}
if ( null != $a_array_of_required_params )
{
ksort($a_array_of_required_params);
# check that all the required params are in the hash
$missing_required_params = array_diff_key($a_array_of_required_params, $array_of_passed_params);
if (sizeof($missing_required_params) != 0)
{
throw new Exception("Zooomr::params_are_valid missing required parameter(s) " . join(",", $missing_required_params) . " was passed: " . print_r($a_hash_of_params_and_values));
return false;
}
}
if ( null == $a_hash_of_params_and_values && null == $a_array_of_extra_allowed_param_names)
{
# don't worry about it if they're both nil
}
elseif( (!null == $a_array_of_extra_allowed_param_names) )
{
# check that there aren't any extra ones we weren't expecting
ksort($a_array_of_extra_allowed_param_names);
# make sure we've removed the mandatory ones
$extra_params = $array_of_passed_params;
if( null != $a_array_of_required_params )
{
$extra_params = array_diff($array_of_passed_params, $a_array_of_required_params);
}
ksort($extra_params);
$unrecognised_params = array_diff($extra_params, $a_array_of_extra_allowed_param_names);
if (0 != sizeof($unrecognised_params))
{
throw new Exception("Zooomr::params_are_valid unrecognised parameter(s) " . join(",", $unrecognised_params));
return false;
}
}
}
?>