Skip to content

Commit ff29415

Browse files
committed
Added reset method
1 parent c7a2da3 commit ff29415

File tree

5 files changed

+43
-9
lines changed

5 files changed

+43
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- `Fixed` for any bug fixes.
1313
- `Security` in case of vulnerabilities
1414

15+
## [1.1.0] - 2020.10.20
16+
17+
### Added
18+
19+
- Added `reset` method.
20+
1521
## [1.0.0] - 2020.08.10
1622

1723
### Added

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ John Robinson, [Bayfront Media](https://www.bayfrontmedia.com)
1919
## Requirements
2020

2121
- PHP >= 7.1.0
22+
- JSON PHP extension
2223

2324
## Installation
2425

@@ -28,6 +29,7 @@ composer require bayfrontmedia/php-http-response
2829

2930
## Usage
3031

32+
- [reset](#reset)
3133
- [setStatusCode](#setstatuscode)
3234
- [getStatusCode](#getstatuscode)
3335
- [setHeaders](#setheaders)
@@ -40,6 +42,28 @@ composer require bayfrontmedia/php-http-response
4042

4143
<hr />
4244

45+
### reset
46+
47+
**Description:**
48+
49+
Resets all headers (including status code) and body.
50+
51+
**Parameters:**
52+
53+
- None
54+
55+
**Returns:**
56+
57+
- (self)
58+
59+
**Example:**
60+
61+
```
62+
$response->reset();
63+
```
64+
65+
<hr />
66+
4367
### setStatusCode
4468

4569
**Description:**

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Easily send HTTP responses.",
44
"homepage": "https://github.com/bayfrontmedia/php-http-response",
55
"license" : "MIT",
6-
"version": "1.0.0",
6+
"version": "1.1.0",
77
"type": "library",
88
"keywords": [
99
"php",
@@ -29,7 +29,8 @@
2929
}
3030
],
3131
"require": {
32-
"php": ">=7.1.0"
32+
"php": ">=7.1.0",
33+
"ext-json": "*"
3334
},
3435
"autoload": {
3536
"psr-4": {

composer.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Response.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ class Response
1313
{
1414

1515
/**
16-
* Resets response back to default
16+
* Resets all headers (including status code) and body.
1717
*
18-
* @return void
18+
* @return self
1919
*/
2020

21-
private function _resetResponse(): void
21+
public function reset(): self
2222
{
2323

2424
$this->status_code = 200;
2525
$this->headers = [];
2626
$this->body = NULL;
2727

28+
return $this;
29+
2830
}
2931

3032
/*
@@ -278,7 +280,7 @@ public function send(): void
278280

279281
// -------------------- Reset --------------------
280282

281-
$this->_resetResponse();
283+
$this->reset();
282284

283285
exit; // Ensure nothing else loads, just to be safe
284286

@@ -332,7 +334,7 @@ public function redirect(string $url, int $status = 302): void
332334
throw new InvalidStatusCodeException('Unable to redirect: invalid status code');
333335
}
334336

335-
$this->_resetResponse(); // Reset anything that may be set
337+
$this->reset(); // Reset anything that may be set
336338

337339
$this->setHeaders([
338340
'Location' => $url

0 commit comments

Comments
 (0)