runtime/psr-nyholm

PSR runtime with nyholm/psr7

Fund package maintenance!
nyholm

Installs: 61 390

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 3

Forks: 0

0.1.0 2021-04-29 08:57 UTC

This package is auto-updated.

Last update: 2024-11-22 14:24:43 UTC


README

A runtime with nyholm/psr-7.

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

Installation

composer require runtime/psr-nyholm

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\PsrNyholm\Runtime

PSR-7

// public/index.php

use Psr\Http\Message\ServerRequestInterface;
use Nyholm\Psr7;

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (ServerRequestInterface $request) {
    return new Psr7\Response(200, [], 'PSR-7');
};

PSR-15

// public/index.php

use Psr\Http\Server\RequestHandlerInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Nyholm\Psr7;

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

class Application implements RequestHandlerInterface {
    // ...
    public function handle(ServerRequestInterface $request): ResponseInterface
    {
        return new Psr7\Response(200, [], 'PSR-15');
    }
}

return function (array $context) {
    return new Application($context['APP_ENV'] ?? 'dev');
};