NaifyDb\Schema\ColumnInfo クラス PHP 8.0+ 8.1 → readonly

カラムのメタデータを保持する値オブジェクト

describeTable() の戻り値として使う。 ドライバ間の差異を吸収し、統一されたインターフェースで情報を提供する。

使用例

$schema = $connection->describeTable('users');
$email = $schema->getColumn('email');

if ($email !== null) {
    $email->getType();
    $email->isNullable();
    $email->isPrimaryKey();
}

プロパティ

名前型説明
private $name string カラム名
private $type string データ型 (VARCHAR, INTEGER, TEXT 等)
private $size ?int サイズ (VARCHAR(255) → 255、不明なら null)
private $nullable bool NULL 許可
private $default mixed デフォルト値 (null = デフォルトなし)
private $primaryKey bool プライマリキーか
private $autoIncrement bool 自動採番か
private $comment string カラムコメント (ドライバ非対応なら空文字)
private $extra string その他の情報 (MySQL の Extra 等)
private $rawType string ドライバから返された生の型文字列

メソッド

メソッド説明
public __construct(string $name, string $type, ?int $size, bool $nullable, mixed $default, bool $primaryKey, bool $autoIncrement, string $comment, string $extra, string $rawType): カラム情報オブジェクトを生成する
public getName(): string カラム名を返す 8.4 → property hooks
public getType(): string 正規化済みのデータ型を返す 8.4 → property hooks
public getSize(): ?int 型サイズを返す 8.4 → property hooks
public isNullable(): bool NULL 許可かどうかを返す 8.4 → property hooks
public getDefault(): mixed デフォルト値を返す 8.4 → property hooks
public isPrimaryKey(): bool プライマリキー列かどうかを返す 8.4 → property hooks
public isAutoIncrement(): bool 自動採番列かどうかを返す 8.4 → property hooks
public getComment(): string カラムコメントを返す 8.4 → property hooks
public getExtra(): string ドライバー固有の追加情報を返す 8.4 → property hooks
public getRawType(): string ドライバーが返した生の型文字列を返す 8.4 → property hooks
public toArray(): array 配列に変換する
JSON 化やデバッグ表示に流しやすい素直な配列形式へ変換する。