borobudur / http
Borobudur Http Component
dev-master / 0.1.x-dev
2018-01-19 04:01 UTC
Requires
- psr/http-message: ~1.0
- zendframework/zend-diactoros: ^1.6
This package is auto-updated.
Last update: 2024-12-07 00:11:13 UTC
README
Borobudur\Http
is high performance and lightweight core Http Component for PHP 5.4+. It provides abstraction for Header, Request, URI, Cookie, Session, File Upload, etc
- Can be used with all HTTP Methods
- Create request from server variable or dummy
- Support chunk response
- Session with flash
- Composite file upload
- Response with http encoding
- Cookie
- Http header (Cache-Control, Content-Type, etc)
- etc
Installation
- Get Composer
- Install Borobudur\Http with
composer require borobudur/http
- Add composer autoload on your main PHP file:
require __DIR__.'/vendor/autoload.php';
Example
Example 1 - Create request from $_SERVER variables
use Borobudur\Http\Request; $request = Request::createFromServer(); echo $request->getUri()->getPathInfo();
Example 2 - Create self request (can be use for cli or php unit)
use Borobudur\Http\Request; $request = Request::create('/page/demo', Request::HTTP_METHOD_GET); echo $request->getUri()->getSegment(0); // should return "page"
Example 3 - Send response
use Borobudur\Http\Response; $response = new Response('Hello world'); $response->send();
Example 4 - Send chunk response with gzip content encoding
use Borobudur\Http\Response; $response = new Response( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore'. 'magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo'. 'consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.'. 'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.' ); $response->setContentEncoding('gzip'); $response->setChunkedTransferEncoding(); $response->send();
Example 5 - Send json response
use Borobudur\Http\Response\JsonResponse; $response = new JsonResponse(array('name' => 'Iqbal', 'status' => 'online')); $response->send();
Example 6 - Send redirect response
use Borobudur\Http\Response\RedirectResponse; $response = new RedirectResponse('/user/profile'); $response->send();