動的モデル
動的モデルエンジンは Doggy ローコードプラットフォームの核心です。@Ef アノテーションと PHP 8 Attributes を組み合わせて業務フィールドをマークし、データベースマイグレーション、API、管理画面を自動生成します。
概要
動的モデルシステムは 2 つのコアアノテーションに基づいて構築されています:
Ef: 業務フィールドのグルーピングとメタデータ属性をマークEfGroup: フィールドグループを定義
アノテーションは src/Annotation/Ef.php と src/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
すべてのエンティティは CommonTrait(src/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)
- ワンクリックでのマイグレーション生成
- 関連関係の設定