PHP code example of narrowspark / http-message-util
1. Go to this page and download the library: Download narrowspark/http-message-util library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
narrowspark / http-message-util example snippets php
declare(strict_types=1);
use Narrowspark\Http\Message\Util\InteractsWithAcceptLanguage;
$request = new Request();
$request = $request->withHeader('Accept-Language', 'zh, en-us; q=0.8, en; q=0.6');
return InteractsWithAcceptLanguage::getLanguages($request); // => ['zh', 'en', 'en_US']
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']
php
declare(strict_types=1);
use Narrowspark\Http\Message\Util\InteractsWithContentTypes;
$request = new Request();
$request = $request->withHeader('Content-Type', 'application/json, */*');
return InteractsWithContentTypes::isJson($request); // => true
$request = $request->withHeader('X-Pjax', 'true');
return InteractsWithContentTypes::isPjax($request); // => true
$request = $request->withHeader('X-Requested-With', 'XMLHttpRequest');
return InteractsWithContentTypes::isAjax($request); // => true
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
php
declare(strict_types=1);
use Narrowspark\Http\Message\Util\InteractsWithDisposition;
$response = InteractsWithDisposition::appendDispositionHeader(new Response(), InteractsWithDisposition::DISPOSITION_ATTACHMENT, 'foo.html');
return $response->getHeaderLine('Content-Disposition'); // => attachment; filename=foo.html
or
return InteractsWithDisposition::makeDisposition(InteractsWithDisposition::DISPOSITION_ATTACHMENT, 'foo.html'); // => attachment; filename=foo.html