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