vakata/http

HTTP Request / Response classes (extending Laminas/Diactoros with a few methods)

3.3.2 2024-03-01 13:41 UTC

README

Latest Version on Packagist Software License Build Status Scrutinizer Code Quality Code Coverage

HTTP Request / Response classes, extending Zend Diactoros with just a few helful methods.

Install

Via Composer

$ composer require vakata/http

Usage

// REQUEST extras
// create a request instance from the current client data
$req = \vakata\http\Request::fromGlobals();
// now you can inspect properties
$req->getQuery('asdf'); // get the "asdf" GET parameter value
$req->getCookie('sessid'); // get the "sessid" cookie value
$req->getPost('pass'); // get the "pass" POST parameter value
$req->getPrefferedResponseLanguage(); // get the preffered response language
// if a parameter is missing a default you pass in can be returned
$req->getQuery('missing', 'default'); // now $a contains "default"
// return values can also be filtered (all filters are listed in the docs)
$req->getPost('user_id', null, 'int');
// you can also get the whole array of parameters
$all = $req->getPost();

// URI extras
$req->getUri()->getSegment(0);
$req->getUri()->linkTo('some/path', [ 'get_param' => 'value' ]);

// RESPONSE extras
$res = new \vakata\http\Response();
$res = $res->expireCookie('sessid');
if ($res->hasCache()) {
    $res = $res->cacheUntil('+7 days');
}
$res = $res->setContentTypeByExtension('json');

Read more in the API docs

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email github@vakata.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.