library hx-http
HTTP input and output handler
guinso/hx-http
HTTP input and output handler
- Saturday, July 2, 2016
- by guinso
- Repository
- 1 Watchers
- 1 Stars
- 29 Installations
- PHP
- 1 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 8 Versions
- 0 % Grown
hx-http
PHP Http input and output handler, (*1)
Install
//for PHP 5.5
{
"require": {
"guinso/hx-http": "1.0.*"
}
}
//for PHP 7
{
"require": {
"guinso/hx-http": "2.0.*"
}
}
require_once('path-of-hx-http-library/src/autoloader.php');
Example
$httpHeader = new \Hx\Http\HeaderReader();
$httpInputService = new \Hx\Http\InputService();
$arrInfo = $httpInputService.getInput($httpHeader);
//to read general input (no matter GET, POST, or PUT)
$yourClientDataValue = $arrInfo['data']['your-client-specified-data-key'];
//to read client uploaded file path (work for multipart format as well)
$clientUploadTemporaryFilePath = $arrInfo['file']['your-client-specified-file-name'];
-
Write Http Output, (*2)
$outputService = new \Hx\Http\OutputService();
$outputData = array(
'key-A' => 123,
'key-B' => 'Cat meow',
'key-C' => [
'sub-key-1' => 157.67,
'sub-key-2' => "tree"
]
);
//generate JSON output to http
$outputService->generateOutput('json', $outputData);
//OR generate in XML format
$outputService->generateOutput('xml', $outputData);
$outputService = new \Hx\Http\OutputService();
$htmlOutput = array(
'header' => //this is html header tag
"<title>Page Title</title>
<link rel="stylesheet" href="mystyle.css">",
'body' => //this is html body tag
"<body>
...
</body>"
);
//generate Html output format
$outputService->generateOutput('html', $htmlOutput);
$outputService = new \Hx\Http\OutputService();
$fileInfo = array(
'fileName' => 'filename-which-you-want-show-to-client',
'filePath' => 'actual-physical-file-path'
);
//download file to client (client never know physical file location)
$outputService->generateOutput('file', $fileInfo);
$outputService = new \Hx\Http\OutputService();
$data = array("data" => "anything....");
//generate plain text to client
//NOTE: output is not in Html format since it is marked as 'text/plain' MIME type
$outputService->generateOutput('text', $data);
dev-master
9999999-dev
HTTP input and output handler
Sources
Download
MIT
The Requires
http
2.0
2.0.0.0
HTTP input and output handler
Sources
Download
MIT
The Requires
http
1.0.4
1.0.4.0
HTTP input and output handler
Sources
Download
MIT
The Requires
http
1.0.5
1.0.5.0
HTTP input and output handler
Sources
Download
MIT
The Requires
http
1.0.3
1.0.3.0
HTTP input and output handler
Sources
Download
MIT
The Requires
http
1.0.2
1.0.2.0
HTTP input and output handler
Sources
Download
MIT
The Requires
http
1.0.1
1.0.1.0
HTTP input and output handler
Sources
Download
MIT
The Requires
http
1.0.0
1.0.0.0
HTTP input and output handler
Sources
Download
MIT
The Requires