target = $target; $this->alias = $alias; if ($target === '' || $alias === '') { throw new RuntimeException("Bad join."); } } /** * Get a join target. A relationName or table. * A relationName is in camelCase, a table is in CamelCase. */ public function getTarget(): string { return $this->target; } /** * Get an alias. */ public function getAlias(): ?string { return $this->alias; } /** * Get join conditions. */ public function getConditions(): ?WhereItem { return $this->conditions; } public function isTable(): bool { return $this->target[0] === ucfirst($this->target[0]); } public function isRelation(): bool { return !$this->isTable(); } /** * Create. * * @param string $target * A relation name or table. A relationName should be in camelCase, a table in CamelCase. * When joining a table, conditions should be specified. * When joining a relation, conditions will be applied automatically. */ public static function create(string $target, ?string $alias = null): self { return new self($target, $alias); } /** * Create with a table target. */ public static function createWithTableTarget(string $table, ?string $alias = null): self { return self::create(ucfirst($table), $alias); } /** * Create with a relation target. Conditions will be applied automatically. */ public static function createWithRelationTarget(string $relation, ?string $alias = null): self { return self::create(lcfirst($relation), $alias); } /** * Clone with an alias. */ public function withAlias(?string $alias): self { $obj = clone $this; $obj->alias = $alias; return $obj; } /** * Clone with join conditions. */ public function withConditions(?WhereItem $conditions): self { $obj = clone $this; $obj->conditions = $conditions; return $obj; } }