Symfony Console Commands
Complete reference of all Symfony Console commands for SimpleDto.
Introduction
Section titled “Introduction”SimpleDto provides several console commands for Symfony:
- make:dto - Create new Dtos
- dto:typescript - Generate TypeScript types
- dto:list - List all Dtos
- dto:validate - Validate Dto structure
- dto:cache - Cache validation rules
- dto:clear - Clear validation cache
make:dto
Section titled “make:dto”Create a new Dto class.
Basic Usage
Section titled “Basic Usage”bin/console make:dto UserDtoCreates src/Dto/UserDto.php:
<?php
namespace App\Dto;
use event4u\DataHelpers\SimpleDto;
class UserDto extends SimpleDto{ public function __construct( public readonly int $id, public readonly string $name, ) {}}Options
Section titled “Options”—validation
Section titled “—validation”Create a Dto with validation attributes:
bin/console make:dto CreateUserDto --validationCreates:
<?php
namespace App\Dto;
use event4u\DataHelpers\SimpleDto;use event4u\DataHelpers\SimpleDto\Attributes\Required;use event4u\DataHelpers\SimpleDto\Attributes\Email;
class CreateUserDto extends SimpleDto{ public function __construct( #[Required] public readonly string $name,
#[Required, Email] public readonly string $email, ) {}}—resource
Section titled “—resource”Create a resource Dto for API responses:
bin/console make:dto UserResourceDto --resource—entity
Section titled “—entity”Create Dto from existing Doctrine entity:
bin/console make:dto UserDto --entity=User—force
Section titled “—force”Overwrite existing Dto:
bin/console make:dto UserDto --forcedto:typescript
Section titled “dto:typescript”Generate TypeScript types from Dtos.
Basic Usage
Section titled “Basic Usage”bin/console dto:typescriptGenerates TypeScript interfaces in assets/types/dtos.ts.
Options
Section titled “Options”—output
Section titled “—output”Specify output file:
bin/console dto:typescript --output=assets/types/api.ts—watch
Section titled “—watch”Watch for changes and regenerate automatically:
bin/console dto:typescript --watch—export
Section titled “—export”Specify export type:
bin/console dto:typescript --export=export # export interfacebin/console dto:typescript --export=declare # declare interfacebin/console dto:typescript --export= # no exportdto:list
Section titled “dto:list”List all Dtos in the project.
Basic Usage
Section titled “Basic Usage”bin/console dto:listOutput:
+------------------+------------------+------------+| Dto | Namespace | Properties |+------------------+------------------+------------+| UserDto | App\Dto | 5 || CreateUserDto | App\Dto\Requests | 3 || UserResourceDto | App\Dto\Resources| 7 |+------------------+------------------+------------+Options
Section titled “Options”—namespace
Section titled “—namespace”Filter by namespace:
bin/console dto:list --namespace=App\\Dto\\Apidto:validate
Section titled “dto:validate”Validate Dto structure and configuration.
Basic Usage
Section titled “Basic Usage”bin/console dto:validate UserDtoChecks:
- Class exists
- Extends SimpleDto
- Properties are readonly
- Validation attributes are valid
- Type casts are valid
- No circular dependencies
Options
Section titled “Options”Validate all Dtos:
bin/console dto:validate --allAttempt to fix common issues:
bin/console dto:validate UserDto --fixdto:cache
Section titled “dto:cache”Cache validation rules for better performance.
Basic Usage
Section titled “Basic Usage”bin/console dto:cacheCaches validation rules for all Dtos, improving validation performance by up to 198x.
Options
Section titled “Options”—clear
Section titled “—clear”Clear cache before caching:
bin/console dto:cache --cleardto:clear
Section titled “dto:clear”Clear validation rule cache.
Basic Usage
Section titled “Basic Usage”bin/console dto:clearClears all cached validation rules.
Real-World Examples
Section titled “Real-World Examples”Create API Dtos
Section titled “Create API Dtos”# Create request Dtobin/console make:dto CreateUserDto --validation
# Create response Dtobin/console make:dto UserResourceDto --resource
# Generate TypeScriptbin/console dto:typescriptDevelopment Workflow
Section titled “Development Workflow”# Create Dto from entitybin/console make:dto OrderDto --entity=Order
# Validate structurebin/console dto:validate OrderDto
# Generate TypeScript with watchbin/console dto:typescript --watchCI/CD Pipeline
Section titled “CI/CD Pipeline”# Validate all Dtosbin/console dto:validate --all
# Check TypeScript is up to datebin/console dto:typescript --check
# Cache validation rulesbin/console dto:cacheDeployment
Section titled “Deployment”# Clear old cachebin/console dto:clear
# Cache validation rulesbin/console dto:cache
# Generate TypeScriptbin/console dto:typescriptCombining Commands
Section titled “Combining Commands”Create and Validate
Section titled “Create and Validate”bin/console make:dto UserDto && bin/console dto:validate UserDtoGenerate TypeScript and Watch
Section titled “Generate TypeScript and Watch”bin/console dto:typescript --watch &Best Practices
Section titled “Best Practices”1. Use Validation in Development
Section titled “1. Use Validation in Development”# Always validate after creating Dtosbin/console make:dto UserDtobin/console dto:validate UserDto2. Cache in Production
Section titled “2. Cache in Production”# Add to deployment scriptbin/console dto:cache3. Generate TypeScript Automatically
Section titled “3. Generate TypeScript Automatically”# Add to composer.json scripts"scripts": { "post-install-cmd": [ "@php bin/console dto:typescript" ]}4. Validate in CI/CD
Section titled “4. Validate in CI/CD”# Add to CI/CD pipelinebin/console dto:validate --allbin/console dto:typescript --checkSee Also
Section titled “See Also”- Symfony Integration - Symfony integration guide
- TypeScript Generation - TypeScript generation details
- Validation - Validation guide