/** * isValidSpecialForm: Tells us if the ffname supplied is a valid * special form for the current gateway. * @var string $ffname The form name we want to try * @return boolean True if this is a valid special form, otherwise false */ public function isValidSpecialForm($ffname) { $defn = GatewayFormChooser::getFormDefinition($ffname); if (is_array($defn) && DataValidator::value_appears_in($this->getIdentifier(), $defn['gateway']) && array_key_exists('special_type', $defn)) { return true; } return false; }
/** * Test to determine if a value appears in a haystack. The haystack may have * explicit +/- rules (a - will take precedence over a +; if there is no * + rule, but there is a - rule everything is implicitly accepted); and may * also have an 'ALL' condition. * * @param mixed $needle Value, or array of values, to match * @param mixed $haystack Value, or array of values, that are acceptable * @return bool */ public static function value_appears_in($needle, $haystack) { $needle = is_array($needle) ? $needle : array($needle); $haystack = is_array($haystack) ? $haystack : array($haystack); $plusCheck = array_key_exists('+', $haystack); $minusCheck = array_key_exists('-', $haystack); if ($plusCheck || $minusCheck) { // With +/- checks we will first explicitly deny anything in '-' // Then if '+' is defined accept anything there // but if '+' is not defined we just let everything that wasn't denied by '-' through // Otherwise we assume both were defined and deny everything :) if ($minusCheck && DataValidator::value_appears_in($needle, $haystack['-'])) { return false; } if ($plusCheck && DataValidator::value_appears_in($needle, $haystack['+'])) { return true; } elseif (!$plusCheck) { // Implicit acceptance return true; } return false; } if (count($haystack) === 1 && in_array('ALL', $haystack)) { // If the haystack can accept anything, then whoo! return true; } $haystack = array_filter($haystack, function ($value) { return !is_array($value); }); $result = array_intersect($haystack, $needle); if (!empty($result)) { return true; } else { return false; } }
protected static function prefAllowedBySpec($prefs, $prefKey, $form, $formKey) { // we only filter on keys that exist if (empty($prefs[$prefKey]) || empty($form[$formKey])) { return true; } $prefValue = $prefs[$prefKey]; $formSetting = $form[$formKey]; return DataValidator::value_appears_in($prefValue, $formSetting); }