You are here

public static function RulesData::typesMatch in Rules 7.2

Returns whether the type match. They match if type1 is compatible to type2.

Parameters

$var_info: The name of the type to check for whether it is compatible to type2.

$param_info: The type expression to check for.

bool $ancestors: (optional) Whether sub-type relationships for checking type compatibility should be taken into account. Defaults to TRUE.

Return value

bool Whether the types match.

5 calls to RulesData::typesMatch()
RulesData::matchingDataSelector in includes/rules.state.inc
Returns data for the given info and the to-be-configured parameter.
RulesDataProcessor::processors in includes/rules.processor.inc
Returns defined data processors applicable for the given parameter.
RulesPlugin::checkParameterSettings in includes/rules.core.inc
Checks whether parameters are correctly configured.
RulesTestDataCase::testTypeMatching in tests/rules.test
Tests type matching.
rules_condition_data_is_form_alter in modules/data.rules.inc
Form alter callback for the condition data_is.

File

includes/rules.state.inc, line 395
Contains the state and data related stuff.

Class

RulesData
A class holding static methods related to data.

Code

public static function typesMatch($var_info, $param_info, $ancestors = TRUE) {
  $var_type = $var_info['type'];
  $param_type = $param_info['type'];
  if ($param_type == '*' || $param_type == 'unknown') {
    return TRUE;
  }
  if ($var_type == $param_type) {

    // Make sure the bundle matches, if specified by the parameter.
    return !isset($param_info['bundles']) || isset($var_info['bundle']) && in_array($var_info['bundle'], $param_info['bundles']);
  }

  // Parameters may specify multiple types using an array.
  $valid_types = is_array($param_type) ? $param_type : array(
    $param_type,
  );
  if (in_array($var_type, $valid_types)) {
    return TRUE;
  }

  // Check for sub-type relationships.
  if ($ancestors && !isset($param_info['bundles'])) {
    $cache =& rules_get_cache();
    self::typeCalcAncestors($cache, $var_type);

    // If one of the types is an ancestor return TRUE.
    return (bool) array_intersect_key($cache['data_info'][$var_type]['ancestors'], array_flip($valid_types));
  }
  return FALSE;
}