You are here

public function BusinessRulesUtil::criteriaMet in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Util/BusinessRulesUtil.php \Drupal\business_rules\Util\BusinessRulesUtil::criteriaMet()

Criteria checker.

Parameters

string $value1: The value to be compared.

string $operator: The operator.

string $value2: The value to test against.

Return value

bool Criteria met/not met.

File

src/Util/BusinessRulesUtil.php, line 199

Class

BusinessRulesUtil
Class BusinessRulesUtil.

Namespace

Drupal\business_rules\Util

Code

public function criteriaMet($value1, $operator, $value2) {
  switch ($operator) {
    case self::EQUALS:
      if ($value1 === $value2) {
        return TRUE;
      }
      break;
    case self::CONTAINS:
      if (strpos($value1, $value2) !== FALSE) {
        return TRUE;
      }
      break;
    case self::BIGGER:
      if ($value1 > $value2) {
        return TRUE;
      }
      break;
    case self::BIGGER_OR_EQUALS:
      if ($value1 >= $value2) {
        return TRUE;
      }
      break;
    case self::SMALLER:
      if ($value1 < $value2) {
        return TRUE;
      }
      break;
    case self::SMALLER_OR_EQUALS:
      if ($value1 <= $value2) {
        return TRUE;
      }
      break;
    case self::DIFFERENT:
      if ($value1 != $value2) {
        return TRUE;
      }
      break;
    case self::IS_EMPTY:
      if (empty($value1)) {
        return TRUE;
      }
      break;
    case self::STARTS_WITH:
      if (strpos($value1, $value2) === 0) {
        return TRUE;
      }
      break;
    case self::ENDS_WITH:
      if (substr($value1, strlen($value2) * -1) === $value2) {
        return TRUE;
      }
      break;
    default:
      return FALSE;
  }
  return FALSE;
}