Download the PHP package componenta/interceptor without Composer

On this page you can find all versions of the php package componenta/interceptor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package interceptor

Componenta Interceptor

PHP 8.4+ License MIT

Middleware-style interceptor pipeline for PHP callables. Wrap any function, method or closure with cross-cutting logic (logging, caching, transactions, authorization, serialization) declared either via pipe() or method-level attributes.

Русская документация

Installation

Requirements

Related Packages

Package Why it matters here
componenta/di Invokes callables and resolves missing parameters before interceptors run.
componenta/reflection Reads callable reflection and method attributes lazily.
componenta/config Registers context factories and attribute interceptors.
componenta/interceptor-app Prepares native attribute metadata through app:build.
componenta/serialize-interceptor Ready-made result serialization interceptor backed by Symfony Serializer.
componenta/http-respond-interceptor Ready-made HTTP interceptor that wraps results into PSR-7 responses.
componenta/http-paginate-interceptor Ready-made HTTP interceptor for PaginatorInterface -> ResourcePaginator.
componenta/pipeline Similar chain idea for PSR-15 HTTP middleware; this package wraps arbitrary PHP callables.

Quick Start

Core Concepts

Interceptor

A class implementing InterceptorInterface. Receives the execution context and a continuation handler; may act before/after, short-circuit, or transform the result.

Context

Immutable object carrying the callable, its parameters, arbitrary attributes, and a lazily-resolved reflector. Mutators return new instances:

Pipeline

InterceptingExecutor composes interceptors into a pre-built chain on first use. Execution order is FIFO — the first registered interceptor is outermost (runs first in the call direction, last on unwind):

pipe() returns a new immutable pipeline:

Short-circuit

An interceptor may return without invoking the handler (auth rejections, cache hits, maintenance screens). The pipeline stops, and the value bubbles back through outer interceptors.

Attributes

Declare interceptors on methods via #[Intercept]:

Resolution is driven by AttributeInterceptor (register it once in your pipeline). The interceptor instance is built via FactoryInterface with the declared params. Attributes are read as layers wrapped around the method, from outside in — the topmost attribute is the outermost layer (enters first, returns last), the bottommost attribute is closest to the method body.

Put entry-side interceptors (authorization, rate limits, caching gates) above result-side ones (response formatting, serialization, pagination). The method's return value flows outward through the inner layers first, so a serializer placed below a response wrapper gets the raw value and passes the serialized string up to the wrapper:

Attribute classes can also implement InterceptorInterface directly — they are instantiated through native PHP attribute construction:

Scopes

Restrict where an interceptor runs by implementing Componenta\Scope\ScopedInterface on the attribute or on the interceptor instance:

The integrator signals the current scope by setting a context attribute before the pipeline runs:

Attribute-level scope takes priority over instance-level scope and is checked before resolving the interceptor's dependencies. Interceptors without either ScopedInterface always match.

Built-in scopes: HTTP, CONSOLE, GRPC, QUEUE, WEBSOCKET. Custom scopes can be represented by Componenta\Scope\ScopeName or by a package-specific enum implementing Componenta\Scope\ScopeInterface.

Callback Interceptors

Build interceptors from closures without dedicated classes:

Parameter Resolution

Register ParameterResolvingInterceptor to enrich the callable's parameters through DI before downstream interceptors see them:

This lets attribute interceptors read resolved arguments (e.g., $ctx->parameters for cache keys).

Parameter attributes run once during this preparation. The terminal passes prepared arguments through the configured executor using DI's PreparedCallable adapter, including changes made by downstream interceptors. Executor decoration still runs; nested InterceptingExecutor instances retain the original callable and its method attributes. Changing context attributes does not repeat preparation. Nested parameter-resolving interceptors reuse the prepared arguments.

Reading, updating and removing a prepared fixed parameter by name or position address the same argument. Explicit null parameters and context attributes remain null even when a fallback is supplied; the fallback applies only to absent keys.

PreparedCallable is recognized by call(), handle() and intercept(), including contexts created by CallableContextFactory. Nested adapters are unwrapped to the original callable. These entry points preserve context attributes and the original callable metadata without resolving its parameters again.

PreparedCallable arguments follow native PHP binding: integer keys bind in insertion order, while string keys bind by name. Untouched arguments retain native binding errors. Editing parameters through the context switches to logical name/position binding, so removing a fixed argument preserves the positions of its neighbours.

Prepared parameters are final invocation values: updates by name or position replace the corresponding argument, and omitted optional arguments use PHP defaults. DI does not refill arguments removed after preparation. Replacing the callable with withCallable() starts ordinary DI resolution for the new target. A pipeline without ParameterResolvingInterceptor continues to invoke its target through the configured DI executor.

Caching

AttributeInterceptor caches native ReflectionAttribute metadata for stable method and function signatures. Every invocation constructs fresh attribute arguments and attributes via ReflectionAttribute::newInstance(), then calls FactoryInterface::make() for Intercept declarations. Scope selection is evaluated on those fresh instances.

Declarations whose attribute classes are not yet available are rechecked on later invocations; incomplete classification is not retained in the metadata cache.

Explicit interceptor instances passed to InterceptingExecutor or pipe() retain their normal application-defined lifetime. Attributed interceptors do not share mutable state between invocations. Closures are not retained in the metadata cache.

componenta/interceptor-app prepares a plain array of attribute positions through app:build. The map avoids repeated classification of attribute classes and can skip attribute reads for methods without interceptors. PHP remains responsible for argument construction, attribute targets and repeatability. Runtime works without this artifact.

Version 3 uses DI 5 and Config 3. The old COMPILED_INTERCEPTORS, COMPILED_INTERCEPTORS_FILE, CACHE_VERSION keys and descriptor-array constructor argument are removed. App integration owns the optional interceptors.map_file setting. The old weak-terminal chain cache is removed.

Container Wiring

Register the module's ConfigProvider in your application:

It binds CallableContextFactory, AttributeInterceptor, and PipelineInterface. The PipelineInterface service is intended for HTTP route handler execution and is built by HttpInterceptorPipelineFactory:

  1. ParameterResolvingInterceptor is always registered first, so callable parameters are resolved through DI before application interceptors run.
  2. Additional interceptors are read from ConfigKey::HTTP_INTERCEPTORS.
  3. Each configured item may be a container service id or an InterceptorInterface instance.

Typical HTTP configuration:

componenta/router-app consumes PipelineInterface when it executes route handlers. Applications usually configure the interceptor list in their src/ConfigProvider.php.

License

MIT


All versions of interceptor with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
componenta/config Version ^3.0.0
componenta/di Version ^5.0.0
componenta/reflection Version ^2.0.1
componenta/scope Version ^1.0
psr/container Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package componenta/interceptor contains the following files

Loading the files please wait ...