composer and ecosystem

PSR Standards

A PSR defines a shared convention or interface for a PHP ecosystem concern. Standards reduce coupling when libraries need to exchange requests, responses, logs, caches, containers, clocks, or autoloaded classes.

Different Kinds Of PSR

Some PSRs describe conventions. PSR-4 explains how namespaces map to autoloaded files. Others publish interfaces that packages can share. PSR-3 defines logger methods, while PSR-18 defines how an HTTP client sends requests.

An interface package is not automatically an implementation. Installing psr/log gives your code a stable type hint, but it does not decide where log messages are written. Installing psr/http-client does not provide network transport on its own.

PHP example
<?php

declare(strict_types=1);

use Psr\SimpleCache\CacheInterface;

final class ProductLookup
{
    public function __construct(private CacheInterface $cache)
    {
    }

    public function forget(string $productId): void
    {
        $this->cache->delete('product:' . $productId);
    }
}

The class can work with any correctly configured PSR-16 cache implementation. The bootstrap code is responsible for constructing one that uses Redis, Memcached, the filesystem, or another suitable store.

Read The Contract

Do not guess behaviour from an interface name. Check the contract when error handling, return values, or edge cases matter. For example, a cache miss and a stored null value need careful handling because CacheInterface::get() returns its default value when an item is missing.

Standards are useful where they reduce coupling between packages or infrastructure choices. A small internal helper with no integration boundary does not need a PSR-shaped wrapper.

Practice

Practice: Choose A PSR Boundary

Choose one real integration boundary and explain whether a PSR interface improves it.

Requirements

  • Pick a logger, HTTP client, or cache boundary.
  • Name interface and implementation roles.
  • Explain interchangeability benefit.
  • Avoid abstraction without a real integration need.
Show solution

For a cache boundary, type-hint Psr\SimpleCache\CacheInterface in the application service and configure a suitable PSR-16 implementation during bootstrap. The service can then use the contract without knowing whether the store is Redis, Memcached, or the filesystem.

Read the interface contract for edge cases such as cache misses. Do not wrap unrelated local helpers merely to introduce another abstraction.