Files
2026-03-26 20:22:34 +08:00

33 lines
1004 B
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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}");
}
}
}