PHP Classes

PHP PSR HTTP Message: PSR-7 compliant HTTP request handling

Recommend this page to a friend!
  Info   View files Documentation   View files View files (13)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 61 This week: 3All time: 10,433 This week: 42Up
Version License PHP version Categories
http-message 1.0.0GNU Lesser Genera...5HTTP, PHP 5, PSR
Description 

Author

This package provides a PSR-7 compliant HTTP request handling.

It provides an implementation of the MessageInterface to process HTTP request input data, the StreamInterface to process the large data being passed to the server, and ResponseInterface to generate the request response.

Picture of Kjell-Inge Gustafsson
  Performance   Level  
Name: Kjell-Inge Gustafsson <contact>
Classes: 15 packages by
Country: Sweden Sweden
Age: ???
All time rank: 4922 in Sweden Sweden
Week rank: 33 Up1 in Sweden Sweden Up
Innovation award
Innovation award
Nominee: 6x

Documentation

Kigkonsult\Http\Message package provide PSR server-side - Message class - Stream class - Response class MESSAGE class - implements Psr\Http\Message\MessageInterface - constructor args: body, headers, protocolVersion body null|string|StreamInterface headers null|string[] protocolVersion null|string STREAM class - implements Psr\Http\Message\StreamInterface - constructor args: content, streamWrapper/resource, mode content null|string streamWrapper null|string|resource (defaults to 'php://memory') mode null|string (defaults to 'wb+') - with a (static) factory methods -- factoryFromString( [ content [, streamWrapper [, mode ]]] ) content null|string streamWrapper null|string (defaults to 'php://memory') mode null|string (defaults to 'wb+') -- factoryFromResource( resource ) resource resource RESPONSE class - extends Message - implements Psr\Http\Message\ResponseInterface Fig\Http\Message\StatusCodeInterface - constructor args: body, status, headers body null|string|resource|StreamInterface status null|int (defaults to STATUS_OK, 200) headers null|array The Response class has an added property: - rawBody -- response body (type mixed) before serialization/encoding in parallel with `ServerRequest::parsedBody` and `ServerRequest::body` with corresponding methods: - getRawBody() -- Return mixed rawBody - isRawBodyEmpty() -- Return bool true on empty rawBody - withRawBody() -- Return new instance with rawBody and two rawBody/body methods - getResponseBody() -- Return mixed rawBody if not empty body if not empty null - isBodyEmpty() -- Return bool true if (serialized/encoded) body is empty Two statusCode methods are added: - assertStatusCode() -- static, Validates statusCode, throws InvalidArgumentException on error - isBodyLessResponse() -- Return bool true on statusCode 1xx, 204 or 304 INSTALL Composer (https://getcomposer.org/), from the Command Line: composer require kigkonsult/http-master:dev-master Composer, in your `composer.json`: { "require": { "kigkonsult/http-master": "dev-master" } } Composer, acquire access ~~~~~~ <?php use Kigkonsult\Http\Message\Stream; use Kigkonsult\Http\Message\Message; use Kigkonsult\Http\Message\Response; ... include 'vendor/autoload.php'; ~~~~~~ Otherwise , download and acquire.. ~~~~~~ <?php use Kigkonsult\Http\Message\Stream; use Kigkonsult\Http\Message\Message; use Kigkonsult\Http\Message\Response; ... include 'pathToSource/http-master/autoload.php'; ~~~~~~ Copyright (c) 2019 Kjell-Inge Gustafsson, kigkonsult, All rights reserved Link https://kigkonsult.se Package http-master Version 1.0 License Subject matter of licence is the software http-message. The above copyright, link, package and version notices and this licence notice shall be included in all copies or substantial portions of the http-message. http-message is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. http-message is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with http-message. If not, see <https://www.gnu.org/licenses/>.

Details

The Kigkonsult\Http\Message package provide [PSR] server-side


> _Message_ class

> _Stream_ class

> _Response_ class

Message class
  • implements [Psr\Http\Message\MessageInterface]
  • constructor args: body, headers, protocolVersion
Stream class
  • implements [Psr\Http\Message\StreamInterface]
  • constructor args: content, streamWrapper/resource, mode
  • with a (static) factory methods * `factoryFromString( content [, streamWrapper [, mode ]] )` * `factoryFromResource( resource )`
Response class
  • extends Message
  • implements * [Psr\Http\Message\ResponseInterface] * [Fig\Http\Message\StatusCodeInterface]
  • constructor args: body, status, headers

The Response class has an added property: * rawBody * response body (type mixed) before serialization/encoding

in parallel with * (Psr\Http\Message\)ServerRequest::parsedBody * (Psr\Http\Message\)ServerRequest::body

with corresponding methods: * getRawBody() * Return rawBody * isRawBodyEmpty() * Return bool true on empty rawBody * withRawBody() * Return new instance with rawBody

and two rawBody/body methods * getResponseBody() * Return rawBody if not empty else body * isBodyEmpty() * Return bool true if (serialized/encoded) body is empty

Two statusCode methods are added:

  • `assertStatusCode()` * (static) validates statusCode, throws InvalidArgumentException on error
  • `isBodyLessResponse()` * Return bool true on statusCode 1xx, 204 or 304
Installation

[Composer], from the Command Line:

composer require kigkonsult/http-master:dev-master

Composer, in your composer.json:

{
    "require": {
        "kigkonsult/http-master": "dev-master"
    }
}

Composer, acquire access

<?php
use Kigkonsult\Http\Message\Stream;
use Kigkonsult\Http\Message\Message;
use Kigkonsult\Http\Message\Response;
...
include 'vendor/autoload.php';

Otherwise , download and acquire..

<?php
use Kigkonsult\Http\Message\Stream;
use Kigkonsult\Http\Message\Message;
use Kigkonsult\Http\Message\Response;
...
include 'pathToSource/http-master/autoload.php';

License

This project is licensed under the LGPLv3 License

[Psr]:https://github.com/php-fig/http-message [Psr\Http\Message\MessageInterface]:https://github.com/php-fig/http-message [Psr\Http\Message\StreamInterface]:https://github.com/php-fig/http-message [Psr\Http\Message\ResponseInterface]:https://github.com/php-fig/http-message [Fig\Http\Message\StatusCodeInterface]:https://github.com/php-fig/http-message-util [Composer]:https://getcomposer.org/


  Files folder image Files  
File Role Description
Files folder imagedocs (2 files)
Files folder imagesrc (4 files)
Files folder imagetest (3 files)
Accessible without login Plain text file autoload.php Aux. Auxiliary script
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  docs  
File Role Description
  Accessible without login Plain text file lgpl.txt Doc. Documentation
  Accessible without login Plain text file README.txt Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file Message.php Class Class source
  Plain text file Response.php Class Class source
  Plain text file ResponseInterface.php Class Class source
  Plain text file Stream.php Class Class source

  Files folder image Files  /  test  
File Role Description
  Plain text file MessageTest.php Class Class source
  Plain text file ResponseTest.php Class Class source
  Plain text file StreamTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:61
This week:3
All time:10,433
This week:42Up