composer and ecosystem

Common PSRs

Several PSRs recur in modern PHP applications. A junior developer does not need to memorise every method, but should recognise what problem each standard solves.

Common Contracts

PSR-3 covers logging interfaces. PSR-4 describes namespace-based autoloading. These are widely encountered even in small applications.

PSR-6 and PSR-16 both cover caching. PSR-6 exposes cache items and gives applications more control. PSR-16 offers a smaller key-value interface that is often enough for straightforward cache reads and writes.

Several PSRs work together around HTTP:

  • PSR-7 models immutable HTTP request and response messages.
  • PSR-15 defines server-side request handlers and middleware.
  • PSR-17 defines factories for creating HTTP messages.
  • PSR-18 defines a client that sends an outgoing request and returns a response.

PSR-11 describes a dependency-injection container. Application code should usually receive dependencies directly instead of repeatedly fetching them from a container, but framework bootstrapping and package integration often use this contract.

PSR-20 defines a clock. Injecting a clock avoids hard-coding the current time deep inside business logic, which makes expiry rules easier to test.

Read Types As Clues

When an unfamiliar repository type-hints Psr\Http\Message\ServerRequestInterface, start by identifying it as an incoming PSR-7 request. If middleware implements Psr\Http\Server\MiddlewareInterface, trace the PSR-15 pipeline. If a service receives Psr\Clock\ClockInterface, look for time-sensitive business logic.

The point is recognition, not memorisation. Read the relevant contract before implementing edge cases, and inspect the installed implementation when debugging configuration or runtime behaviour.

Practice

Practice: Map Common PSRs

Build a compact reference table that maps the common PSRs to the problem each one solves.

Requirements

  • Map each PSR to its concern.
  • Distinguish HTTP message, factory, middleware, and client roles.
  • Compare PSR-6 and PSR-16.
  • Explain why PSR-20 improves testability.
Show solution

PSR-3 covers logging and PSR-4 covers autoloading. PSR-6 and PSR-16 cover caching, with PSR-16 exposing the simpler interface. PSR-11 describes containers.

For HTTP, PSR-7 models messages, PSR-15 defines server middleware and handlers, PSR-17 creates messages, and PSR-18 sends outgoing requests. PSR-20 supplies an injectable clock so time-dependent behaviour can be tested deterministically.