Guest User

Untitled

a guest
Jun 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. <?php
  2. /*
  3. * To change this template, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. namespace Doctrine\ORM\Query;
  8.  
  9. /**
  10. * Description of Expression
  11. *
  12. * @author robo
  13. */
  14. class Expr
  15. {
  16. /* type => method */
  17. private static $_methodMap = array(
  18. 'and' => '_andExpr',
  19. 'or' => '_orExpr',
  20. 'in' => '_inExpr',
  21. 'eq' => '_equalExpr',
  22. 'trim' => '_trimExpr',
  23. 'literal' => '_literalExpr',
  24. 'lt' => '_ltExpr',
  25. 'prod' => '_prodExpr',
  26. 'sum' => '_sumExpr',
  27. 'trim' => '_trimExpr'
  28. );
  29.  
  30. private $_type;
  31. private $_parts;
  32.  
  33. protected function __construct($type, array $parts)
  34. {
  35. $this->_type = $type;
  36. $this->_parts = $parts;
  37. }
  38.  
  39. public function getDql()
  40. {
  41. return $this->{self::$_methodMap[$this->_type]}();
  42. }
  43.  
  44. private function _inExpr()
  45. {
  46.  
  47. }
  48.  
  49. private function _equalExpr()
  50. {
  51. return (is_string($this->_parts[0]) ? $this->_parts[0] : $this->_parts[0]->getDql())
  52. . ' = ' .
  53. (is_string($this->_parts[1]) ? $this->_parts[1] : $this->_parts[1]->getDql());
  54. }
  55.  
  56. private function _andExpr()
  57. {
  58. return '(' . $this->_parts[0]->getDql() . ' and ' . $this->_parts[1]->getDql() . ')';
  59. }
  60.  
  61. private function _orExpr()
  62. {
  63. return '(' . $this->_parts[0]->getDql() . ' or ' . $this->_parts[1]->getDql() . ')';
  64. }
  65.  
  66. private function _literalExpr()
  67. {
  68. if (is_numeric($this->_parts[0])) {
  69. return $this->_parts[0];
  70. } else {
  71. return "'" . $this->_parts[0] . "'";
  72. }
  73. }
  74.  
  75. private function _ltExpr()
  76. {
  77. return '(' .
  78. (is_string($this->_parts[0]) ? $this->_parts[0] : $this->_parts[0]->getDql())
  79. . ' < ' .
  80. (is_string($this->_parts[1]) ? $this->_parts[1] : $this->_parts[1]->getDql())
  81. . ')';
  82. }
  83.  
  84. private function _prodExpr()
  85. {
  86. return '(' .
  87. (is_string($this->_parts[0]) ? $this->_parts[0] : $this->_parts[0]->getDql())
  88. . ' * ' .
  89. (is_string($this->_parts[1]) ? $this->_parts[1] : $this->_parts[1]->getDql())
  90. . ')';
  91. }
  92.  
  93. private function _sumExpr()
  94. {
  95. return '(' .
  96. (is_string($this->_parts[0]) ? $this->_parts[0] : $this->_parts[0]->getDql())
  97. . ' + ' .
  98. (is_string($this->_parts[1]) ? $this->_parts[1] : $this->_parts[1]->getDql())
  99. . ')';
  100. }
  101.  
  102. private function _trimExpr()
  103. {
  104. return 'trim(' . (is_string($this->_parts[0]) ? $this->_parts[0] : $this->_parts[0]->getDql()) . ')';
  105. }
  106.  
  107. //---
  108.  
  109. public static function avg($x)
  110. {
  111. return new self('avg', array($x));
  112. }
  113.  
  114. public static function max($x)
  115. {
  116. return new self('max', array($x));
  117. }
  118.  
  119. public static function min($x)
  120. {
  121. return new self('min', array($x));
  122. }
  123.  
  124. public static function count($x)
  125. {
  126. return new self('count', array($x));
  127. }
  128.  
  129. public static function countDistinct($x)
  130. {
  131. return new self('countDistinct', array($x));
  132. }
  133.  
  134. public static function exists($subquery)
  135. {
  136.  
  137. }
  138.  
  139. public static function all($subquery)
  140. {
  141.  
  142. }
  143.  
  144. public static function some($subquery)
  145. {
  146.  
  147. }
  148.  
  149. public static function any($subquery)
  150. {
  151.  
  152. }
  153.  
  154. public static function not($restriction)
  155. {
  156.  
  157. }
  158.  
  159. public static function andx($x, $y)
  160. {
  161.  
  162. }
  163.  
  164. public static function orx($x, $y)
  165. {
  166. return new self('or', array($x, $y));
  167. }
  168.  
  169. public static function abs($x)
  170. {
  171. return new self('abs', array($x));
  172. }
  173.  
  174. public static function prod($x, $y)
  175. {
  176. return new self('prod', array($x, $y));
  177. }
  178.  
  179. public static function diff($x, $y)
  180. {
  181.  
  182. }
  183.  
  184. public static function sum($x, $y)
  185. {
  186. return new self('sum', array($x, $y));
  187. }
  188.  
  189. public static function quot($x, $y)
  190. {
  191.  
  192. }
  193.  
  194. public static function sqrt($x)
  195. {
  196.  
  197. }
  198.  
  199. public static function eq($x, $y)
  200. {
  201. return new self('eq', array($x, $y));
  202. }
  203.  
  204. public static function notEqual($x, $y)
  205. {
  206.  
  207. }
  208.  
  209. public static function like($x, $pattern, $escapeChar = null)
  210. {
  211.  
  212. }
  213.  
  214. public static function concat($x, $y)
  215. {
  216.  
  217. }
  218.  
  219. public static function substr($x, $from = null, $len = null)
  220. {
  221.  
  222. }
  223.  
  224. public static function lower($x)
  225. {
  226.  
  227. }
  228.  
  229. public static function upper($x)
  230. {
  231.  
  232. }
  233.  
  234. public static function lengt($x)
  235. {
  236.  
  237. }
  238.  
  239. public static function greaterThan($x, $y)
  240. {
  241.  
  242. }
  243.  
  244. public static function lessThan($x, $y)
  245. {
  246.  
  247. }
  248.  
  249. public static function lt($x, $y)
  250. {
  251. return new self('lt', array($x, $y));
  252. }
  253.  
  254. public static function path($path)
  255. {
  256. return new self('path', array($path));
  257. }
  258.  
  259. public static function literal($literal)
  260. {
  261. return new self('literal', array($literal));
  262. }
  263.  
  264. public static function greaterThanOrEqualTo($x, $y)
  265. {
  266.  
  267. }
  268.  
  269. public static function lessThanOrEqualTo($x, $y)
  270. {
  271.  
  272. }
  273.  
  274. public static function between($val, $x, $y)
  275. {
  276.  
  277. }
  278.  
  279. public static function trim($val, $spec = null, $char = null)
  280. {
  281. return new self('trim', array($val, $spec, $char));
  282. }
  283. }
Add Comment
Please, Sign In to add comment