. */ namespace Doctrine\ORM\Query; /** * This class is used to generate DQL expressions via a set of PHP static functions * * @author Jonathan H. Wage * @author Roman Borschel * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link http://www.phpdoctrine.org * @since 2.0 * @version $Revision$ */ class Expr { public static function andx($x = null) { return new Expr\Andx(func_get_args()); } public static function orx($x = null) { return new Expr\Orx(func_get_args()); } public static function select($select = null) { return new Expr\Select(func_get_args()); } public static function from($from, $alias = null) { return new Expr\From($from, $alias); } public static function join($joinType, $join, $alias = null, $conditionType = null, $condition = null) { return new Expr\Join($joinType, $join, $alias, $conditionType, $condition); } public static function leftJoin($join, $alias = null, $conditionType = null, $condition = null) { return new Expr\Join(Expr\Join::LEFT_JOIN, $join, $alias, $conditionType, $condition); } public static function innerJoin($join, $alias = null, $conditionType = null, $condition = null) { return new Expr\Join(Expr\Join::INNER_JOIN, $join, $alias, $conditionType, $condition); } public static function orderBy($sort = null, $order = null) { return new Expr\OrderBy($sort, $order); } public static function groupBy($groupBy = null) { return new Expr\GroupBy(func_get_args()); } public static function having($having = null) { return new Expr\Having(func_get_args()); } public static function eq($x, $y) { return new Expr\Comparison($x, '=', $y); } public static function neq($x, $y) { return new Expr\Comparison($x, '<>', $y); } public static function lt($x, $y) { return new Expr\Comparison($x, '<', $y); } public static function lte($x, $y) { return new Expr\Comparison($x, '<=', $y); } public static function gt($x, $y) { return new Expr\Comparison($x, '>', $y); } public static function gte($x, $y) { return new Expr\Comparison($x, '>=', $y); } public static function avg($x) { return new Expr\Func('AVG', array($x)); } public static function max($x) { return new Expr\Func('MAX', array($x)); } public static function min($x) { return new Expr\Func('MIN', array($x)); } public static function count($x) { return new Expr\Func('COUNT', array($x)); } public static function countDistinct($x) { return 'COUNT(DISTINCT ' . implode(', ', func_get_args()) . ')'; } public static function exists($subquery) { return new Expr\Func('EXISTS', array($subquery)); } public static function all($subquery) { return new Expr\Func('ALL', array($subquery)); } public static function some($subquery) { return new Expr\Func('SOME', array($subquery)); } public static function any($subquery) { return new Expr\Func('ANY', array($subquery)); } public static function not($restriction) { return new Expr\Func('NOT', array($restriction)); } public static function abs($x) { return new Expr\Func('ABS', array($x)); } public static function prod($x, $y) { return new Expr\Math($x, '*', $y); } public static function diff($x, $y) { return new Expr\Math($x, '-', $y); } public static function sum($x, $y) { return new Expr\Math($x, '+', $y); } public static function quot($x, $y) { return new Expr\Math($x, '/', $y); } public static function sqrt($x) { return new Expr\Func('SQRT', array($x)); } public static function in($x, $y) { return new Expr\Func($x . ' IN', (array) $y); } public static function notIn($x, $y) { return new Expr\Func($x . ' NOT IN', (array) $y); } public static function like($x, $y) { return new Expr\Comparison($x, 'LIKE', $y); } public static function concat($x, $y) { return new Expr\Func('CONCAT', array($x, $y)); } public static function substr($x, $from, $len) { return new Expr\Func('SUBSTR', array($x, $from, $len)); } public static function lower($x) { return new Expr\Func('LOWER', array($x)); } public static function upper($x) { return new Expr\Func('UPPER', array($x)); } public static function length($x) { return new Expr\Func('LENGTH', array($x)); } public static function literal($literal) { if (is_numeric($literal)) { return (string) $literal; } else { return "'" . $literal . "'"; } } public static function between($val, $x, $y) { return new Expr\Func('BETWEEN', array($val, $x, $y)); } public static function trim($x) { return new Expr\Func('TRIM', $x); } }