From.php
4 years ago
Having.php
4 years ago
Join.php
4 years ago
JoinCondition.php
4 years ago
MetaTable.php
4 years ago
OrderBy.php
4 years ago
RawSQL.php
4 years ago
Select.php
4 years ago
Union.php
4 years ago
Where.php
4 years ago
Join.php
63 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\QueryBuilder\Clauses; |
| 4 | |
| 5 | use Give\Framework\QueryBuilder\QueryBuilder; |
| 6 | use Give\Framework\QueryBuilder\Types\JoinType; |
| 7 | use InvalidArgumentException; |
| 8 | |
| 9 | /** |
| 10 | * @since 2.19.0 |
| 11 | */ |
| 12 | class Join |
| 13 | { |
| 14 | /** |
| 15 | * @var string |
| 16 | */ |
| 17 | public $table; |
| 18 | |
| 19 | /** |
| 20 | * @var string |
| 21 | */ |
| 22 | public $joinType; |
| 23 | |
| 24 | /** |
| 25 | * @var string|null |
| 26 | */ |
| 27 | public $alias; |
| 28 | |
| 29 | /** |
| 30 | * @param string $table |
| 31 | * @param string $joinType \Give\Framework\QueryBuilder\Types\JoinType |
| 32 | * @param string|null $alias |
| 33 | */ |
| 34 | public function __construct($joinType, $table, $alias = null) |
| 35 | { |
| 36 | $this->table = QueryBuilder::prefixTable($table); |
| 37 | $this->joinType = $this->getJoinType($joinType); |
| 38 | $this->alias = trim($alias); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @param string $type |
| 43 | * |
| 44 | * @return string |
| 45 | */ |
| 46 | private function getJoinType($type) |
| 47 | { |
| 48 | $type = strtoupper($type); |
| 49 | |
| 50 | if (array_key_exists($type, JoinType::getTypes())) { |
| 51 | return $type; |
| 52 | } |
| 53 | |
| 54 | throw new InvalidArgumentException( |
| 55 | sprintf( |
| 56 | 'Join type %s is not supported. Please provide one of the supported join types (%s)', |
| 57 | $type, |
| 58 | implode(',', JoinType::getTypes()) |
| 59 | ) |
| 60 | ); |
| 61 | } |
| 62 | } |
| 63 |