A minimal static file middleware for PSR 15.
- php: ^8.1
- psr/http-factory: ^1.0.2
- psr/http-message: ^1.1|^2.0
- psr/http-server-handler: ^1.0.2
- psr/http-server-middleware: ^1.0.2
Through Composer as chubbyphp/chubbyphp-static-file.
composer require chubbyphp/chubbyphp-static-file "^1.3"
<?php
declare(strict_types=1);
namespace App;
use Chubbyphp\StaticFile\StaticFileMiddleware;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
/** @var ResponseFactoryInterface $responseFactory */
$responseFactory = ...;
/** @var StreamFactoryInterface $streamFactory */
$streamFactory = ...;
$app = ...;
// add the static file middleware before the routing your PSR15 based framework
$app->add(new StaticFileMiddleware(
$responseFactory,
$streamFactory,
__DIR__ . '/public'
));
2024 Dominik Zogg