GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - hackphp/http

BranchesTags
Open more actions menu

Latest commit

 

History

2 Commits
2 Commits

Folders and files

NameName
Last commit message
Last commit date
src
src
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
phpunit.xml
phpunit.xml
 
 

Repository files navigation

HackPHP Http

HackPHP Http Message. Compatible with PSR-7, PSR-15, and PSR-17

Installation

composer require hackphp/http

Usage

Middleware Request Handler

/** @var \Psr\Http\Message\ServerRequestInterface $request */
$request = (new ServerRequestFactory)->createFromSwoole($swooleRequest);

$middlewares = [
    new FirstMiddleware(),
    new SecondMiddleware(),
    function (ServerRequestInterface $request, RequestHandlerInterface $next) {
        return $next($request);
    }
];

$handler = new RequestHandler(
    $middlewares,
    $swooleResponse
);

$response = $handler->handle($request);

$response->send();

Response

// create normal response
$statusCode = 200;
$reasonPhrase = "Ok";
$response = (new ResponseFactory)->createResponse(
    $statusCode,
    $reasonPhrase
);

// create from swoole response
$response = (new ResponseFactory)->createFromSwoole($swooleResponse);

// Change the response body
$stream = (new StreamFactory)->createStream("Hack PHP");
$response = $response->withBody($stream);

// Change the status code
$response = $response->withStatus(400);

Request

// Create Request
$request = (new RequestFactory)->createRequest("GET", "/");

// Create Server Request
$request = (new ServerRequestFactory)->createServerRequest(
    "GET",
    "/",
    $_SERVER // server params
);

// Create Server Request from swoole request
$request = (new ServerRequestFactory)->createFromSwoole($swooleRequest);

Stream

// Create from string
$stream = (new StreamFactory)->createStream("Hack PHP");

// Create from file
$mode = 'r';
$stream = (new StreamFactory)->createStreamFromFile($filename, $mode);

// Create from resource
$stream = (new StreamFactory)->createStreamFromResource($resource);

Uploaded File

$file = (new UploadedFileFactory)->createUploadedFile(
    StreamInterface $stream,
    ?int $size = null,
    int $error = \UPLOAD_ERR_OK,
    ?string $clientFilename = null,
    ?string $clientMediaType = null
);

URI

// Create URI
$uri = (new UriFactory)->createUri("https://github.com/hackphp");

// Create From Swoole
$uri = (new UriFactory)->createFromSwoole($swooleRequest);

About

No description, website, or topics provided.

Resources

Readme
Activity
Custom properties

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.