mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-02 07:52:48 +08:00
33 lines
1004 B
PHP
33 lines
1004 B
PHP
<?php
|
||
|
||
namespace base\common\scheme\attribute;
|
||
|
||
use Attribute;
|
||
|
||
#[Attribute(Attribute::TARGET_PROPERTY)]
|
||
class Field
|
||
{
|
||
public function __construct(
|
||
public string $type = 'varchar',
|
||
public ?int $length = null,
|
||
public int $precision = 0,
|
||
public int $scale = 0,
|
||
public bool $nullable = true,
|
||
public mixed $default = null,
|
||
public string $comment = '',
|
||
public bool $unsigned = false,
|
||
public bool $autoIncrement = false,
|
||
public bool $primary = false
|
||
) {
|
||
$type = strtolower(trim($this->type));
|
||
|
||
if ($this->length !== null && $this->length < 1) {
|
||
throw new \InvalidArgumentException("Scheme 字段 length 必须 >= 1,当前={$this->length}");
|
||
}
|
||
|
||
if ($type === 'char' && $this->length !== null && $this->length > 255) {
|
||
throw new \InvalidArgumentException("Scheme 字段类型 char 的 length 超出范围,允许 1-255,当前={$this->length}");
|
||
}
|
||
}
|
||
}
|