A minimal static file middleware for PSR 15.
- php: ^7.2
- psr/http-factory: ^1.0.1
- psr/http-message: ^1.0.1
- psr/http-server-handler: ^1.0.1
- psr/http-server-middleware: ^1.0.1
Through Composer as chubbyphp/chubbyphp-static-file.
composer require chubbyphp/chubbyphp-static-file "^1.0"<?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'
));Dominik Zogg 2020


