spiral/interceptors
Spiral Interceptors provides a lightweight interception layer for Spiral apps, enabling cross-cutting concerns (logging, caching, transactions, etc.) around method calls with strong typing and test-friendly design. Includes CI checks and static analysis support.
Start by installing the package via Composer (composer require spiral/interceptors), then register InterceptorsBootloader in your app’s bootstrap sequence. The core concept is method interception — wrapping calls to public methods (e.g., in services or controllers) to inject cross-cutting concerns like logging, caching, or retry logic. The simplest first use case is wrapping a service method to log входящие вызовы (input) and выходящие (output) data by defining an interceptor class that implements Spiral\Interceptors\InterceptorInterface, then tagging it with #[Interceptor] and attaching it to methods via attributes like #[Loggable].
Use interceptors for:
Typical workflow:
#[Cacheable]) using Spiral\Attributes\Attribute, optionally with properties like ttl or key.#[Intercept(...)] attribute on target classes/methods.InterceptedProxy or framework-provided integration (e.g., Spiral Framework’s DI container) to apply proxies where applicable.For performance-critical apps, combine interceptors with lazy initialization and ensure they are non-intrusive and stackable (support multiple interceptors per method).
bin/rebuild) are cleared after changing interceptor definitions. Production builds benefit from pre-generated proxies.yield from, __call(), or wrong typing breaks type safety.LoggerInterface inside an interceptor that itself is used during container initialization).#[Debug] or custom logging in interceptors with debug-only guards to avoid side effects in production.Spiral\Interceptors\ProviderInterface to dynamically register interceptors at runtime (e.g., based on config or environment).How can I help you explore Laravel packages today?