Skip to content

Commit

Permalink
HTTP Exceptions (#39)
Browse files Browse the repository at this point in the history
* Build up request URI in parts for greater compatibility

* Change visibility to public for all getStatusCode functions

* Organise redirection exceptions
  • Loading branch information
g105b authored Jun 16, 2020
1 parent 2d626b1 commit 80683ce
Show file tree
Hide file tree
Showing 56 changed files with 135 additions and 113 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
namespace Gt\Http\ResponseStatusException\ClientError;

use Gt\Http\ResponseStatusException\AbstractResponseStatusException;

abstract class AbstractClientErrorException extends AbstractResponseStatusException {}
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions src/ResponseStatusException/ClientError/HttpMisdirectedRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Gt\Http\ResponseStatusException\ClientError;

use Gt\Http\StatusCode;

class HttpMisdirectedRequest extends AbstractClientErrorException {
public function getHttpCode():int {
return StatusCode::MISDIRECTED_REQUEST;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Gt\Http\ResponseStatusException;
namespace Gt\Http\ResponseStatusException\ClientError;

use Gt\Http\StatusCode;

Expand All @@ -8,7 +8,7 @@
* according to the Accept headers sent in the request.
* @linkhttps://httpstatuses.com/406
*/
class HttpNotAcceptable extends AbstractResponseStatusException {
class HttpNotAcceptable extends AbstractClientErrorException {
public function getHttpCode():int {
return StatusCode::NOT_ACCEPTABLE;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Gt\Http\ResponseStatusException;
namespace Gt\Http\ResponseStatusException\ClientError;

use Gt\Http\StatusCode;

Expand All @@ -8,7 +8,7 @@
* Subsequent requests by the client are permissible.
* @link https://httpstatuses.com/404
*/
class HttpNotFound extends AbstractResponseStatusException {
class HttpNotFound extends AbstractClientErrorException {
public function getHttpCode():int {
return StatusCode::NOT_FOUND;
}
Expand Down
10 changes: 10 additions & 0 deletions src/ResponseStatusException/ClientError/HttpPayloadTooLarge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Gt\Http\ResponseStatusException\ClientError;

use Gt\Http\StatusCode;

class HttpPayloadTooLarge extends AbstractClientErrorException {
public function getHttpCode():int {
return StatusCode::PAYLOAD_TOO_LARGE;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Gt\Http\ResponseStatusException;
namespace Gt\Http\ResponseStatusException\ClientError;

use Gt\Http\StatusCode;

Expand All @@ -15,7 +15,7 @@
* parameters were correct, for example blocked fraudulent payments.
* @linkhttps://httpstatuses.com/402
*/
class HttpPaymentRequired extends AbstractResponseStatusException {
class HttpPaymentRequired extends AbstractClientErrorException {
public function getHttpCode():int {
return StatusCode::PAYMENT_REQUIRED;
}
Expand Down
10 changes: 10 additions & 0 deletions src/ResponseStatusException/ClientError/HttpPreconditionFailed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Gt\Http\ResponseStatusException\ClientError;

use Gt\Http\StatusCode;

class HttpPreconditionFailed extends AbstractClientErrorException {
public function getHttpCode():int {
return StatusCode::PRECONDITION_FAILED;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Gt\Http\ResponseStatusException\ClientError;

use Gt\Http\StatusCode;

class HttpPreconditionRequired extends AbstractClientErrorException {
public function getHttpCode():int {
return StatusCode::PRECONDITION_REQUIRED;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
namespace Gt\Http\ResponseStatusException;
namespace Gt\Http\ResponseStatusException\ClientError;

use Gt\Http\StatusCode;

/**
* The client must first authenticate itself with the proxy.
* @linkhttps://httpstatuses.com/407
*/
class HttpProxyAuthenticationRequired extends AbstractResponseStatusException {
class HttpProxyAuthenticationRequired extends AbstractClientErrorException {
public function getHttpCode():int {
return StatusCode::PROXY_AUTHENTICATION_REQUIRED;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
namespace Gt\Http\ResponseStatusException;
namespace Gt\Http\ResponseStatusException\ClientError;

use Gt\Http\StatusCode;

class HttpRangeNotSatisfiable extends AbstractResponseStatusException {
class HttpRangeNotSatisfiable extends AbstractClientErrorException {
public function getHttpCode():int {
return StatusCode::REQUESTED_RANGE_NOT_SATISFIABLE;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Gt\Http\ResponseStatusException\ClientError;

use Gt\Http\StatusCode;

class HttpRequestHeaderFieldsTooLarge extends AbstractClientErrorException {
public function getHttpCode():int {
return StatusCode::REQUEST_HEADER_FIELDS_TOO_LARGE;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Gt\Http\ResponseStatusException;
namespace Gt\Http\ResponseStatusException\ClientError;

use Gt\Http\StatusCode;

Expand All @@ -10,7 +10,7 @@
* modifications at any later time."
* @linkhttps://httpstatuses.com/408
*/
class HttpRequestTimeout extends AbstractResponseStatusException {
class HttpRequestTimeout extends AbstractClientErrorException {
public function getHttpCode():int {
return StatusCode::REQUEST_TIME_OUT;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Gt\Http\ResponseStatusException;
namespace Gt\Http\ResponseStatusException\ClientError;

use Gt\Http\StatusCode;

Expand All @@ -8,7 +8,7 @@
* might be replayed.
* @link https://tools.ietf.org/html/rfc8470
*/
class HttpTooEarly extends AbstractResponseStatusException {
class HttpTooEarly extends AbstractClientErrorException {
public function getHttpCode():int {
return StatusCode::TOO_EARLY;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Gt\Http\ResponseStatusException;
namespace Gt\Http\ResponseStatusException\ClientError;

use Gt\Http\StatusCode;

Expand All @@ -8,7 +8,7 @@
* for use with rate-limiting schemes.
* @link https://httpstatuses.com/429
*/
class HttpTooManyRequests extends AbstractResponseStatusException {
class HttpTooManyRequests extends AbstractClientErrorException {
public function getHttpCode():int {
return StatusCode::TOO_MANY_REQUESTS;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Gt\Http\ResponseStatusException;
namespace Gt\Http\ResponseStatusException\ClientError;

use Gt\Http\StatusCode;

Expand All @@ -15,7 +15,7 @@
* refused permission to access a website.
* @link https://httpstatuses.com/401
*/
class HttpUnauthorized extends AbstractResponseStatusException {
class HttpUnauthorized extends AbstractClientErrorException {
public function getHttpCode():int {
return StatusCode::UNAUTHORIZED;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Gt\Http\ResponseStatusException;
namespace Gt\Http\ResponseStatusException\ClientError;

use Gt\Http\StatusCode;

Expand All @@ -9,7 +9,7 @@
* was chosen as a reference to the novel Fahrenheit 451.
* @link https://httpstatuses.com/451
*/
class HttpUnavailableForLegalReasons extends AbstractResponseStatusException {
class HttpUnavailableForLegalReasons extends AbstractClientErrorException {
public function getHttpCode():int {
return StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Gt\Http\ResponseStatusException;
namespace Gt\Http\ResponseStatusException\ClientError;

use Gt\Http\StatusCode;

Expand All @@ -8,7 +8,7 @@
* errors.
* @link https://httpstatuses.com/422
*/
class HttpUnprocessableEntity extends AbstractResponseStatusException {
class HttpUnprocessableEntity extends AbstractClientErrorException {
public function getHttpCode():int {
return StatusCode::UNPROCESSABLE_ENTITY;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Gt\Http\ResponseStatusException;
namespace Gt\Http\ResponseStatusException\ClientError;

use Gt\Http\StatusCode;

Expand All @@ -9,7 +9,7 @@
* server requires that images use a different format.
* @link https://httpstatuses.com/415
*/
class HttpUnsupportedMediaType extends AbstractResponseStatusException {
class HttpUnsupportedMediaType extends AbstractClientErrorException {
public function getHttpCode():int {
return StatusCode::UNSUPPORTED_MEDIA_TYPE;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Gt\Http\ResponseStatusException;
namespace Gt\Http\ResponseStatusException\ClientError;

use Gt\Http\StatusCode;

Expand All @@ -8,7 +8,7 @@
* the Upgrade header field.
* @link https://httpstatuses.com/426
*/
class HttpUpgradeRequired extends AbstractResponseStatusException {
class HttpUpgradeRequired extends AbstractClientErrorException {
public function getHttpCode():int {
return StatusCode::UPGRADE_REQUIRED;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Gt\Http\ResponseStatusException;
namespace Gt\Http\ResponseStatusException\ClientError;

use Gt\Http\StatusCode;

Expand All @@ -10,7 +10,7 @@
* Called "Request-URI Too Long" previously.
* @link https://httpstatuses.com/414
*/
class HttpUriTooLong extends AbstractResponseStatusException {
class HttpUriTooLong extends AbstractClientErrorException {
public function getHttpCode():int {
return StatusCode::REQUEST_URI_TOO_LONG;
}
Expand Down
10 changes: 0 additions & 10 deletions src/ResponseStatusException/HttpMisdirectedRequest.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/ResponseStatusException/HttpPayloadTooLarge.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/ResponseStatusException/HttpPreconditionFailed.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/ResponseStatusException/HttpPreconditionRequired.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/ResponseStatusException/HttpRequestHeaderFieldsTooLarge.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Gt\Http\ResponseStatusException\Redirection;

use Gt\Http\ResponseStatusException\AbstractResponseStatusException;

abstract class AbstractRedirectionException extends AbstractResponseStatusException {
public function __construct(string $redirectTo) {
parent::__construct($redirectTo);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Gt\Http\ResponseStatusException;
namespace Gt\Http\ResponseStatusException\Redirection;

use Gt\Http\StatusCode;

Expand All @@ -14,7 +14,7 @@
* applications and frameworks use the 302 status code as if it were the 303.
* @link https://httpstatuses.com/302
*/
class HttpFound extends AbstractResponseStatusException {
class HttpFound extends AbstractRedirectionException {
public function getHttpCode():int {
return StatusCode::FOUND;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
namespace Gt\Http\ResponseStatusException;
namespace Gt\Http\ResponseStatusException\Redirection;

use Gt\Http\StatusCode;

/**
* This and all future requests should be directed to the given URI.
* @link https://httpstatuses.com/301
*/
class HttpMovedPermanently extends AbstractResponseStatusException {
class HttpMovedPermanently extends AbstractRedirectionException {
public function getHttpCode():int {
return StatusCode::MOVED_PERMANENTLY;
}
Expand Down
Loading

0 comments on commit 80683ce

Please sign in to comment.