Repository pattern

The Repository pattern isolates data access behind a class that exposes business methods such as findById or save. The rest of the application ignores SQL, which simplifies testing and lets you change storage without rewriting the logic.

Example

class UserRepository {
  public function findById(int $id): ?User { /* ... */ }
}

Related concepts

The whole glossary