AgentSkillsCN

symfony-sk:api-dto

为表单数据创建带有验证属性的 DTO。在接收结构化输入时,此方法尤为适用。

SKILL.md
--- frontmatter
name: symfony-sk:api-dto
description: Create DTOs with validation attributes for form data. Use when receiving structured input.
allowed-tools: Read, Write, Edit, Glob, Grep

API DTO Skill

Mission

Create Data Transfer Objects with validation attributes for API input.


Location

api/src/Dto/<Feature>/<Name>Dto.php


Template

php
<?php

namespace App\Dto\<Feature>;

use StarterKit\Attribute\Dto;
use StarterKit\Attribute\StringProperty;
use StarterKit\Attribute\IntegerProperty;
use App\Attribute\DateProperty;
use App\Attribute\TimeProperty;

#[Dto(emptyError: -XXXXX)]
final class <Name>Dto
{
    #[StringProperty(emptyError: -XXXXY, invalidError: -XXXXY, mandatory: true)]
    public ?string $title = null;

    #[DateProperty(emptyError: -XXXXZ, invalidError: -XXXXZ, mandatory: true)]
    public ?\DateTime $date = null;

    #[StringProperty(emptyError: -XXXXW, invalidError: -XXXXW, mandatory: false)]
    public ?string $description = null;
}

Property Attributes

From StarterKit (StarterKit\Attribute\)

AttributePHP TypeUsage
StringProperty?stringText, lists
TextareaProperty?stringLong text
IntegerProperty?intNumbers
BooleanProperty?boolYes/No
EmailProperty?stringEmail validation
SettingProperty?stringDropdown from settings

From App (App\Attribute\)

AttributePHP TypeUsage
DateProperty?\DateTimeDate (Y-m-d)
TimeProperty?\DateTimeTime (H:i)

Common Parameters

ParameterDescription
emptyErrorError code when empty but mandatory
invalidErrorError code when format invalid
mandatoryRequired field (true/false)
hiddenHide in form
onChangeJS callback function name

Error Code Allocation

Use /error-code skill to allocate codes. Query existing codes first via vm-executor agent.

Convention -XXYZZ:

  • XX = Feature code
  • Y = Action index
  • ZZ = Unique error number (not necessarily sequential, just unique in the range)

Note: Each DTO/form needs unique codes. If a feature already has codes -28100 to -28105, the next ones could be -28106, -28107, etc.


Checklist

  • #[Dto(emptyError: -XXXXX)] on class
  • Each property has attribute with error codes
  • Error codes allocated via /error-code skill (query existing first)
  • Register form via /autoform skill