Comparison check

@param	mixed	$value		検証する値
@param	string	$operator	演算子
@param	array	$options	オプション
@return	bool	検証に合格した場合:true、検証に失敗した場合:false
5784
public static function Comparison ($value, $operator, $operand, $options) {
		$converter = static::GetConverter($options['type'] ?? null);
		if (is_callable($converter)) {
			$value		= $converter($value);
			$operand	= $converter($operand);
		}

 		if (is_object($value) && is_callable($value)) {
 			$value = $value($operator, $operand, $options);
 		}

 		if (is_object($operand) && is_callable($operand)) {
 			$operand = $operand($operator, $operand, $options);
 		}

		if (($empty_skip_type = $options['have_to_skip'] ?? false) !== false) {
			if (static::TwoValueEmptyChecker($value, $operand, $empty_skip_type, $options['empty_filter'] ?? null)) {
				return true;
			}
		}

		switch ($operator) {
			case static::OP_LT:
				return $value < $operand;
			case static::OP_LT_EQ:
				return $value <= $operand;
			case static::OP_GT:
				return $value > $operand;
			case static::OP_GT_EQ:
				return $value >= $operand;
			case static::OP_EQ:
				return $value == $operand;
			case static::OP_NOT_EQ:
				return $value != $operand;
			case static::OP_S_EQ:
				return $value === $operand;
			case static::OP_S_NOT_EQ:
				return $value !== $operand;
			case static::OP_IN:
				return in_array($value, Arrays::AdjustArray($operand), true);
			case static::OP_ANY:
				$ret = array_intersect(Arrays::AdjustArray($value), Arrays::AdjustArray($operand));
				return !empty($ret);
			case static::OP_NOT_IN:
				return !in_array($value, Arrays::AdjustArray($operand), true);
			case static::OP_KEY_EXISTS:
			case static::OP_KEY:
				return isset($operand[$value]) || array_key_exists($value, $operand);
			case static::OP_ANY_KEY_EXISTS:
				foreach ((array) $operand as $needle) {
					if (isset($value[$needle]) || array_key_exists($needle, $value)) {
						return true;
					}
				}
				return false;
			case static::OP_NOT_ANY_KEY_EXISTS:
				$count = 0;
				foreach ((array) $operand as $needle) {
					if (isset($value[$needle]) || array_key_exists($needle, $value)) {
						if (++$count > 1) {
							return false;
						}
					}
				}
				return true;
			default:
				return false;
		}
	}
482154
function optionExists($value) {
        foreach ($this->_options as $option) {
            if (isset($option['attr']['value']) && ($option['attr']['value'] == $value)) {
                return true;
            }
        }
        return false;
    }
1305667
public static function isApply($currentValue, $expectedValue, $operator = self::EQUAL)
    {
        list($currentValue, $expectedValue) = self::convertValues($currentValue, $expectedValue, $operator);

        switch ($operator) {
            case self::LIKE:
                if (stripos($currentValue, $expectedValue) !== false) {
                    return true;
                }
                break;

            case self::LIKE_LEFT:
                $length = strlen($expectedValue);
                $start = 0 - $length;
                $searchedValue = substr($currentValue, $start, $length);
                if (stripos($searchedValue, $expectedValue) !== false) {
                    return true;
                }
                break;

            case self::LIKE_RIGHT:
                $length = strlen($expectedValue);
                $searchedValue = substr($currentValue, 0, $length);
                if (stripos($searchedValue, $expectedValue) !== false) {
                    return true;
                }
                break;

            case self::NOT_LIKE:
                if (stripos($currentValue, $expectedValue) === false) {
                    return true;
                }
                break;

            case self::NOT_LIKE_LEFT:
                $length = strlen($expectedValue);
                $start = 0 - $length;
                $searchedValue = substr($currentValue, $start, $length);
                if (stripos($searchedValue, $expectedValue) === false) {
                    return true;
                }
                break;

            case self::NOT_LIKE_RIGHT:
                $length = strlen($expectedValue);
                $searchedValue = substr($currentValue, 0, $length);
                if (stripos($searchedValue, $expectedValue) === false) {
                    return true;
                }
                break;

            case self::EQUAL:
            case self::IN:
                return $currentValue == $expectedValue;

            case self::NOT_EQUAL:
            case self::NOT_IN:
                return $currentValue != $expectedValue;

            case self::GREATER_EQUAL:
                return $currentValue >= $expectedValue;

            case self::GREATER:
                return $currentValue > $expectedValue;

            case self::LESS_EQUAL:
                return $currentValue <= $expectedValue;

            case self::LESS:
                return $currentValue < $expectedValue;

            case self::BETWEEN:
                if (is_array($expectedValue) && count($expectedValue) >= 2) {
                    if ($currentValue >= $expectedValue[0] && $currentValue <= $expectedValue[1]) {
                        return true;
                    }
                } else {
                    throw new InvalidArgumentException(
                        sprintf(
                            'Between needs exactly an array of two expected values. Give: "%s"',
                            print_r($expectedValue, true)
                        )
                    );
                }
                break;

            default:
                throw new InvalidArgumentException('currently not implemented filter type: "' . $operator . '"');
        }

        return false;
    }
