Guess the handler for the value.

@param mixed    $value
@param string[] $types
@return string|null
16125
protected function checkClass($value, array $types): ?string
    {
        if (!is_object($value)) {
            return null;
        }

        foreach ($types as $type) {
            if (class_exists($type) && is_a($value, $type)) {
                return $type;
            }
        }

        return null;
    }
1024245
private function parseValue($value, $types, \ReflectionProperty $property, $object)
    {
        foreach ($types as $type) {
            foreach ($this->context->getParsers() as $parser) {
                if ($parser instanceof ValueParserInterface) {
                    if (is_array($value) && strpos($type, '[]') !== false) {
                        foreach ($value as $key => &$arrayValue) {
                            $arrayValue = $parser->toArrayValue($arrayValue, str_replace('[]', null, $type), $property, $arrayValue);
                        }
                    } else {
                        $value = $parser->toArrayValue($value, $type, $property, $object);
                    }
                } else {
                    throw new \InvalidArgumentException(sprintf('%s is not a valid parser.', get_class($parser)));
                }
            }
        }

        return $value;
    }
345274
protected function process($value, string $type)
    {
        if ($type === 'integer') {
            return (int) $value;
        }

        if ($type === 'float') {
            return (float) $value;
        }

        if ($type === 'boolean') {
            return (bool) $value;
        }

        return (string) $value;
    }
850369
public function elseValue($value = null, $type = null)
    {
        if (is_array($value)) {
            end($value);
            $value = key($value);
        }

        if ($value !== null && !$value instanceof ExpressionInterface) {
            $value = $this->_castToExpression($value, $type);
        }

        if (!$value instanceof ExpressionInterface) {
            $value = ['value' => $value, 'type' => $type];
        }

        $this->_elseValue = $value;
    }
648788
private static function MaybeThrowIfValueArrayDoesNotMatchTypes(
        array $value,
        string ...$types
    ) : array {
        $initialCount = count($value);

        $value = array_filter(
            $value,
            /**
            * @param scalar|array|object|null $maybe
            */
            function ($maybe) use ($types) : bool {
                if (is_object($maybe)) {
                    foreach ($types as $maybeType) {
                        if (is_a($maybe, $maybeType)) {
                            return true;
                        }
                    }

                    return false;
                }

                return in_array(
                    gettype($maybe),
                    $types,
                    DefinitionAssistant::IN_ARRAY_STRICT_MODE
                );
            }
        );

        if (count($value) !== $initialCount) {
            throw new InvalidArgumentException(
                'Argument 3 passed to ' .
                __METHOD__ .
                ' contained values that did not match the provided types!'
            );
        }

        return $value;
    }
1173812
protected function _getValueByType($value, $type)
	{
		if( !is_null($value) )
		{
			switch( $type )
			{
				case "id":
					if( array_contains( array('',null), $value, true ) )
					{
						$value = null;
					}
					else
					{
						$value = intval( $value );
					}
				break;
				case "bool":
				case "boolean":
					$value = (bool) $value;
				break;
				case "int":
					$value = (int) $value;
					break;
				case "float":
					$value = (float) $value;
				break;
				case "object":
				case "array":
					if(is_object($value) || !is_array($value))
					{
						$value = unserialize($value);
					}
				break;
				case "date":
					if($value == '0000-00-00' || $value == '')
					{
						$value = null;
					}
				break;
				case "time":
					if($value == '00:00:00' || $value == '')
					{
						$value = null;
					}
				break;
				case "datetime":
					if($value == '0000-00-00 00:00:00' || $value == '')
					{
						$value = null;
					}
				break;
				case "text":
				default:
					$value = (string) $value;
				break;
			}
		}

		return $value;
	}
812225
private function normalizeValue($value, string $type)
    {
        if (Types::ID === $type && $value) {
            if (\is_array($value)) {
                $idsArray = [];
                foreach ($value as $id) {
                    if ($id) {
                        $idsArray[] = $this->decodeID($id);
                    }
                }
                $value = $idsArray;
            } else {
                $value = $this->decodeID($value);
            }
        }

        return $value;
    }
