/symfony-hexagonal:symfony-validationfrom symfony-hexagonal
Validates Symfony applications using a 3-layer hexagonal architecture: presentation DTOs with #[MapRequestPayload], application commands via Messenger middleware, and domain invariants in value objects. Covers custom constraints, validation groups, and #[ExtendsValidationFor].
Ships in symfony-hexagonal. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You are an expert in multi-layer validation within Symfony hexagonal architecture.
| Feature | Requires | Fallback |
|---|---|---|
#[MapRequestPayload] / #[MapQueryString] auto-validation | Symfony 6.3 | manual ValidatorInterface::validate() |
Named-argument constraints Length(min: 2) | all versions; arrays removed in 8.0 | - |
| Custom constraint with named-argument constructor | required for 8.0 (arrays deprecated 7.3) | same code works on 6.4 |
#[ExtendsValidationFor(Target::class)] | Symfony 7.4 | validate a Request DTO / Command instead |
When(..., otherwise: [...]) | Symfony 7.3 | two constraints with groups |
Where: Request DTOs in Presentation/{Module}/API/Request/
What: Format validation: is the input well-formed?
How: Constraints on the DTO + #[MapRequestPayload] (422 on failure)
namespace App\Presentation\User\API\Request;
use Symfony\Component\Validator\Constraints as Assert;
final readonly class RegisterUserRequest
{
public function __construct(
#[Assert\NotBlank]
#[Assert\Email]
public string $email = '',
#[Assert\NotBlank]
#[Assert\Length(min: 2, max: 100)]
public string $name = '',
#[Assert\NotBlank]
#[Assert\Length(min: 8)]
#[Assert\Regex(pattern: '/[A-Z]/', message: 'Must contain uppercase')]
#[Assert\Regex(pattern: '/[0-9]/', message: 'Must contain a number')]
public string $password = '',
) {
}
}
// Controller
public function register(#[MapRequestPayload] RegisterUserRequest $request): JsonResponse
Where: Command/Query classes, validated by the Messenger validation middleware
What: Use-case pre-checks: are the values acceptable for this use case (including checks that need ports, e.g. uniqueness)?
How: Symfony Validator constraints on command properties
final readonly class RegisterUser
{
public function __construct(
#[Assert\NotBlank]
#[Assert\Email]
#[UniqueEmail]
public string $email,
#[Assert\NotBlank]
public string $name,
#[Assert\NotBlank]
public string $plainPassword,
) {
}
}
The validation middleware validates before handler execution and throws Messenger\Exception\ValidationFailedException (mapped to 422 by ApiExceptionSubscriber). Commands dispatched from CLI, Scheduler or other handlers are validated too, which is why this layer exists even with Layer 1.
Where: Entity constructors/factories, value objects, business methods
What: Business invariants: is the operation valid in domain context?
How: Pure PHP checks, throw domain exceptions (no #[Assert] attributes in Domain)
// Value object self-validates
final readonly class Email
{
public function __construct(public string $value)
{
if (filter_var($value, FILTER_VALIDATE_EMAIL) === false) {
throw InvalidEmailException::forValue($value);
}
}
}
// Entity protects invariants
final class Order
{
public function cancel(string $reason, \DateTimeImmutable $now): void
{
if (!$this->status->canTransitionTo(OrderStatus::CANCELLED)) {
throw InvalidOrderTransitionException::from($this->id->value, $this->status, OrderStatus::CANCELLED);
}
// ...
}
}
See references/ for detailed guides:
validation-layers.md - Full examples for each layer, custom constraints, #[ExtendsValidationFor], groups, pre-6.3 fallbackWhat SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub aligundogdu/symfony-hexagonal-skill --plugin symfony-hexagonal10 skills in this plugin
/symfony-api-responseSymfony REST API response standard {result, error, extra, status}: thin controllers, #[MapRequestPayload] / #[MapQueryString] request DTOs, ApiResponseTrait, exception subscriber that unwraps Messenger HandlerFailedException, validation error format, debug mode. Use when: API, endpoint, controller, response, error handling, JSON, REST, API response, exception subscriber, HTTP, request DTO/symfony-cqrs-handlersSymfony CQRS with Messenger: commands, queries, handlers, command.bus / query.bus / event.bus configuration, typed bus wrappers, HandlerFailedException unwrapping, read ports and pagination, use cases. Works on Symfony 6.4, 7.x, 8.x. Use when: command, query, handler, CQRS, bus, use case, command handler, query handler, message bus, HandleTrait, HandledStamp/symfony-doctrine-persistenceDoctrine persistence for Symfony hexagonal architecture (ORM 2.x/3.x, DBAL 3/4, DoctrineBundle 2/3): repository adapters, XML mapping in Infrastructure, embeddables, enums, custom DBAL types, native lazy objects, migrations, transactions, read models with DBAL QueryBuilder, strict no-native-SQL rule. Use when: doctrine, repository, persistence, database, mapping, migration, ORM, entity manager, DBAL, transaction, query builder, pagination/symfony-domain-modelingSymfony DDD domain modeling in pure PHP: entities, aggregates, value objects, domain events, domain exceptions, ID generation ports, PHP 8.2-8.5 modeling features (readonly, private(set), clone with). Use when: entity, value object, domain event, aggregate, domain exception, domain model, domain logic, business rule, invariant, enum status/symfony-hexagonal-architectureSymfony hexagonal architecture (ports & adapters) setup for Symfony 6.4 LTS, 7.4 LTS and 8.x: project structure, module scaffolding, layer responsibilities, dependency rules, version compatibility, progressive refactoring of legacy code. Use when: architecture, module, layer, hexagonal, scaffold, project structure, directory structure, new project, new module, bounded context, deptrac, Symfony version, upgrade/symfony-messenger-asyncSymfony Messenger async processing and Symfony Scheduler instead of cron: transports, routing (#[AsMessage] 7.2+), retry with backoff and jitter, failure transport, idempotency keys, DeduplicateStamp (7.3+), workers, supervisor, scheduled commands with stateful/locked schedules. Use when: messenger, async, queue, retry, scheduler, background job, worker, transport, message queue, cron, scheduled task, idempotency, deduplicationOther plugins' skills for the same job