1071808
public static function prepParamValue(&$value, &$operator): bool
    {

        if (is_array($value)) {
            return true;
        } else {
            self::normalizeEmptyValue($value);
            $operator = self::parseParamOperator($value);

            if (is_numeric($value)) {
                return true;
            } else {
                $value = StringHelper::toLowerCase($value);

                if ($value !== ':empty:' || $value !== 'not :empty:') {
                    // Trim any whitespace from the value
                    $value = StringHelper::trim($value);

                    return false;
                }
            }
        }

        return true;
    }
647595
final protected static function validateOperator (string $operator, string $defaultOperator="=") : string
	{
		return static::isOperatorValid($operator) ? $operator : ($defaultOperator ?: '=');
	}
627752
public function whereCmp($field, $operator, $value)
    {
        if ($operator === '=') {
            $this->_filters[] = [$field => $this->normalizeValue($field, $value)];
        } elseif ($operator === '~=') {
            if ($this->_types && !isset($this->_types[$field])) {
                throw new InvalidArgumentException(['`:field` field is not exist in `:collection` collection',
                    'field' => $field,
                    'collection' => $this->getSource()
                ]);
            }

            if (is_scalar($value)) {
                if (is_int($value)) {
                    $this->_filters[] = [$field => ['$in' => [(string)$value, (int)$value]]];
                } elseif (is_float($value)) {
                    $this->_filters[] = [$field => ['$in' => [(string)$value, (float)$value]]];
                } else {
                    $this->_filters[] = [$field => ['$in' => [(string)$value, (int)$value, (float)$value]]];
                }
            } else {
                throw new InvalidValueException(['`:operator` operator is not  valid: value must be scalar value', 'operator' => $operator]);
            }
        } else {
            $operator_map = ['>' => '$gt', '>=' => '$gte', '<' => '$lt', '<=' => '$lte', '!=' => '$ne', '<>' => '$ne'];
            if (!isset($operator_map[$operator])) {
                throw new InvalidValueException(['unknown `:operator` operator', 'operator' => $operator]);
            }
            $this->_filters[] = [$field => [$operator_map[$operator] => $this->normalizeValue($field, $value)]];
        }

        return $this;
    }
585773
public static function doUnaryOperation($operator, &$value)
    {
        if (self::$unaryOperations === null) {
            self::$unaryOperations = [
                    self::BITWISE_NOT   => function (&$i) { return ~$i; },
                    self::NOT           => function (&$i) { return !$i; },
                    self::INCREMENT     => function (&$i) { return $i++; },
                    self::DECREMENT     => function (&$i) { return $i--; },
                    self::PRE_INCREMENT => function (&$i) { return ++$i; },
                    self::PRE_DECREMENT => function (&$i) { return --$i; },
                    self::NEGATION      => function (&$i) { return -$i; },
                    self::PLUS          => function (&$i) { return +$i; },
            ];
        }

        if (!isset(self::$unaryOperations[$operator])) {
            throw new PinqException('Unary operator \'%s\' is not supported', $operator);
        }

        $operation = self::$unaryOperations[$operator];

        return $operation($value);
    }
771190
public function isValid($value = null, array $options = []): bool
    {
        if (\count($options) > 0) {
            $this->setOptions($options);
        }
        $this->setValue($value);
        $this->errors = [];

        if (\strpos($this->value, '..') !== false || !\preg_match('/^(.+)@([^@]+)$/', $this->value, $matches)) {
            $this->setError(self::VALIDATOR_ERROR_EMAIL_INCORRECT_FORMAT);
            return false;
        }
        if (!\filter_var($this->value, FILTER_VALIDATE_EMAIL) !== false) {
            $this->setError(self::VALIDATOR_ERROR_EMAIL_INCORRECT_FORMAT);
            return false;
        }
        $host = $matches[2];
        if ($this->options['domain-check'] === true && @\gethostbyname($host) === $host) {
            $this->setError(self::VALIDATOR_ERROR_EMAIL_INVALID_DOMAIN);
            return false;
        }
        if ($this->options['mx-check'] === true) {
            return $this->mxCheck($host);
        }

        return true;
    }
