gephart/http

Gephart HTTP Component

0.5.5 2024-06-24 13:44 UTC

This package is auto-updated.

Last update: 2024-11-24 14:31:28 UTC


README

Build Status

Dependencies

  • PHP >= 7.1
  • psr/http-message = 1.0.1

Instalation

composer require gephart/http dev-master

Using

Request:

$request = (new Gephart\Http\RequestFactory())->createFromGlobals();

Response:

<?php

use Gephart\Http\Response;
use Gephart\Http\Stream;

class JsonResponseFactory
{
    public function createResponse($content, int $statusCode = 200, $headers = [])
    {
        $body = json_encode($content);

        $stream = new Stream("php://temp", "rw");
        $stream->write($body);

        $response = new Response($stream, $statusCode, $headers);
        return $response;
    }
}

$reponse = (new JsonResponseFactory)->createResponse(["data"=>"data"]);