1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Phuria SQL Builder package. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2016 Beniamin Jonatan Šimko |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Phuria\QueryBuilder\ExprBuilder; |
13
|
|
|
|
14
|
|
|
use Phuria\QueryBuilder\ExprBuilder; |
15
|
|
|
use Phuria\QueryBuilder\Expression\ConjunctionExpression; |
16
|
|
|
use Phuria\QueryBuilder\ExprNormalizer; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Beniamin Jonatan Šimko <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
trait ArithmeticTrait |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @param $connector |
25
|
|
|
* @param $expression |
26
|
|
|
* |
27
|
|
|
* @return ExprBuilder |
28
|
|
|
*/ |
29
|
|
|
abstract public function conjunction($connector, $expression); |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param mixed $expression |
33
|
|
|
* |
34
|
|
|
* @return ExprBuilder |
35
|
|
|
*/ |
36
|
1 |
|
public function add($expression) |
37
|
|
|
{ |
38
|
1 |
|
$expression = ExprNormalizer::normalizeExpression($expression); |
39
|
|
|
|
40
|
1 |
|
return $this->conjunction(ConjunctionExpression::SYMBOL_ADD, $expression); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param mixed $expression |
45
|
|
|
* |
46
|
|
|
* @return ExprBuilder |
47
|
|
|
*/ |
48
|
|
|
public function div($expression) |
49
|
|
|
{ |
50
|
|
|
$expression = ExprNormalizer::normalizeExpression($expression); |
51
|
|
|
|
52
|
|
|
return $this->conjunction(ConjunctionExpression::SYMBOL_DIV, $expression); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param mixed $expression |
57
|
|
|
* |
58
|
|
|
* @return ExprBuilder |
59
|
|
|
*/ |
60
|
|
|
public function divide($expression) |
61
|
|
|
{ |
62
|
|
|
$expression = ExprNormalizer::normalizeExpression($expression); |
63
|
|
|
|
64
|
|
|
return $this->conjunction(ConjunctionExpression::SYMBOL_DIVIDE, $expression); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param mixed $expression |
69
|
|
|
* |
70
|
|
|
* @return ExprBuilder |
71
|
|
|
*/ |
72
|
|
|
public function modulo($expression) |
73
|
|
|
{ |
74
|
|
|
$expression = ExprNormalizer::normalizeExpression($expression); |
75
|
|
|
|
76
|
|
|
return $this->conjunction(ConjunctionExpression::SYMBOL_MODULO, $expression); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param mixed $expression |
81
|
|
|
* |
82
|
|
|
* @return ExprBuilder |
83
|
|
|
*/ |
84
|
|
|
public function multiply($expression) |
85
|
|
|
{ |
86
|
|
|
$expression = ExprNormalizer::normalizeExpression($expression); |
87
|
|
|
|
88
|
|
|
return $this->conjunction(ConjunctionExpression::SYMBOL_MULTIPLY, $expression); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param mixed $expression |
93
|
|
|
* |
94
|
|
|
* @return ExprBuilder |
95
|
|
|
*/ |
96
|
|
|
public function subtract($expression) |
97
|
|
|
{ |
98
|
|
|
$expression = ExprNormalizer::normalizeExpression($expression); |
99
|
|
|
|
100
|
|
|
return $this->conjunction(ConjunctionExpression::SYMBOL_SUBTRACT, $expression); |
101
|
|
|
} |
102
|
|
|
} |