Use Cases and Application Services
Express business actions as framework-free use cases.
What a Use Case Really Is
A use case (a.k.a. application service or interactor) captures exactly one application-specific operation: Register User, Place Order, Cancel Subscription. It coordinates entities and ports to fulfill a single intent. Crucially, it is framework-free: no Request, no Response, no global helpers — just plain PHP you can call from anywhere.
Command and Result DTOs
A use case takes an immutable command DTO as input and returns a result DTO. DTOs are dumb data carriers — no behavior, no validation logic beyond shape. Readonly properties (PHP 8.1+) make them tamper-proof.
<?php
final class RegisterUserCommand
{
public function __construct(
public readonly string $email,
public readonly string $plainPassword,
) {}
}
final class RegisterUserResult
{
public function __construct(public readonly string $userId) {}
}All lessons in this course
- From Layered to Clean Architecture
- Ports and Adapters Explained
- Use Cases and Application Services
- Dependency Inversion in Practice