PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / Framework / QueryBuilder / Clauses / Where.php

Where.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.8.1, at src/Framework/QueryBuilder/Clauses/Where.php

117 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Framework\QueryBuilder\Clauses;
4
5 use Give\Framework\QueryBuilder\Types\Operator;
6 use InvalidArgumentException;
7
8 /**
9 * @since 2.19.0
10 */
11 class Where
12 {
13 /**
14 * @var string
15 */
16 public $column;
17
18 /**
19 * @var mixed
20 */
21 public $value;
22
23 /**
24 * @var string
25 */
26 public $comparisonOperator;
27
28 /**
29 * @var string
30 */
31 public $logicalOperator;
32
33 /**
34 * @var string|null
35 */
36 public $type;
37
38 /**
39 * @param string $column
40 * @param string $value
41 * @param string $comparisonOperator
42 * @param string|null $logicalOperator
43 */
44 public function __construct($column, $value, $comparisonOperator, $logicalOperator)
45 {
46 $this->column = trim($column);
47 $this->value = $value;
48 $this->comparisonOperator = $this->getComparisonOperator($comparisonOperator);
49 $this->logicalOperator = $logicalOperator ? $this->getLogicalOperator($logicalOperator) : '';
50 }
51
52 /**
53 * @param string $comparisonOperator
54 *
55 * @return string
56 */
57 private function getComparisonOperator($comparisonOperator)
58 {
59 $operators = [
60 '<',
61 '<=',
62 '>',
63 '>=',
64 '<>',
65 '!=',
66 '=',
67 Operator::LIKE,
68 Operator::NOTLIKE,
69 Operator::IN,
70 Operator::NOTIN,
71 Operator::BETWEEN,
72 Operator::NOTBETWEEN,
73 Operator::ISNULL,
74 Operator::NOTNULL
75 ];
76
77 if (!in_array($comparisonOperator, $operators, true)) {
78 throw new InvalidArgumentException(
79 sprintf(
80 'Unsupported comparison operator %s. Please use one of the supported operators (%s)',
81 $comparisonOperator,
82 implode(',', $operators)
83 )
84 );
85 }
86
87 return $comparisonOperator;
88 }
89
90 /**
91 * @param string $logicalOperator
92 *
93 * @return string
94 */
95 private function getLogicalOperator($logicalOperator)
96 {
97 $operators = [
98 Operator::_AND,
99 Operator::_OR
100 ];
101
102 $logicalOperator = strtoupper($logicalOperator);
103
104 if (!in_array($logicalOperator, $operators, true)) {
105 throw new InvalidArgumentException(
106 sprintf(
107 'Unsupported logical operator %s. Please use one of the supported operators (%s)',
108 $logicalOperator,
109 implode(',', $operators)
110 )
111 );
112 }
113
114 return $logicalOperator;
115 }
116 }
117