$ show tuupola/server-timing-middleware
This repository implements a PSR-7 and PSR-15 compliant middleware that adds Server-Timing HTTP headers to responses for performance monitoring. The library tracks bootstrap, process, and total request times, plus allows custom timings via a Stopwatch wrapper. It includes a Doctrine DBAL QueryTimer for automatic SQL query timing. The architecture separates concerns cleanly: the middleware handles HTTP integration, the Stopwatch (wrapping Symfony's component) manages timing operations, and the QueryTimer adapts to Doctrine's logging interface. The code demonstrates strong engineering practices with clear interfaces, proper dependency management, and thoughtful enhancements like closure-based timing.
The LLM identified 2 files worth highlighting for reuse:
A self-contained wrapper around Symfony's Stopwatch that adds useful functionality like closure-based timing (automatically starts/stops timer around a closure) and manual value setting. Implements StopwatchInterface for easy mocking and only depends on Symfony Stopwatch. Demonstrates non-obvious skill in enhancing a complex library with a simpler, more flexible interface while maintaining full compatibility.
A focused implementation of Doctrine's SQLLogger interface that automatically times SQL queries using the Stopwatch. Only requires StopwatchInterface as a dependency, making it highly extractable to any project needing query timing. Exemplifies the adapter pattern by cleanly translating Doctrine's logging interface to timing concerns with minimal, purpose-built code.