467107
protected function _type_assignment_get( $type, $value )
	{
		switch ( $type ) 
		{
			case 'int':
			case 'timestamp':
				return (int) $value;
			break;

			case 'string':
				return (string) $value;
			break;

			case 'bool':
				return (bool) $value;
			break;

			// json datatype try to decode return array on failure
			case 'json':
				if ( is_array( $value ) )
				{
					return $value;
				}
				if ( is_array( $value = json_decode( $value, true ) ) )
				{
					return $value;
				}
				return array();
			break;
		}

		return $value;
	}
580950
public static function castValueToDataType($value, $type)
    {
        switch ($type) {
            case Property::DATA_TYPE_FLOAT:
                return empty($value) ? null : (float) $value;
                break;

            case Property::DATA_TYPE_BOOLEAN:
                return empty($value) ? null : (bool) $value;
                break;

            case Property::DATA_TYPE_INTEGER:
                return empty($value) ? null : (int) $value;
                break;

            default:
                return $value;
                break;
        }
    }
303472
public function expectCurrent($type, $value = null)
    {
        if ($this->current->test($type, $value)) {
            return $this->current;
        }
        $value   = $this->current->getValue();
        $message = "Unexpected {$this->current->getTypeString()}";
        if ($value === true) {
            $message .= ' (true)';
        } elseif ($value === false) {
            $message .= ' (false)';
        } elseif ($value !== '') {
            $message .= " ({$value})";
        }
        throw new SyntaxException($message, $this->current->getLine());
    }
998198
public static function setType($value, $type, $nullable = TRUE)
	{
		if (!$nullable || NULL !== $value) {
			settype($value, $type);
		}

		return $value;
	}
1298974
public function expect(int $type, $value = null) : bool
    {
        if (!$this->accept($type, $value)) {
            $this->syntaxError('Expected '.Token::getStringRepresentation($type, $value).' got '.$this->getCurrentToken());
        }

        return true;
    }
153682
protected function toNull($value)
    {
        if ($value === 0 || $value === false || $value === '') {
            return null;
        }
        if ($this->getTypeCheck()->isArray($value) && count($value) === 1) {
            return $this->toNull(reset($value));
        }

        return $value;
    }
428445
static function guessType($value)
    {
        $map = array(
            "float"=>"number",
            "double"=>"number",
            "int"=>"number",
            "integer"=>"number",
            "bool"=>"number",
            "numeric"=>"number",
            "string"=>"string",
        );

        $type = strtolower(gettype($value));
        foreach ($map as $key=>$value) {
            if (strpos($type, $key)!==false) {
                return $value;
            }
        }
        return "unknown";
    }
812000
protected function validateTypeArray($value, array $schema, array $types = []): ErrorResult
    {
        $result = new ErrorResult();
        $isValid = false;
        foreach ($schema['type'] as $type) {
            $partResult = $this->validate($value, $type, $types);
            if ($partResult->hasErrors() === false) {
                $isValid = true;
            }
        }
        if ($isValid === false) {
            $possibleTypes = [];
            foreach ($schema['type'] as $type) {
                if (is_scalar($type)) {
                    $possibleTypes[] = $type;
                } elseif (is_array($type) && array_key_exists('type', $type)) {
                    $possibleTypes[] = $type['type'];
                }
            }
            $error = $this->createError(sprintf('None of the given schemas %s matched %s',
                implode(',', $possibleTypes),
                is_scalar($value) ? (string)$value : gettype($value)
            ));
            $result->addError($error);
        }

        return $result;
    }
59965
public function setValue($value, $type = null)
    {
        $this->value = $value;
        $this->type  = $type ?: ParameterTypeInferer::inferType($value);
    }
510605
public function getTypeFromValue($value = null)
    {
        $value = ($value == null ? $this->value : $value);
        return array_search($this->value, self::$sourceList);
    }