0PricingLogin
PHP Academy · Lesson

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

  1. From Layered to Clean Architecture
  2. Ports and Adapters Explained
  3. Use Cases and Application Services
  4. Dependency Inversion in Practice
← Back to PHP Academy