Skip to content

Repository files navigation

PSR-7 and PSR-15 Runtime

A runtime with support for any PSR-17 compatible implementation.

If you are new to the Symfony Runtime component, read more in the main readme.

Installation

Install this runtime plus a package that provide psr/http-factory-implementation.

composer require runtime/psr-17 slim/psr7

Also update your composer.json with some extra config:

{
"require": {
"...": "..."
},
"extra": {
"runtime": {
"psr17_server_request_factory": "Slim\\Psr7\\Factory\\ServerRequestFactory""psr17_uri_factory": "Slim\\Psr7\\Factory\\UriFactory""psr17_uploaded_file_factory": "Slim\\Psr7\\Factory\\UploadedFileFactory""psr17_stream_factory": "Slim\\Psr7\\Factory\\StreamFactory"
}
}
}

Usage

This runtime is discovered automatically. You can force your application to use this runtime by defining the environment variable APP_RUNTIME.

APP_RUNTIME=Runtime\Psr17\Runtime

PSR-7

// public/index.phpusePsr\Http\Message\ServerRequestInterface;
useAny\Psr7;
require_oncedirname(__DIR__).'/vendor/autoload_runtime.php';
returnfunction (ServerRequestInterface$request) {
returnnewPsr7\Response(200, [], 'PSR-7');
};

PSR-15

// public/index.phpusePsr\Http\Server\RequestHandlerInterface;
usePsr\Http\Message\ServerRequestInterface;
usePsr\Http\Message\ResponseInterface;
useAny\Psr7;
require_oncedirname(__DIR__).'/vendor/autoload_runtime.php';
class Application implements RequestHandlerInterface {
// ...publicfunctionhandle(ServerRequestInterface$request): ResponseInterface
{
returnnewPsr7\Response(200, [], 'PSR-15');
}
}
returnfunction (array$context) {
returnnewApplication($context['APP_ENV'] ?? 'dev');
};

About

[READ ONLY]

Resources

Stars

3 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages