. */ namespace Doctrine\ORM\Query; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Types\Type; /** * Provides an enclosed support for parameter infering. * * * @link www.doctrine-project.org * @since 2.0 * @author Benjamin Eberlei * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel */ class ParameterTypeInferer { /** * Infer type of a given value, returning a compatible constant: * - Type (\Doctrine\DBAL\Types\Type::*) * - Connection (\Doctrine\DBAL\Connection::PARAM_*) * * @param mixed $value Parameter value * * @return mixed Parameter type constant */ public static function inferType($value) { if (is_integer($value)) { return Type::INTEGER; } if ($value instanceof \DateTime) { return Type::DATETIME; } if (is_array($value)) { return is_integer(current($value)) ? Connection::PARAM_INT_ARRAY : Connection::PARAM_STR_ARRAY; } return \PDO::PARAM_STR; } }