コード例 #1
0
 /**
  * @param mixed $value
  * @param string $operator
  * @return mixed
  */
 protected function convertRuleValueToConditionValue($value, $operator)
 {
     if (is_array($value)) {
         foreach ($value as &$val) {
             $val = trim($this->convertRuleValueToConditionValue($val, null));
         }
         unset($val);
         if ($this->getDataType() === static::TYPE_STRING && in_array($operator, [static::OPERATOR_IN_ARRAY, static::OPERATOR_NOT_IN_ARRAY], true)) {
             $value = '^(' . implode('|', array_map('preg_quote', $value)) . ')$';
         }
         return array_values($value);
     }
     switch ($this->getDataType()) {
         case static::TYPE_TIME:
             $value = NormalizeValue::normalizeTime($value);
             break;
         case static::TYPE_DATE:
             $value = NormalizeValue::normalizeDate($value);
             break;
         case static::TYPE_TIMESTAMP:
             $value = NormalizeValue::normalizeDateTime($value);
             break;
         case static::TYPE_INTEGER:
             $value = NormalizeValue::normalizeInteger($value);
             break;
         case static::TYPE_FLOAT:
             $value = NormalizeValue::normalizeFloat($value);
             break;
         case static::TYPE_BOOL:
             $value = NormalizeValue::normalizeBoolean($value, ['f']);
             break;
     }
     switch ($operator) {
         case static::OPERATOR_BEGINS_WITH:
         case static::OPERATOR_NOT_BEGINS_WITH:
             return '^' . preg_quote($value);
             break;
         case static::OPERATOR_ENDS_WITH:
         case static::OPERATOR_NOT_ENDS_WITH:
             return preg_quote($value) . '$';
             break;
         case static::OPERATOR_CONTAINS:
         case static::OPERATOR_NOT_CONTAINS:
             return preg_quote($value);
             break;
         case static::OPERATOR_EQUAL:
         case static::OPERATOR_NOT_EQUAL:
             if ($this->getDataType() === static::TYPE_STRING) {
                 return '^' . preg_quote($value) . '$';
             }
             break;
         case static::OPERATOR_IS_NULL:
         case static::OPERATOR_IS_NOT_NULL:
             return null;
         case static::OPERATOR_IS_EMPTY:
         case static::OPERATOR_IS_NOT_EMPTY:
             return '';
     }
     return $value;
 }