Skip to content

Commit 3ec39fa

Browse files
authored
Merge pull request #2 from ABGEO07/develope
Develope
2 parents 283750d + c7c00d3 commit 3ec39fa

File tree

4 files changed

+52
-18
lines changed

4 files changed

+52
-18
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
# Cherry-response Changelog
22

3-
## [v1.0.0](https://github.com/ABGEO07/cherry-response/releases/tag/v1.0.0 "v1.0.0") (2019-03-25)
3+
## [v1.0.1](https://github.com/ABGEO07/cherry-response/releases/tag/v1.0.1 "v1.0.1") (2019-03-28)
4+
5+
- Change Namespace
6+
7+
Now you should use new namespace `Cherry\HttpUtils\Response`
8+
9+
- Validate code in PHP CodeSniffer
10+
11+
Code and comments has checked on [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)
12+
13+
14+
## [v1.0.0](https://github.com/ABGEO07/cherry-response/releases/tag/v1.0.0 "v1.0.0") (2019-02-25)
415
#### The first stable version
516

617
- Package available on: `composer require cherry-project/response`

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require_once __DIR__ . '/vendor/autoload.php';
2020
## Class Request
2121
Import class
2222
```php
23-
use Cherry\Response;
23+
use Cherry\HttpUtils\Response;
2424
```
2525
Crete class new object
2626
```php

examples/test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//Include autoloader
44
require_once __DIR__ . '/../vendor/autoload.php';
55

6-
use Cherry\Response;
6+
use Cherry\HttpUtils\Response;
77

88
//Send Response
99
$response = new Response();

src/Response.php renamed to src/HttpUtils/Response.php

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
11
<?php
2+
/**
3+
* The file contains Response class
4+
*
5+
* PHP version 5
6+
*
7+
* @category Library
8+
* @package Cherry
9+
* @author Temuri Takalandze <[email protected]>
10+
* @license https://github.com/ABGEO07/cherry-response/blob/master/LICENSE MIT
11+
* @link https://github.com/ABGEO07/cherry-response
12+
*/
213

3-
namespace Cherry;
14+
namespace Cherry\HttpUtils;
415

516
/**
617
* Cherry project response class
718
*
8-
* @package Cherry
9-
* @author Temuri Takalandze(ABGEO) <[email protected]>
19+
* @category Library
20+
* @package Cherry
21+
* @author Temuri Takalandze <[email protected]>
22+
* @license https://github.com/ABGEO07/cherry-response/blob/master/LICENSE MIT
23+
* @link https://github.com/ABGEO07/cherry-response
1024
*/
1125
class Response
1226
{
1327
/**
1428
* Get http status code full text
1529
*
16-
* @param $statusCode
30+
* @param int $statusCode HTTP Status Code
31+
*
1732
* @return string
1833
*/
19-
private function getStatusCodeMsg($statusCode)
34+
private function _getStatusCodeMsg($statusCode)
2035
{
2136
$msg = array(
2237
100 => 'Continue',
@@ -101,33 +116,41 @@ private function getStatusCodeMsg($statusCode)
101116
/**
102117
* Set HTTP Headers
103118
*
104-
* @param $statusCode
105-
* @param $headers
119+
* @param int $statusCode HTTP Status Code
120+
* @param array $headers HTTP Headers
121+
*
122+
* @return void
106123
*/
107-
private function setHTTPHeaders($statusCode, $headers)
124+
private function _setHTTPHeaders($statusCode, $headers)
108125
{
109126
//Set HTTP Version and status header
110-
header("{$_SERVER['SERVER_PROTOCOL']} {$statusCode} {$this->getStatusCodeMsg($statusCode)}");
127+
header(
128+
"{$_SERVER['SERVER_PROTOCOL']} {$statusCode} ".
129+
"{$this->_getStatusCodeMsg($statusCode)}"
130+
);
131+
111132
//Set other headers
112-
foreach ($headers as $k => $v)
133+
foreach ($headers as $k => $v) {
113134
header("{$k}: $v");
135+
}
114136
}
115137

116138
/**
117139
* Send Response.
118140
*
119-
* @param $content
120-
* @param int $statusCode
121-
* @param array $headers
141+
* @param string $content Content value
142+
* @param int $statusCode HTTP Status Code
143+
* @param array $headers HTTP Headers
122144
*
123145
* @return mixed
124146
*/
125147
public function sendResponse($content, $statusCode = 200, $headers = [])
126148
{
127-
if ($content == '' || $content == null)
149+
if ($content == '' || $content == null) {
128150
die('Set response content!');
151+
}
129152

130-
$this->setHTTPHeaders($statusCode, $headers);
153+
$this->_setHTTPHeaders($statusCode, $headers);
131154

132155
return $content;
133156
}

0 commit comments

Comments
 (0)