PHPackages                             agungsugiarto/mini-framework - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. agungsugiarto/mini-framework

ActiveLibrary[Framework](/categories/framework)

agungsugiarto/mini-framework
============================

The PHP Mini Framework.

9.x-dev(3y ago)116MITPHPPHP ^8.0.2CI passing

Since Dec 28Pushed 11mo agoCompare

[ Source](https://github.com/agungsugiarto/mini-framework)[ Packagist](https://packagist.org/packages/agungsugiarto/mini-framework)[ Docs](https://lumen.laravel.com)[ RSS](/packages/agungsugiarto-mini-framework/feed)WikiDiscussions 3.x Synced 1w ago

READMEChangelogDependencies (36)Versions (4)Used By (0)

PHP Mini Framework
==================

[](#php-mini-framework)

[![Latest Version on Packagist](https://camo.githubusercontent.com/fc627f70f66aeb5d8ed1d6a2835c47a514c35fb084a7e7fba90f670b3bd8893d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6167756e67737567696172746f2f6d696e692d6672616d65776f726b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/agungsugiarto/mini-framework)[![GitHub Tests Action Status](https://camo.githubusercontent.com/c99ef76c55718fd6c2f11d776760138f60977e0d47f7fef4b8e161f14add17de/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6167756e67737567696172746f2f6d696e692d6672616d65776f726b2f74657374732e796d6c3f6272616e63683d332e78266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/agungsugiarto/mini-framework/actions?query=workflow%3Atests+branch%3A3.x)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/a07b169ab8732a9bbc59bb92a1363adaefadfba9aab04023bec4027eae47cc6c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6167756e67737567696172746f2f6d696e692d6672616d65776f726b2f70687063732e796d6c3f6272616e63683d332e78266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/agungsugiarto/mini-framework/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3A3.x)[![Total Downloads](https://camo.githubusercontent.com/6f2548f315a2944b02d9c023e196a861a878e62783525f8d26b04b274be688da/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6167756e67737567696172746f2f6d696e692d6672616d65776f726b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/agungsugiarto/mini-framework)[![MIT License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

PHP Mini Framework is a fast and lightweight micro-framework for building web applications with expressive and elegant syntax. This framework is a fork of Laravel Lumen that has been specifically modified and enhanced with modern PSR standards implementation, with a unique focus on seamless PSR-15 middleware integration using Laravel Pipeline as its dispatcher. This innovative approach delivers optimal performance while maintaining developer-friendly experience and universal middleware compatibility for modern PHP applications.

Table of Contents
-----------------

[](#table-of-contents)

- [Framework Architecture](#framework-architecture)
- [MiddlewareTransformer: The Core](#middlewaretransformer-the-core)
- [Installation and Usage](#installation-and-usage)
- [Testing and Quality Assurance](#testing-and-quality-assurance)
- [Documentation and Resources](#documentation-and-resources)
- [Community &amp; Support](#community--support)
- [License](#license)

Framework Architecture
----------------------

[](#framework-architecture)

### PSR Standards Implementation

[](#psr-standards-implementation)

Modern PSR standards implementation for interoperability (PSR-3, 7, 11, 15):

- **PSR-3**: Logger Interface with Monolog integration for systematic logging
- **PSR-7**: HTTP Message Interface (ServerRequest/Response) for standard HTTP communication
- **PSR-11**: Container Interface with auto-wiring for dependency injection
- **PSR-15**: HTTP Server Request Handlers &amp; Middleware for processing pipeline

### Core Architecture

[](#core-architecture)

1. **Application**: Integrated PSR-15 RequestHandler + PSR-11 Container
2. **HTTP Layer**: PSR-7 messages with Laravel-style helpers for development ease
3. **Routing**: Fast nikic/fast-route with intelligent auto-response transformation
4. **Middleware**: PSR-15 pipeline with smart parameter injection and Laravel Pipeline as dispatcher

### Key Features

[](#key-features)

**Middleware with Auto Parameter Injection:**

```
// Zero-config parameter injection for middleware
'middleware' => 'throttle:60,1|cache:3600,redis'

class ThrottleMiddleware implements MiddlewareInterface {
    public function __construct(
        private int $maxAttempts,    // Auto: 60
        private int $decayMinutes    // Auto: 1
    ) {}
}
```

**Smart Response Transformation:**

```
return $user;                    // Model → JSON 201
return ['data' => $users];       // Array → JSON
return "Hello World";            // String → HTML
```

### MiddlewareTransformer: The Core Innovation

[](#middlewaretransformer-the-core-innovation)

Mini Framework's `MiddlewareTransformer` bridges PSR-15 middleware with Laravel Pipeline, enabling seamless integration of any PSR-15 middleware within Laravel's familiar ecosystem.

**Core Transform Method:**

```
public function transform(array $middlewares): array
{
    return array_map(function ($middleware) {
        return function (RequestInterface $request, Closure $next) use ($middleware) {
            return $this->resolveMiddleware($middleware)->process(
                $request,
                new PipelineRequestHandler($next)
            );
        };
    }, $middlewares);
}
```

**How the Transform Process Works:**

1. **Input**: Array of middleware definitions (strings, classes, instances)

    ```
    ['auth:api', 'throttle:60,5', CustomMiddleware::class]
    ```
2. **Transform Output**: Array of Laravel Pipeline-compatible closures

    ```
    [
        // Auth middleware closure with parameter
        function($request, $next) {
            return (new AuthMiddleware('api'))->process(
                $request,
                new PipelineRequestHandler($next)
            );
        },

        // Throttle middleware closure with parameters
        function($request, $next) {
            return (new ThrottleMiddleware(60, 5))->process(
                $request,
                new PipelineRequestHandler($next)
            );
        },

        // Custom middleware closure
        function($request, $next) {
            return (new CustomMiddleware())->process(
                $request,
                new PipelineRequestHandler($next)
            );
        }
    ]
    ```
3. **Pipeline Execution**: Laravel Pipeline processes each closure sequentially

    ```
    $pipeline = new Pipeline($container);
    $response = $pipeline
        ->send($request)
        ->through($transformedMiddlewares)  // Our closures
        ->then(fn (ServerRequestInterface $request): ResponseInterface => $then($request));
    ```

**The Bridge Mechanism:**

- Each closure receives Laravel Pipeline's `($request, $next)` signature
- `PipelineRequestHandler` converts `$next` closure to PSR-15 `RequestHandlerInterface`
- PSR-15 middleware's `process()` method is called with proper interfaces
- Response flows back through the pipeline chain

**PipelineRequestHandler - The Bridge:**

```
class PipelineRequestHandler implements RequestHandlerInterface
{
    public function __construct(private Closure $next) {}

    public function handle(ServerRequestInterface $request): ResponseInterface
    {
        return ($this->next)($request);  // Calls Laravel Pipeline's $next
    }
}
```

This simple adapter class enables PSR-15 middleware to call the next middleware in Laravel Pipeline by:

1. **Wrapping** Laravel's `$next` closure in PSR-15 `RequestHandlerInterface`
2. **Converting** Pipeline's `$next($request)` call to PSR-15's `$handler->handle($request)`
3. **Maintaining** the middleware chain flow without breaking either standard

**Smart Parameter Injection:**

```
// Definition: 'throttle:100,5'
// Resolves to: new ThrottleMiddleware(100, 5)
class ThrottleMiddleware implements MiddlewareInterface {
    public function __construct(private int $maxAttempts, private int $decayMinutes) {}

    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        // Your throttling logic here
        return $handler->handle($request);
    }
}
```

**Key Benefits:**

- **Universal Compatibility**: Any PSR-15 middleware works instantly
- **Pipeline Integration**: Maintains Laravel's familiar middleware execution flow
- **Smart Resolution**: Auto-injection with reflection and container integration
- **Performance Optimized**: Minimal overhead with efficient closure transformation

### PSR-15 Middleware Examples

[](#psr-15-middleware-examples)

**Basic Middleware:**

```
class CustomMiddleware implements MiddlewareInterface {
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $request = $request->withAttribute('processed_at', time());
        $response = $handler->handle($request);
        return $response->withHeader('X-Processed-By', 'CustomMiddleware');
    }
}
```

**Parameterized Middleware:**

```
class ThrottleMiddleware implements MiddlewareInterface {
    public function __construct(private int $maxAttempts, private int $decayMinutes) {}

    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        // Throttling logic with injected parameters
        if ($this->exceedsLimit($request)) {
            return new JsonResponse(['error' => 'Too many requests'], 429);
        }
        return $handler->handle($request);
    }
}
// Usage: 'throttle:100,5' auto-injects maxAttempts=100, decayMinutes=5
```

### Performance and Optimization

[](#performance-and-optimization)

- **Lightweight**: Minimal overhead compared to full Laravel framework
- **Fast Routing**: nikic/fast-route + optimal auto-response transformation
- **Smart Middleware**: PSR-15 bridge with parameter injection for maximum flexibility
- **Exception Safe**: Bulletproof pipeline execution with proper error handling
- **Terminable Lifecycle**: Full support for middleware termination cleanup

### Core Dependencies

[](#core-dependencies)

Core libraries used:

- [`laminas/diactoros`](https://github.com/laminas/laminas-diactoros) - PSR-7 HTTP message implementation
- [`nikic/fast-route`](https://github.com/nikic/FastRoute) - High-performance router
- [`illuminate/*`](https://github.com/illuminate) - Laravel components (Container, Pipeline, etc.)
- [`spatie/ignition`](https://github.com/spatie/ignition) - Advanced error handling and debugging

### What Makes Mini Framework Special?

[](#what-makes-mini-framework-special)

**PSR-15 Bridge with Laravel Pipeline** - Seamlessly use any PSR-15 middleware within Laravel's pipeline ecosystem without compatibility issues.

**Smart Parameter Injection** - Auto-inject constructor parameters from middleware definitions using reflection with performance caching.

**Universal Middleware Compatibility** - Compatible with all existing PSR-15 middleware libraries, enabling code reuse across different frameworks.

Installation and Usage
----------------------

[](#installation-and-usage)

### System Requirements

[](#system-requirements)

- PHP 8.1 or higher
- Composer for dependency management

### Installation Methods

[](#installation-methods)

#### Create New Application (Recommended)

[](#create-new-application-recommended)

```
# Create new application from starter template
composer create-project agungsugiarto/mini-application my-app
cd my-app
```

#### Install Framework Only

[](#install-framework-only)

```
# Install framework as dependency
composer require agungsugiarto/mini-framework
```

### Environment Configuration

[](#environment-configuration)

```
# Create environment file
cp .env.example .env

# Configure database and other settings in .env
APP_ENV=local
APP_DEBUG=true
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=mini_framework
```

### Quick Start - Simple Application

[](#quick-start---simple-application)

```
