chillerlan /
php-database
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Trait OnConflictTrait |
||
| 4 | * |
||
| 5 | * @filesource OnConflictTrait.php |
||
| 6 | * @created 09.01.2018 |
||
| 7 | * @package chillerlan\Database\Query |
||
| 8 | * @author Smiley <[email protected]> |
||
| 9 | * @copyright 2018 Smiley |
||
| 10 | * @license MIT |
||
| 11 | */ |
||
| 12 | |||
| 13 | namespace chillerlan\Database\Query; |
||
| 14 | |||
| 15 | trait OnConflictTrait{ |
||
| 16 | |||
| 17 | protected string $name; |
||
| 18 | protected ?string $on_conflict = null; |
||
| 19 | protected ?string $conflict_target = null; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param string $name |
||
| 23 | * @param string|null $on_conflict |
||
| 24 | * @param string|null $conflict_target |
||
| 25 | * |
||
| 26 | * @return $this |
||
| 27 | * @throws \chillerlan\Database\Query\QueryException |
||
| 28 | */ |
||
| 29 | public function name(string $name, string $on_conflict = null, string $conflict_target = null):Statement{ |
||
| 30 | $this->name = trim($name); |
||
| 31 | $on_conflict = trim(strtoupper($on_conflict)); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 32 | $conflict_target = trim(strtoupper($conflict_target)); |
||
| 33 | |||
| 34 | if(empty($this->name)){ |
||
| 35 | throw new QueryException('no name specified'); |
||
| 36 | } |
||
| 37 | |||
| 38 | if(!empty($on_conflict)){ |
||
| 39 | $this->on_conflict = $on_conflict; |
||
| 40 | } |
||
| 41 | |||
| 42 | if(!empty($conflict_target)){ |
||
| 43 | $this->conflict_target = $conflict_target; |
||
| 44 | } |
||
| 45 | |||
| 46 | return $this; |
||
| 47 | } |
||
| 48 | |||
| 49 | } |
||
| 50 |