Skip to content

Instantly share code, notes, and snippets.

@akky
Created December 6, 2025 11:10
Show Gist options
  • Select an option

  • Save akky/442a318a78c6bd6fdbe09f3b2246c8ea to your computer and use it in GitHub Desktop.

Select an option

Save akky/442a318a78c6bd6fdbe09f3b2246c8ea to your computer and use it in GitHub Desktop.
sample DTO for Symfony command
<?php
namespace App\Dto;
use App\Enum\City;
use Symfony\Component\Console\Attribute\Argument;
use Symfony\Component\Console\Attribute\Option;
use Symfony\Component\Validator\Constraints as Assert;
class WeatherInput
{
#[Argument(description: '天気を知りたい都市名')]
#[Assert\NotBlank(message: '都市名を入力してください。')]
#[Assert\Choice(
callback: [City::class, 'getNames'],
message: '指定された都市名は無効です。利用可能な都市名: {{ choices }}'
)]
public string $city;
#[Option(
description: '温度を華氏で表示する',
shortcut: 'f'
)]
public bool $fahrenheit = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment