2017 © Pedro Peláez
 

library http-message-util

This repository holds utility classes and constants to facilitate common operations of PSR-7.

image

narrowspark/http-message-util

This repository holds utility classes and constants to facilitate common operations of PSR-7.

  • Tuesday, May 8, 2018
  • by dani33
  • Repository
  • 1 Watchers
  • 4 Stars
  • 3,541 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 21 % Grown

The README.md

Http Message Util

This repository holds utility classes and constants to facilitate common operations of PSR-7.

, (*1)

Each header class is named after the specific http header and has the following functions for parsing and signing., (*2)

Installation

$ composer require narrowspark/http-message-util

Use

Here's an example using the InteractsWithAcceptLanguage class: ``` php <?php declare(strict_types=1);, (*3)

use Narrowspark\Http\Message\Util\InteractsWithAcceptLanguage;, (*4)

$request = new Request(); $request = $request->withHeader('Accept-Language', 'zh, en-us; q=0.8, en; q=0.6');, (*5)

return InteractsWithAcceptLanguage::getLanguages($request); // => ['zh', 'en', 'en_US'], (*6)


Here's an example using the InteractsWithAuthorization class: ``` php <?php declare(strict_types=1); use Narrowspark\Http\Message\Util\InteractsWithAuthorization; $request = new Request(); $request = $request->withHeader('Authorization', 'Basic QWxhZGRpbjpPcGVuU2VzYW1l'); return InteractsWithAuthorization::getAuthorization($request); // => ['Basic', 'QWxhZGRpbjpPcGVuU2VzYW1l']

Here's an example using the InteractsWithContentTypes class:, (*7)

``` php <?php declare(strict_types=1);, (*8)

use Narrowspark\Http\Message\Util\InteractsWithContentTypes;, (*9)

$request = new Request(); $request = $request->withHeader('Content-Type', 'application/json, /');, (*10)

return InteractsWithContentTypes::isJson($request); // => true, (*11)

$request = $request->withHeader('X-Pjax', 'true');, (*12)

return InteractsWithContentTypes::isPjax($request); // => true, (*13)

$request = $request->withHeader('X-Requested-With', 'XMLHttpRequest');, (*14)

return InteractsWithContentTypes::isAjax($request); // => true, (*15)


Here's an example using the HeaderUtils class: ``` php <?php declare(strict_types=1); use Narrowspark\Http\Message\Util\HeaderUtils; return HeaderUtils::split("da, en-gb;q=0.8", ",;"); // => array(array('da'), array('en-gb', 'q=0.8')) or return HeaderUtils::combine(array(array("foo", "abc"), array("bar"))); // => array("foo" => "abc", "bar" => true) or return HeaderUtils::toString(array("foo" => "abc", "bar" => true, "baz" => "a b c"), ","); // => 'foo=abc, bar, baz="a b c"' or return HeaderUtils::quote('foo bar'); // => "foo bar" or return HeaderUtils::unquote('"foo bar"'); // => foo bar

Here's an example using the InteractsWithDisposition class: ``` php <?php declare(strict_types=1);, (*16)

use Narrowspark\Http\Message\Util\InteractsWithDisposition;, (*17)

$response = InteractsWithDisposition::appendDispositionHeader(new Response(), InteractsWithDisposition::DISPOSITION_ATTACHMENT, 'foo.html');, (*18)

return $response->getHeaderLine('Content-Disposition'); // => attachment; filename=foo.html, (*19)

or, (*20)

return InteractsWithDisposition::makeDisposition(InteractsWithDisposition::DISPOSITION_ATTACHMENT, 'foo.html'); // => attachment; filename=foo.html, (*21)


Testing ------------ ``` bash $ vendor/bin/phpunit

Contributing

If you would like to help take a look at the list of issues and check our Contributing guild., (*22)

Note: Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms., (*23)

License

The Narrowspark http-emitter is open-sourced software licensed under the MIT license, (*24)

The Versions

08/05 2018

dev-master

9999999-dev https://github.com/narrowspark/http-message-util

This repository holds utility classes and constants to facilitate common operations of PSR-7.

  Sources   Download

MIT

The Requires

 

The Development Requires

psr-7 http psr7 util http-message-util

08/05 2018

v0.3.0

0.3.0.0 https://github.com/narrowspark/http-message-util

This repository holds utility classes and constants to facilitate common operations of PSR-7.

  Sources   Download

MIT

The Requires

 

The Development Requires

psr-7 http psr7 util http-message-util

07/05 2018

v0.2.0

0.2.0.0 https://github.com/narrowspark/http-message-util

This repository holds utility classes and constants to facilitate common operations of PSR-7.

  Sources   Download

MIT

The Requires

 

The Development Requires

psr-7 http psr7 util http-message-util

27/10 2017

v0.1.0

0.1.0.0 https://github.com/narrowspark/http-message-util

This repository holds utility classes and constants to facilitate common operations of PSR-7.

  Sources   Download

MIT

The Requires

 

The Development Requires

psr-7 http psr7 util http-message-util