Download the PHP package bermudaphp/psr15factory without Composer
On this page you can find all versions of the php package bermudaphp/psr15factory. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bermudaphp/psr15factory
More information about bermudaphp/psr15factory
Files in bermudaphp/psr15factory
Package psr15factory
Short Description Powerful and flexible factory for creating PSR-15 compatible middleware with automatic dependency injection and request data mapping
License MIT
Informations about the package psr15factory
Bermuda PSR-15 Factory
Languages: Русский
A powerful and flexible factory for creating PSR-15 compatible middleware in PHP. Supports various types of middleware definitions, automatic dependency injection, request data mapping, and multiple middleware patterns.
Requirements
- PHP 8.4+
- PSR-7 HTTP Message Interface
- PSR-11 Container Interface
- PSR-15 HTTP Server Request Handlers
Installation
Quick Start
Basic Setup
Controller Example
Middleware Types
1. Class Name Strategy
Resolves middleware by class name from the container:
2. Callable Strategy
Automatically detects and adapts various callable patterns. Supports multiple callable formats through built-in CallableResolver:
Supported callable formats:
1. Closures
2. Standard PHP callables
3. String representations:
-
Static class methods:
"Class::method"
-
Container service methods:
"serviceId::method"
-
Global functions:
"functionName"
- Callable services from container:
"serviceId"
4. Arrays:
-
Object and method:
[object, method]
- Service ID and method:
[serviceId, method]
Middleware patterns (automatic detection):
Single-pass middleware
Double-pass middleware
Standard callable with DI
Factory Callable
For dynamic middleware creation using the container:
Examples with different formats:
3. Pipeline Strategy and MiddlewareGroup
For combining multiple middleware into a single pipeline:
Request Data Mapping
The factory supports automatic extraction and transformation of data from PSR-7 requests into method parameters using PHP 8+ attributes. This provides clean separation between HTTP data handling and business logic.
Query parameters
The #[MapQueryParameter]
attribute extracts individual parameters from the query string:
Query string (complete parameter set)
The #[MapQueryString]
attribute extracts all query parameters with optional field renaming:
Request payload (request body)
The #[MapRequestPayload]
attribute extracts data from request body (JSON, form data, XML):
Request attributes
The #[RequestAttribute]
attribute extracts data set by previous middleware:
Combining different data sources
Mapping error handling
Configuration and DI container
Complex example with configuration
Advanced Usage
Creating custom strategy
Configuration through container
Error handling
Architecture
Main components
- MiddlewareFactory - Main factory coordinating strategies
- Strategy - Interface for middleware resolution strategies
- Adapter - Adapters for converting types to PSR-15
- Resolver - Resolvers for dependency injection
- Attribute - PHP 8+ attributes for declarative mapping
Execution flow
- Middleware resolution - Factory tries strategies in order
- Adaptation - Converting to PSR-15 MiddlewareInterface
- Dependency injection - Resolving parameters through container
- Data mapping - Extracting data from request by attributes
- Execution - Calling middleware with prepared parameters
Real-world examples
REST API controller
Middleware with dependency injection
Complex data processing
Best Practices
1. Strategy order
Register more specific strategies first:
2. Error handling
Always wrap middleware creation in try-catch:
3. Parameter typing
Use strict typing for automatic type conversion:
4. Documenting attributes
Document used attributes for clarity:
5. Configuration usage
Group related settings and use default values:
6. Service injection
Use meaningful service names in the container:
Performance
The factory is optimized for performance:
- Lazy creation - Middleware created only when needed
- Strategy caching - Strategies registered once
- Minimal reflection - Reflection used only for signature analysis
- Efficient adaptation - Minimal overhead when adapting types
Testing
License
MIT License
All versions of psr15factory with dependencies
bermudaphp/container-aware Version ^1.0.1
bermudaphp/di-resolver Version ^1.0
bermudaphp/config Version ^2.0
bermudaphp/pipeline Version ^2.1
bermudaphp/reflection Version ^2.0
psr/container Version ^2.0.2
psr/http-message Version ^2.0
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.0