From.php
2 years ago
Having.php
4 years ago
Join.php
2 years ago
JoinCondition.php
4 years ago
MetaTable.php
4 years ago
OrderBy.php
4 years ago
RawSQL.php
4 years ago
Select.php
2 years ago
Union.php
4 years ago
Where.php
4 years ago
JoinCondition.php
76 lines
| 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 JoinCondition |
| 12 | { |
| 13 | /** |
| 14 | * @var string |
| 15 | */ |
| 16 | public $logicalOperator; |
| 17 | |
| 18 | /** |
| 19 | * @var string |
| 20 | */ |
| 21 | public $column1; |
| 22 | |
| 23 | /** |
| 24 | * @var mixed |
| 25 | */ |
| 26 | public $column2; |
| 27 | |
| 28 | /** |
| 29 | * @var bool |
| 30 | */ |
| 31 | public $quote; |
| 32 | |
| 33 | |
| 34 | /** |
| 35 | * @param string $logicalOperator |
| 36 | * @param string $column1 |
| 37 | * @param string $column2 |
| 38 | * @param bool $quote |
| 39 | */ |
| 40 | public function __construct($logicalOperator, $column1, $column2, $quote = false) |
| 41 | { |
| 42 | $this->logicalOperator = $this->getLogicalOperator($logicalOperator); |
| 43 | $this->column1 = trim($column1); |
| 44 | $this->column2 = trim($column2); |
| 45 | $this->quote = $quote; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @param string $operator |
| 50 | * |
| 51 | * @return string |
| 52 | */ |
| 53 | private function getLogicalOperator($operator) |
| 54 | { |
| 55 | $operator = strtoupper($operator); |
| 56 | |
| 57 | $supportedOperators = [ |
| 58 | Operator::ON, |
| 59 | Operator::_AND, |
| 60 | Operator::_OR |
| 61 | ]; |
| 62 | |
| 63 | if ( ! in_array($operator, $supportedOperators, true)) { |
| 64 | throw new InvalidArgumentException( |
| 65 | sprintf( |
| 66 | 'Unsupported logical operator %s. Please provide one of the supported operators (%s)', |
| 67 | $operator, |
| 68 | implode(',', $supportedOperators) |
| 69 | ) |
| 70 | ); |
| 71 | } |
| 72 | |
| 73 | return $operator; |
| 74 | } |
| 75 | } |
| 76 |