Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Fatfree Psr7 Laravel Package

f3-factory/fatfree-psr7

PSR-7 HTTP message implementation for the Fat-Free Framework (F3). Provides request/response and stream factories to bridge F3 apps with PSR-7 compatible middleware and libraries, helping standardize HTTP handling without leaving the F3 ecosystem.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package via Composer:

composer require f3-factory/fatfree-psr7

In your F3 application (index.php or bootstrap file), import the RequestFactory and ResponseFactory classes. Use them early in the request lifecycle—after F3 has populated its global state ($_GET, $_POST, etc.)—to generate PSR-7 objects:

$f3 = require 'lib/base.php';

use FatFreePSR7\RequestFactory;
use FatFreePSR7\ResponseFactory;

$request  = (new RequestFactory())->createFromF3();
$response = (new ResponseFactory())->create();

Your first practical use case: passing $request into middleware stacks (e.g., slim/psr7-compatible routing or authentication middleware) that expect a ServerRequestInterface.

Implementation Patterns

  • Middleware Integration: Use RequestFactory to wrap incoming F3 requests into PSR-7 objects for libraries like nyholm/psr7, guzzlehttp/psr7, or Slim’s PSR-7 bridge. Example:
    $psrRequest = (new RequestFactory())->createFromF3();
    $psrResponse = $someMiddleware($psrRequest, new Response());
    // Map back to F3 response if needed
    $f3->set('response.body', $psrResponse->getBody());
    $f3->status($psrResponse->getStatusCode());
    
  • Testability: In unit tests, construct ServerRequestInterface instances programmatically instead of relying on F3 globals:
    $request = (new RequestFactory())->createServerRequest('GET', '/api/users', ['HTTP_HOST' => 'example.com']);
    
  • Hybrid Routing: Wrap legacy F3 route callbacks to accept PSR-7 interfaces while slowly migrating logic:
    $f3->route('GET /users', function() {
      $request  = (new RequestFactory())->createFromF3();
      $response = $this->userController->listUsers($request);
      return $response->getBody();
    });
    
  • HTTP Clients: Feed PSR-7 requests into Symfony HttpClient, Guzzle, or custom clients that accept PSR-7 interfaces.

Gotchas and Tips

  • Timing matters: Call createFromF3() after F3’s boot process populates its internal $_GET, $_POST, $_COOKIE, etc. Calling too early (e.g., before $f3->run()) may yield incomplete data.
  • Header case sensitivity: F3 normalizes header names to lowercase, but PSR-7 implementations are case-insensitive per spec. Avoid comparing headers directly by string; use getHeaderLine() consistently.
  • Response body handling: PSR-7 responses are immutable. If you mutate $response (e.g., $response->withStatus(404)), ensure you assign the result back:
    $response = $response->withStatus(404); // correct
    
  • Streaming large uploads: createFromF3() reads php://input fully into memory. For large payloads, implement a custom StreamFactory or stream the raw php://input yourself.
  • Extend factories: Override factory behavior by extending RequestFactory/ResponseFactory—e.g., inject custom UriFactory for F3’s BASE-aware URI building.
  • Debugging tip: Use var_dump($request->getHeaders()) in development to inspect how F3 globals map to headers (e.g., HTTP_X_FORWARDED_PROTOuri->getScheme()).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport