sspmod_consent_Auth_Process_Consent::checkDisable PHP Method

checkDisable() private static method

Helper function to check whether consent is disabled.
private static checkDisable ( mixed $option, string $entityId ) : boolean
$option mixed The consent.disable option. Either an array of array, an array or a boolean.
$entityId string The entityID of the SP/IdP.
return boolean True if disabled, false if not.
    private static function checkDisable($option, $entityId)
    {
        if (is_array($option)) {
            // Check if consent.disable array has one element that is an array
            if (count($option) === count($option, COUNT_RECURSIVE)) {
                // Array is not multidimensional.  Simple in_array search suffices
                return in_array($entityId, $option, true);
            }
            // Array contains at least one element that is an array, verify both possibilities
            if (in_array($entityId, $option, true)) {
                return true;
            }
            // Search in multidimensional arrays
            foreach ($option as $optionToTest) {
                if (!is_array($optionToTest)) {
                    continue;
                    // bad option
                }
                if (!array_key_exists('type', $optionToTest)) {
                    continue;
                    // option has no type
                }
                // Option has a type - switch processing depending on type value :
                if ($optionToTest['type'] === 'regex') {
                    // regex-based consent disabling
                    if (!array_key_exists('pattern', $optionToTest)) {
                        continue;
                        // no pattern defined
                    }
                    if (preg_match($optionToTest['pattern'], $entityId) === 1) {
                        return true;
                    }
                } else {
                    // option type is not supported
                    continue;
                }
            }
            // end foreach
            // Base case : no match
            return false;
        } else {
            return (bool) $option;
        }
    }