Skip to content

Symfony Console Commands

Complete reference of all Symfony Console commands for SimpleDTO.

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

Create a new DTO class.

Terminal window
bin/console make:dto UserDTO

Creates 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,
) {}
}

Create a DTO with validation attributes:

Terminal window
bin/console make:dto CreateUserDTO --validation

Creates:

<?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,
) {}
}

Create a resource DTO for API responses:

Terminal window
bin/console make:dto UserResourceDTO --resource

Create DTO from existing Doctrine entity:

Terminal window
bin/console make:dto UserDTO --entity=User

Overwrite existing DTO:

Terminal window
bin/console make:dto UserDTO --force

Generate TypeScript types from DTOs.

Terminal window
bin/console dto:typescript

Generates TypeScript interfaces in assets/types/dtos.ts.

Specify output file:

Terminal window
bin/console dto:typescript --output=assets/types/api.ts

Watch for changes and regenerate automatically:

Terminal window
bin/console dto:typescript --watch

Specify export type:

Terminal window
bin/console dto:typescript --export=export # export interface
bin/console dto:typescript --export=declare # declare interface
bin/console dto:typescript --export= # no export

List all DTOs in the project.

Terminal window
bin/console dto:list

Output:

+------------------+------------------+------------+
| DTO | Namespace | Properties |
+------------------+------------------+------------+
| UserDTO | App\DTO | 5 |
| CreateUserDTO | App\DTO\Requests | 3 |
| UserResourceDTO | App\DTO\Resources| 7 |
+------------------+------------------+------------+

Filter by namespace:

Terminal window
bin/console dto:list --namespace=App\\DTO\\Api

Validate DTO structure and configuration.

Terminal window
bin/console dto:validate UserDTO

Checks:

  • Class exists
  • Extends SimpleDTO
  • Properties are readonly
  • Validation attributes are valid
  • Type casts are valid
  • No circular dependencies

Validate all DTOs:

Terminal window
bin/console dto:validate --all

Attempt to fix common issues:

Terminal window
bin/console dto:validate UserDTO --fix

Cache validation rules for better performance.

Terminal window
bin/console dto:cache

Caches validation rules for all DTOs, improving validation performance by up to 198x.

Clear cache before caching:

Terminal window
bin/console dto:cache --clear

Clear validation rule cache.

Terminal window
bin/console dto:clear

Clears all cached validation rules.

Terminal window
# Create request DTO
bin/console make:dto CreateUserDTO --validation
# Create response DTO
bin/console make:dto UserResourceDTO --resource
# Generate TypeScript
bin/console dto:typescript
Terminal window
# Create DTO from entity
bin/console make:dto OrderDTO --entity=Order
# Validate structure
bin/console dto:validate OrderDTO
# Generate TypeScript with watch
bin/console dto:typescript --watch
Terminal window
# Validate all DTOs
bin/console dto:validate --all
# Check TypeScript is up to date
bin/console dto:typescript --check
# Cache validation rules
bin/console dto:cache
Terminal window
# Clear old cache
bin/console dto:clear
# Cache validation rules
bin/console dto:cache
# Generate TypeScript
bin/console dto:typescript
Terminal window
bin/console make:dto UserDTO && bin/console dto:validate UserDTO
Terminal window
bin/console dto:typescript --watch &
Terminal window
# Always validate after creating DTOs
bin/console make:dto UserDTO
bin/console dto:validate UserDTO
Terminal window
# Add to deployment script
bin/console dto:cache
Terminal window
# Add to composer.json scripts
"scripts": {
"post-install-cmd": [
"@php bin/console dto:typescript"
]
}
Terminal window
# Add to CI/CD pipeline
bin/console dto:validate --all
bin/console dto:typescript --check