Skip to content

Commit b1998a8

Browse files
committed
Use ResponseStatus constants everywhere it is needed
1 parent 7d384d2 commit b1998a8

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/WaterPipe/HTTP/Response/Response.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function sendHtml(string $body, int $status = ResponseStatus::OkCode)
143143
*
144144
* @throws \Exception
145145
*/
146-
public function sendJsonString(string $body, int $status = 200)
146+
public function sendJsonString(string $body, int $status = ResponseStatus::OkCode)
147147
{
148148
$config = WaterPipeConfig::get();
149149

@@ -162,7 +162,7 @@ public function sendJsonString(string $body, int $status = 200)
162162
*
163163
* @throws \Exception
164164
*/
165-
public function sendJson(array $json, int $status = 200)
165+
public function sendJson(array $json, int $status = ResponseStatus::OkCode)
166166
{
167167
$this->sendJsonString(json_encode($json), $status);
168168
}
@@ -175,7 +175,7 @@ public function sendJson(array $json, int $status = 200)
175175
*
176176
* @throws \Exception
177177
*/
178-
public function sendText(string $body, int $status = 200)
178+
public function sendText(string $body, int $status = ResponseStatus::OkCode)
179179
{
180180
$config = WaterPipeConfig::get();
181181

@@ -196,7 +196,7 @@ public function sendText(string $body, int $status = 200)
196196
* @throws \Exception
197197
* @throws FileNotFoundException When the file was not found at the given path.
198198
*/
199-
public function sendFile(string $path, int $status = 200, string $mime = null)
199+
public function sendFile(string $path, int $status = ResponseStatus::OkCode, string $mime = null)
200200
{
201201
$config = WaterPipeConfig::get();
202202

src/WaterPipe/WaterPipe.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use ElementaryFramework\WaterPipe\HTTP\Request\RequestMethod;
3939
use ElementaryFramework\WaterPipe\HTTP\Request\RequestUri;
4040
use ElementaryFramework\WaterPipe\HTTP\Response\Response;
41+
use ElementaryFramework\WaterPipe\HTTP\Response\ResponseStatus;
4142
use ElementaryFramework\WaterPipe\Routing\Middleware\Middleware;
4243
use ElementaryFramework\WaterPipe\Routing\Middleware\IRouteMiddleware;
4344
use ElementaryFramework\WaterPipe\Routing\Middleware\MiddlewareWrapper;
@@ -547,8 +548,8 @@ private function _executeRequest()
547548
}
548549

549550
if ($runner === null) {
550-
if (isset($this->_errorsRegistry[404]))
551-
return $this->_executeAction($this->_errorsRegistry[404]);
551+
if (isset($this->_errorsRegistry[ResponseStatus::NotFoundCode]))
552+
return $this->_executeAction($this->_errorsRegistry[ResponseStatus::NotFoundCode]);
552553
else throw new NotFoundErrorException();
553554
}
554555

@@ -565,8 +566,8 @@ private function _executeRequest()
565566
} catch (\Exception $e) {
566567
$this->_runningException = $e;
567568

568-
if (isset($this->_errorsRegistry[500])) {
569-
$this->_executeAction($this->_errorsRegistry[500]);
569+
if (isset($this->_errorsRegistry[ResponseStatus::InternalServerErrorCode])) {
570+
$this->_executeAction($this->_errorsRegistry[ResponseStatus::InternalServerErrorCode]);
570571
} else {
571572
$config = WaterPipeConfig::get();
572573
if ($config->useStderr()) {

0 commit comments

Comments
 (0)