$columns The columns to constraint. * @param array|null $length The length of the columns, if applicable. */ public function __construct( protected string $name, protected array $columns, protected ?array $length = null, ) { $this->type = self::UNIQUE; } /** * Sets the constraint columns. * * @param array|string $columns Columns * @return $this */ public function setColumns(string|array $columns) { $this->columns = (array)$columns; return $this; } /** * Gets the constraint columns. * * @return ?array */ public function getColumns(): ?array { return $this->columns; } /** * Sets the constraint type. * * @param string $type Type * @return $this */ public function setType(string $type) { $this->type = $type; return $this; } /** * Gets the constraint type. * * @return string */ public function getType(): string { return $this->type; } /** * Sets the constraint name. * * @param string $name Name * @return $this */ public function setName(string $name) { $this->name = $name; return $this; } /** * Gets the constraint name. * * @return ?string */ public function getName(): ?string { return $this->name; } /** * Sets the constraint length. * * In MySQL unique constraints can have limit clauses to control the number of * characters indexed in text and char columns. * * @param array $length array of length values * @return $this */ public function setLength(array $length) { $this->length = $length; return $this; } /** * Gets the constraint length. * * Can be an array of column names and lengths under MySQL. * * @return array|null */ public function getLength(): ?array { return $this->length; } /** * Converts a constraint to an array that is compatible * with the constructor. * * @return array */ public function toArray(): array { return [ 'name' => $this->name, 'type' => $this->type, 'columns' => $this->columns, 'length' => $this->length, ]; } }