Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- namespace Doctrine\ORM\Query;
- /**
- * Description of Expression
- *
- * @author robo
- */
- class Expr
- {
- /* type => method */
- private static $_methodMap = array(
- 'and' => '_andExpr',
- 'or' => '_orExpr',
- 'in' => '_inExpr',
- 'eq' => '_equalExpr',
- 'trim' => '_trimExpr',
- 'literal' => '_literalExpr',
- 'lt' => '_ltExpr',
- 'prod' => '_prodExpr',
- 'sum' => '_sumExpr',
- 'trim' => '_trimExpr'
- );
- private $_type;
- private $_parts;
- protected function __construct($type, array $parts)
- {
- $this->_type = $type;
- $this->_parts = $parts;
- }
- public function getDql()
- {
- return $this->{self::$_methodMap[$this->_type]}();
- }
- private function _inExpr()
- {
- }
- private function _equalExpr()
- {
- return (is_string($this->_parts[0]) ? $this->_parts[0] : $this->_parts[0]->getDql())
- . ' = ' .
- (is_string($this->_parts[1]) ? $this->_parts[1] : $this->_parts[1]->getDql());
- }
- private function _andExpr()
- {
- return '(' . $this->_parts[0]->getDql() . ' and ' . $this->_parts[1]->getDql() . ')';
- }
- private function _orExpr()
- {
- return '(' . $this->_parts[0]->getDql() . ' or ' . $this->_parts[1]->getDql() . ')';
- }
- private function _literalExpr()
- {
- if (is_numeric($this->_parts[0])) {
- return $this->_parts[0];
- } else {
- return "'" . $this->_parts[0] . "'";
- }
- }
- private function _ltExpr()
- {
- return '(' .
- (is_string($this->_parts[0]) ? $this->_parts[0] : $this->_parts[0]->getDql())
- . ' < ' .
- (is_string($this->_parts[1]) ? $this->_parts[1] : $this->_parts[1]->getDql())
- . ')';
- }
- private function _prodExpr()
- {
- return '(' .
- (is_string($this->_parts[0]) ? $this->_parts[0] : $this->_parts[0]->getDql())
- . ' * ' .
- (is_string($this->_parts[1]) ? $this->_parts[1] : $this->_parts[1]->getDql())
- . ')';
- }
- private function _sumExpr()
- {
- return '(' .
- (is_string($this->_parts[0]) ? $this->_parts[0] : $this->_parts[0]->getDql())
- . ' + ' .
- (is_string($this->_parts[1]) ? $this->_parts[1] : $this->_parts[1]->getDql())
- . ')';
- }
- private function _trimExpr()
- {
- return 'trim(' . (is_string($this->_parts[0]) ? $this->_parts[0] : $this->_parts[0]->getDql()) . ')';
- }
- //---
- public static function avg($x)
- {
- return new self('avg', array($x));
- }
- public static function max($x)
- {
- return new self('max', array($x));
- }
- public static function min($x)
- {
- return new self('min', array($x));
- }
- public static function count($x)
- {
- return new self('count', array($x));
- }
- public static function countDistinct($x)
- {
- return new self('countDistinct', array($x));
- }
- public static function exists($subquery)
- {
- }
- public static function all($subquery)
- {
- }
- public static function some($subquery)
- {
- }
- public static function any($subquery)
- {
- }
- public static function not($restriction)
- {
- }
- public static function andx($x, $y)
- {
- }
- public static function orx($x, $y)
- {
- return new self('or', array($x, $y));
- }
- public static function abs($x)
- {
- return new self('abs', array($x));
- }
- public static function prod($x, $y)
- {
- return new self('prod', array($x, $y));
- }
- public static function diff($x, $y)
- {
- }
- public static function sum($x, $y)
- {
- return new self('sum', array($x, $y));
- }
- public static function quot($x, $y)
- {
- }
- public static function sqrt($x)
- {
- }
- public static function eq($x, $y)
- {
- return new self('eq', array($x, $y));
- }
- public static function notEqual($x, $y)
- {
- }
- public static function like($x, $pattern, $escapeChar = null)
- {
- }
- public static function concat($x, $y)
- {
- }
- public static function substr($x, $from = null, $len = null)
- {
- }
- public static function lower($x)
- {
- }
- public static function upper($x)
- {
- }
- public static function lengt($x)
- {
- }
- public static function greaterThan($x, $y)
- {
- }
- public static function lessThan($x, $y)
- {
- }
- public static function lt($x, $y)
- {
- return new self('lt', array($x, $y));
- }
- public static function path($path)
- {
- return new self('path', array($path));
- }
- public static function literal($literal)
- {
- return new self('literal', array($literal));
- }
- public static function greaterThanOrEqualTo($x, $y)
- {
- }
- public static function lessThanOrEqualTo($x, $y)
- {
- }
- public static function between($val, $x, $y)
- {
- }
- public static function trim($val, $spec = null, $char = null)
- {
- return new self('trim', array($val, $spec, $char));
- }
- }
Add Comment
Please, Sign In to add comment