150405
static public function buildParameterValue($operator, $value)
    {
        FilterOperator::isValid($operator, true);

        switch (intval($operator)) {
            case FilterOperator::LIKE:
            case FilterOperator::NOT_LIKE:
                return sprintf('%%%s%%', $value);
            case FilterOperator::START_WITH:
            case FilterOperator::NOT_START_WITH:
                return sprintf('%s%%', $value);
            case FilterOperator::END_WITH:
            case FilterOperator::NOT_END_WITH:
                return sprintf('%%%s', $value);
            default:
                return $value;
        }
    }
303604
protected function invalidOperatorAndValue($operator, $value)
    {
        return is_null($value) && array_key_exists($operator, $this->operators) &&
        ! array_key_exists($operator, ['=', '<>', '!=']);
    }
1284054
public function orWhereRaw($field, $operator = null, $value = null)
    {
        return $this->where($field, $operator, $value, 'or', true);
    }
689839
public static function where($key, $operator, $value = null)
    {
        if (func_num_args() === 2) {
            $value = $operator;
            $operator = '=';
        }

        if (! isset(static::$countries['longlist'])) {
            static::$countries['longlist'] = json_decode(static::getFile(__DIR__.'/../resources/data/longlist.json'), true);
        }

        return static::filter(static::$countries['longlist'], static::operatorForWhere($key, $operator, $value));
    }
1349048
final protected static function isOperatorValid (string $operator) : bool
	{
		// Arithmetic Operators
		$operators1 = ['+', '-', '*', '/', '%'];
		// Bitwise Operators
		$operators2 = ['&', '|', '^'];
		// Comparison Operators
		$operators3 = ['=', '<', '>', '>=', '<=', '<>'];
		// Compound Operators
		$operators4 = ['+=', '-=', '*=', '/=', '%=', '&=', '^-=', '|*='];
		// Logical Operators
		$operators5 = ['ALL', 'AND', 'ANY', 'BETWEEN', 'EXISTS', 'IN', 'LIKE', 'NOT', 'OR', 'SOME'];
		$operators 	= array_merge($operators1, $operators2, $operators3, $operators4, $operators5);
		return in_array(strtoupper($operator), $operators);
	}
739678
public static function compare()
    {
        $args = func_get_args();

        $operator = array_shift($args);

        return call_user_func_array(self::getComparator($operator), $args);
    }
1320058
protected function invalidOperatorAndValue($operator, $value)
    {
        $isOperator = in_array($operator, $this->operators);

        return is_null($value) && $isOperator && ! in_array($operator, ['=', '<>', '!=']);
    }
1025442
public static function compareSize($val, string $operator, $expected): bool
    {
        // type must be same
        if (\gettype($val) !== \gettype($expected)) {
            return false;
        }

        // not in: int, string, array
        if (($len = self::length($val)) < 0) {
            return false;
        }

        $wantLen = self::length($expected);

        switch ($operator) {
            case '>':
                $ok = $len > $wantLen;
                break;
            case '>=':
                $ok = $len >= $wantLen;
                break;
            case '<':
                $ok = $len < $wantLen;
                break;
            case '<=':
                $ok = $len <= $wantLen;
                break;
            default:
                $ok = false;
        }

        return $ok;
    }
1333700
protected static function parseComparisonOperator($value, $is_negation)
    {
        if (preg_match('/^\((gt|ge|lt|le)\)(.+)$/', $value, $match)) {
            $operator = null;
            switch ($match[1]) {
                case 'gt':
                    $operator = $is_negation ? static::OPERATOR_LESS_EQUAL : static::OPERATOR_GREATER;
                    break;
                case 'ge':
                    $operator = $is_negation ? static::OPERATOR_LESS : static::OPERATOR_GREATER_EQUAL;
                    break;
                case 'lt':
                    $operator = $is_negation ? static::OPERATOR_GREATER_EQUAL : static::OPERATOR_LESS;
                    break;
                case 'le':
                    $operator = $is_negation ? static::OPERATOR_GREATER : static::OPERATOR_LESS_EQUAL;
                    break;
            }

            $value = $match[2];

            return [$operator, $value];
        }

        return false;
    }