An open API service indexing awesome lists of open source software.

https://github.com/yii2-extensions/psr-bridge

Transform your Yii2 applications into high-performance, PSR-compliant powerhouses.
https://github.com/yii2-extensions/psr-bridge

emitter frankenphp psr7 roadrunner stateless worker yii2 yii2-extensions

Last synced: 4 months ago
JSON representation

Transform your Yii2 applications into high-performance, PSR-compliant powerhouses.

Awesome Lists containing this project

README

          





Yii Framework

PSR bridge





PHPUnit


Mutation Testing


PHPStan


Transform your Yii2 applications into high-performance, PSR-compliant powerhouses

Supporting traditional SAPI, RoadRunner, FrankenPHP, and worker-based architectures

## Available deployment options

### High-Performance Worker Mode

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/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)

## Features


Feature Overview

### Installation

```bash
composer require yii2-extensions/psr-bridge:^0.2
```

### Quick start

#### Worker mode (FrankenPHP)

```php
safeLoad();

// production default (change to 'true' for development)
define('YII_DEBUG', $_ENV['YII_DEBUG'] ?? false);
// production default (change to 'dev' for development)
define('YII_ENV', $_ENV['YII_ENV'] ?? 'prod');

require_once dirname(__DIR__) . '/vendor/yiisoft/yii2/Yii.php';

$config = require_once dirname(__DIR__) . '/config/web/app.php';

$runner = new FrankenPHP(new Application($config));

$runner->run();
```

#### Worker mode (RoadRunner)

```php
run();
```

#### PSR-7 Conversion

```php
// Convert Yii2 request to PSR-7
$request = Yii::$app->request;
$psr7Request = $request->getPsr7Request();

// Convert Yii2 response to PSR-7
$response = Yii::$app->response;
$psr7Response = $response->getPsr7Response();

// Emit PSR-7 response
$emitter = new yii2\extensions\psrbridge\emitter\SapiEmitter();
$emitter->emit($psr7Response);
```

### Worker lifecycle defaults

In long-running workers, keep `Application` lifecycle defaults unless you have a specific requirement:

- `useSession=true`
- `syncCookieValidation=true`
- `resetUploadedFiles=true`

> [!WARNING]
> `Application::prepareForRequest()` calls `reinitializeApplication()` on each request, so values provided in the
> application config array are reapplied and take precedence over post-construction property assignments.
>
> Configure lifecycle flags in the config array when possible.

```php
$config = [
'class' => Application::class,
// disable session and cookie validation sync for stateless REST APIs; keep resetUploadedFiles=true (the default)
// unless you have a specific reason to retain uploaded file state across requests
'useSession' => false,
'syncCookieValidation' => false,
'resetUploadedFiles' => true,
];
```

### Smart Body Parsing

The bridge automatically parses incoming PSR-7 request bodies based on the `Content-Type` header and your configured
parsers (for example, `application/json`), ensuring `Yii::$app->request->post()` works seamlessly in worker mode without
extra boilerplate.

## Documentation

For detailed configuration options and advanced usage.

- ๐Ÿ“š [Installation Guide](docs/installation.md)
- โš™๏ธ [Configuration Reference](docs/configuration.md)
- ๐Ÿ’ก [Usage Examples](docs/examples.md)
- ๐Ÿงช [Testing Guide](docs/testing.md)
- ๐Ÿ› ๏ธ [Development Guide](docs/development.md)

## Package information

[![PHP](https://img.shields.io/badge/%3E%3D8.1-777BB4.svg?style=for-the-badge&logo=php&logoColor=white)](https://www.php.net/releases/8.1/en.php)
[![Yii 2.0.x](https://img.shields.io/badge/2.0.53-0073AA.svg?style=for-the-badge&logo=yii&logoColor=white)](https://github.com/yiisoft/yii2/tree/2.0.53)
[![Yii 22.0.x](https://img.shields.io/badge/22.0.x-0073AA.svg?style=for-the-badge&logo=yii&logoColor=white)](https://github.com/yiisoft/yii2/tree/22.0)
[![Latest Stable Version](https://img.shields.io/packagist/v/yii2-extensions/psr-bridge.svg?style=for-the-badge&logo=packagist&logoColor=white&label=Stable)](https://packagist.org/packages/yii2-extensions/psr-bridge)
[![Total Downloads](https://img.shields.io/packagist/dt/yii2-extensions/psr-bridge.svg?style=for-the-badge&logo=composer&logoColor=white&label=Downloads)](https://packagist.org/packages/yii2-extensions/psr-bridge)

## Quality code

[![Codecov](https://img.shields.io/codecov/c/github/yii2-extensions/psr-bridge.svg?style=for-the-badge&logo=codecov&logoColor=white&label=Coverage)](https://codecov.io/github/yii2-extensions/psr-bridge)
[![PHPStan Level Max](https://img.shields.io/badge/PHPStan-Level%20Max-4F5D95.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/yii2-extensions/psr-bridge/actions/workflows/static.yml)
[![Super-Linter](https://img.shields.io/github/actions/workflow/status/yii2-extensions/psr-bridge/linter.yml?style=for-the-badge&label=Super-Linter&logo=github)](https://github.com/yii2-extensions/psr-bridge/actions/workflows/linter.yml)
[![StyleCI](https://img.shields.io/badge/StyleCI-Passed-44CC11.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.styleci.io/repos/1019044094?branch=main)

## Our social networks

[![Follow on X](https://img.shields.io/badge/-Follow%20on%20X-1DA1F2.svg?style=for-the-badge&logo=x&logoColor=white&labelColor=000000)](https://x.com/Terabytesoftw)

## License

[![License](https://img.shields.io/badge/License-BSD--3--Clause-brightgreen.svg?style=for-the-badge&logo=opensourceinitiative&logoColor=white&labelColor=555555)](LICENSE)