Skip to content

Commit

Permalink
Merge pull request #2 from ABGEO07/develope
Browse files Browse the repository at this point in the history
Develope
  • Loading branch information
ABGEO authored Mar 28, 2019
2 parents 283750d + c7c00d3 commit 3ec39fa
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 18 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Cherry-response Changelog

## [v1.0.0](https://github.com/ABGEO07/cherry-response/releases/tag/v1.0.0 "v1.0.0") (2019-03-25)
## [v1.0.1](https://github.com/ABGEO07/cherry-response/releases/tag/v1.0.1 "v1.0.1") (2019-03-28)

- Change Namespace

Now you should use new namespace `Cherry\HttpUtils\Response`

- Validate code in PHP CodeSniffer

Code and comments has checked on [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)


## [v1.0.0](https://github.com/ABGEO07/cherry-response/releases/tag/v1.0.0 "v1.0.0") (2019-02-25)
#### The first stable version

- Package available on: `composer require cherry-project/response`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require_once __DIR__ . '/vendor/autoload.php';
## Class Request
Import class
```php
use Cherry\Response;
use Cherry\HttpUtils\Response;
```
Crete class new object
```php
Expand Down
2 changes: 1 addition & 1 deletion examples/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//Include autoloader
require_once __DIR__ . '/../vendor/autoload.php';

use Cherry\Response;
use Cherry\HttpUtils\Response;

//Send Response
$response = new Response();
Expand Down
53 changes: 38 additions & 15 deletions src/Response.php → src/HttpUtils/Response.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
<?php
/**
* The file contains Response class
*
* PHP version 5
*
* @category Library
* @package Cherry
* @author Temuri Takalandze <[email protected]>
* @license https://github.com/ABGEO07/cherry-response/blob/master/LICENSE MIT
* @link https://github.com/ABGEO07/cherry-response
*/

namespace Cherry;
namespace Cherry\HttpUtils;

/**
* Cherry project response class
*
* @package Cherry
* @author Temuri Takalandze(ABGEO) <[email protected]>
* @category Library
* @package Cherry
* @author Temuri Takalandze <[email protected]>
* @license https://github.com/ABGEO07/cherry-response/blob/master/LICENSE MIT
* @link https://github.com/ABGEO07/cherry-response
*/
class Response
{
/**
* Get http status code full text
*
* @param $statusCode
* @param int $statusCode HTTP Status Code
*
* @return string
*/
private function getStatusCodeMsg($statusCode)
private function _getStatusCodeMsg($statusCode)
{
$msg = array(
100 => 'Continue',
Expand Down Expand Up @@ -101,33 +116,41 @@ private function getStatusCodeMsg($statusCode)
/**
* Set HTTP Headers
*
* @param $statusCode
* @param $headers
* @param int $statusCode HTTP Status Code
* @param array $headers HTTP Headers
*
* @return void
*/
private function setHTTPHeaders($statusCode, $headers)
private function _setHTTPHeaders($statusCode, $headers)
{
//Set HTTP Version and status header
header("{$_SERVER['SERVER_PROTOCOL']} {$statusCode} {$this->getStatusCodeMsg($statusCode)}");
header(
"{$_SERVER['SERVER_PROTOCOL']} {$statusCode} ".
"{$this->_getStatusCodeMsg($statusCode)}"
);

//Set other headers
foreach ($headers as $k => $v)
foreach ($headers as $k => $v) {
header("{$k}: $v");
}
}

/**
* Send Response.
*
* @param $content
* @param int $statusCode
* @param array $headers
* @param string $content Content value
* @param int $statusCode HTTP Status Code
* @param array $headers HTTP Headers
*
* @return mixed
*/
public function sendResponse($content, $statusCode = 200, $headers = [])
{
if ($content == '' || $content == null)
if ($content == '' || $content == null) {
die('Set response content!');
}

$this->setHTTPHeaders($statusCode, $headers);
$this->_setHTTPHeaders($statusCode, $headers);

return $content;
}
Expand Down

0 comments on commit 3ec39fa

Please sign in to comment.