Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ high-performance worker modes.

Long-running PHP workers for higher throughput and lower latency.

[![FrankenPHP](https://img.shields.io/badge/FrankenPHP-777BB4?style=for-the-badge&logo=php&logoColor=white)](https://github.com/yii2-extensions/app-basic/tree/franken-php)
[![RoadRunner](https://img.shields.io/badge/RoadRunner-%23FF6B35.svg?style=for-the-badge&logo=data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTEyIDJMMjIgMTJMMTIgMjJMMiAxMkwxMiAyWiIgZmlsbD0iI0ZGRkZGRiIvPgo8cGF0aCBkPSJNOCAyTDE2IDEwTDggMThaIiBmaWxsPSIjRkY2QjM1Ii8+CjxwYXRoIGQ9Ik0xNiA2TDIwIDEwTDE2IDE0WiIgZmlsbD0iI0ZGNkIzNSIvPgo8L3N2Zz4K&logoColor=white)](https://github.com/yii2-extensions/app-basic/tree/road-runner)
[![FrankenPHP](https://img.shields.io/badge/FrankenPHP-777BB4?style=for-the-badge&logo=php&logoColor=white)](https://github.com/yii2-extensions/franken-php)
[![RoadRunner](https://img.shields.io/badge/RoadRunner-%23FF6B35.svg?style=for-the-badge&logo=data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTEyIDJMMjIgMTJMMTIgMjJMMiAxMkwxMiAyWiIgZmlsbD0iI0ZGRkZGRiIvPgo8cGF0aCBkPSJNOCAyTDE2IDEwTDggMThaIiBmaWxsPSIjRkY2QjM1Ii8+CjxwYXRoIGQ9Ik0xNiA2TDIwIDEwTDE2IDE0WiIgZmlsbD0iI0ZGNkIzNSIvPgo8L3N2Zz4K&logoColor=white)](https://github.com/yii2-extensions/road-runner)

### Installation

Expand Down
153 changes: 153 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,161 @@

## Overview

This guide covers all configuration options for the PSR Bridge extension, from
basic setup to advanced HTTP message handling, worker mode integration, and
stateless application configuration.

## Basic configuration

### Core components setup

Replace the default Yii2 Request and Response components with PSR Bridge
enhanced versions.

```php
<?php

declare(strict_types=1);

use yii2\extensions\psrbridge\http\ErrorHandler;
use yii2\extensions\psrbridge\http\Request;
use yii2\extensions\psrbridge\http\Response;

return [
'components' => [
'request' => [
'class' => Request::class,
'enableCookieValidation' => false,
'enableCsrfValidation' => false,
],
'response' => [
'class' => Response::class,
],
'errorHandler' => [
'class' => ErrorHandler::class,
],
],
];
```

## Error handling configuration

```php
<?php

declare(strict_types=1);

use yii2\extensions\psrbridge\http\ErrorHandler;

'errorHandler' => [
'class' => ErrorHandler::class,
'errorAction' => 'site/error',
'discardExistingOutput' => true,
],
```

### Custom error views and formats

```php
<?php

declare(strict_types=1);

use yii2\extensions\psrbridge\http\ErrorHandler;

'errorHandler' => [
'class' => ErrorHandler::class,
'errorView' => '@app/views/error.php',
'exceptionView' => '@app/views/exception.php',
'callStackItemView' => '@app/views/callStackItem.php',
'displayVars' => ['_GET', '_POST', '_FILES', '_COOKIE'],
],
```

### Memory management configuration

Configure memory limits and garbage collection behavior.

```php
<?php

declare(strict_types=1);

use yii2\extensions\psrbridge\http\StatelessApplication;

$app = new StatelessApplication($config);

// Enable logger flushing (default: true)
$app->flushLogger = true;

// Memory management example
if ($app->clean()) {
// Memory usage exceeded 90% of limit
// Trigger worker restart or cleanup
exit(0);
}
```

### PSR-7 factory dependencies

Configure PSR-7 HTTP message factories for request/response conversion.

```php
<?php

declare(strict_types=1);

use HttpSoft\Message\ResponseFactory;
use HttpSoft\Message\ServerRequestFactory;
use HttpSoft\Message\StreamFactory;
use HttpSoft\Message\UploadedFileFactory;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ServerRequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UploadedFileFactoryInterface;

'container' => [
'definitions' => [
ResponseFactoryInterface::class => ResponseFactory::class,
ServerRequestFactoryInterface::class => ServerRequestFactory::class,
StreamFactoryInterface::class => StreamFactory::class,
UploadedFileFactoryInterface::class => UploadedFileFactory::class,
],
],
```

### StatelessApplication configuration

For worker-based environments (FrankenPHP, RoadRunner).

```php
<?php

declare(strict_types=1);

use yii2\extensions\psrbridge\http\Request;
use yii2\extensions\psrbridge\http\Response;
use yii2\extensions\psrbridge\http\StatelessApplication;

$config = [
'id' => 'stateless-app',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'app\\controllers',
'components' => [
'request' => [
'class' => Request::class,
'workerMode' => true,
],
'response' => [
'class' => Response::class,
],
// ... other components
],
];

$app = new StatelessApplication($config);
```

## Next steps

- 💡 [Usage Examples](examples.md)
Expand Down