Skip to content

Event hooks for the request lifecycle #33

Open

Description

@jk

Idea

Allow users to hook into the request lifecycle without subclassing RestServer, e.g. for logging, metrics, auth or response decoration.

Possible events:

  • cache refreshed / URL map built
  • request received (before routing)
  • route resolved (controller + method known)
  • before / after controller call
  • before response is sent (allows modifying headers/body)
  • error occurred

Proposal

  • Accept an optional PSR-14 Psr\EventDispatcher\EventDispatcherInterface in the constructor; no dispatcher → no events, no new hard dependency.
  • One small immutable event class per event (instead of string constants + generic events).
  • Fits well with the planned PSR-7/PSR-15 refactoring; with a middleware architecture some of these hooks might be covered by middleware instead — decide together.

A first draft based on symfony/event-dispatcher existed on the former feature/add-event-dispatcher branch (2015), which was never merged.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions