Skip to content

動的モデル

動的モデルエンジンは Doggy ローコードプラットフォームの核心です。@Ef アノテーションと PHP 8 Attributes を組み合わせて業務フィールドをマークし、データベースマイグレーション、API、管理画面を自動生成します。

概要

動的モデルシステムは 2 つのコアアノテーションに基づいて構築されています:

  • Ef: 業務フィールドのグルーピングとメタデータ属性をマーク
  • EfGroup: フィールドグループを定義

アノテーションは src/Annotation/Ef.phpsrc/Annotation/EfGroup.php に定義されています:

php
// src/Annotation/Ef.php
class Ef
{
    public $value = [];

    public function __construct(array $data)
    {
        $this->value['group'] = $data['group'] ?? null;
        $this->value['bf'] = $data['isBF'] ?? false;
    }
}

モデルの定義

php
namespace App\Entity\Organization;

use App\Annotation\Ef;
use App\Entity\Traits\CommonTrait;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'org_department')]
class Department
{
    use CommonTrait;

    #[ORM\Id]
    #[ORM\Column(type: 'uuid', unique: true)]
    #[ORM\GeneratedValue(strategy: 'CUSTOM')]
    #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
    private $id;

    #[Ef(displayName: '部门名称', required: true)]
    #[ORM\Column(length: 100)]
    private string $name;

    #[Ef(displayName: '部门编码', searchable: true)]
    #[ORM\Column(length: 50, nullable: true)]
    private ?string $code = null;
}

エンティティ管理

管理画面の ローコードプラットフォーム → エンティティ管理App\Controller\Admin\Platform\EntityController)でエンティティを表示・管理できます:

主要エンティティディレクトリ

ディレクトリエンティティ説明
Entity/Organization/Department, Company, Corporation, Employee, Position, PositionLevel組織構造と従業員
Entity/Platform/Entity, EntityProperty, View, ViewField, DataGrid, Menu, DataSourceローコードエンジン
Entity/Security/PasswordPolicy, PasswordStrengthRule, PasswordResetMethod, WebauthnCredentialセキュリティ体系
Entity/Storage/File, StorageConfig, UploadSessionファイルストレージ
Entity/System/AuditLog, Task, TaskLog, EmailConfig, EmailTemplate, EmailLog, SystemCalendarEventインフラ基盤

CommonTrait

すべてのエンティティは CommonTraitsrc/Entity/CommonTrait.php)を通じて以下の機能を組み合わせます:

php
trait CommonTrait
{
    use SoftDeleteableEntity;    // 软删除(deletedAt 字段)
    use TimestampableEntity;     // 时间戳(createdAt, updatedAt)
    use BlameableEntity;        // 操作人(createdBy, updatedBy)

    #[ORM\ManyToOne(targetEntity: Corporation::class)]
    private $corporation;

    #[ORM\ManyToOne(targetEntity: Company::class)]
    private $company;
}

自動生成

モデルを定義すると、EfInitEntityCommand などのコマンドが自動処理します:

  • データベースマイグレーションファイルの生成
  • CRUD 画面のレンダリング
  • データ検証ルール
  • 権限チェック

管理画面

ローコードプラットフォーム → エンティティ管理/admin/platform/entity)に移動するとビジュアル操作が可能です:

  • エンティティ属性の編集(EntityProperty)
  • 属性グループの管理(EntityPropertyGroup)
  • ワンクリックでのマイグレーション生成
  • 関連関係の設定

MIT ライセンスでオープンソース | Copyright © 2026 Doggy