Merge pull request #3938 from MrPetovan/task/3878-mov-HTTPExceptions-to-src
Move HTTPExceptions to src
This commit is contained in:
commit
adc720a7fc
23 changed files with 236 additions and 106 deletions
|
@ -1,105 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Throwable exceptions to return HTTP status code
|
|
||||||
*
|
|
||||||
* This list of Exception has be extracted from
|
|
||||||
* here http://racksburg.com/choosing-an-http-status-code/
|
|
||||||
*/
|
|
||||||
|
|
||||||
class HTTPException extends Exception {
|
|
||||||
var $httpcode = 200;
|
|
||||||
var $httpdesc = "";
|
|
||||||
public function __construct($message="", $code = 0, Exception $previous = null) {
|
|
||||||
if ($this->httpdesc=="") {
|
|
||||||
$this->httpdesc = preg_replace("|([a-z])([A-Z])|",'$1 $2', str_replace("Exception","",get_class($this)));
|
|
||||||
}
|
|
||||||
parent::__construct($message, $code, $previous);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4xx
|
|
||||||
class TooManyRequestsException extends HTTPException {
|
|
||||||
var $httpcode = 429;
|
|
||||||
}
|
|
||||||
|
|
||||||
class UnauthorizedException extends HTTPException {
|
|
||||||
var $httpcode = 401;
|
|
||||||
}
|
|
||||||
|
|
||||||
class ForbiddenException extends HTTPException {
|
|
||||||
var $httpcode = 403;
|
|
||||||
}
|
|
||||||
|
|
||||||
class NotFoundException extends HTTPException {
|
|
||||||
var $httpcode = 404;
|
|
||||||
}
|
|
||||||
|
|
||||||
class GoneException extends HTTPException {
|
|
||||||
var $httpcode = 410;
|
|
||||||
}
|
|
||||||
|
|
||||||
class MethodNotAllowedException extends HTTPException {
|
|
||||||
var $httpcode = 405;
|
|
||||||
}
|
|
||||||
|
|
||||||
class NonAcceptableException extends HTTPException {
|
|
||||||
var $httpcode = 406;
|
|
||||||
}
|
|
||||||
|
|
||||||
class LenghtRequiredException extends HTTPException {
|
|
||||||
var $httpcode = 411;
|
|
||||||
}
|
|
||||||
|
|
||||||
class PreconditionFailedException extends HTTPException {
|
|
||||||
var $httpcode = 412;
|
|
||||||
}
|
|
||||||
|
|
||||||
class UnsupportedMediaTypeException extends HTTPException {
|
|
||||||
var $httpcode = 415;
|
|
||||||
}
|
|
||||||
|
|
||||||
class ExpetationFailesException extends HTTPException {
|
|
||||||
var $httpcode = 417;
|
|
||||||
}
|
|
||||||
|
|
||||||
class ConflictException extends HTTPException {
|
|
||||||
var $httpcode = 409;
|
|
||||||
}
|
|
||||||
|
|
||||||
class UnprocessableEntityException extends HTTPException {
|
|
||||||
var $httpcode = 422;
|
|
||||||
}
|
|
||||||
|
|
||||||
class ImATeapotException extends HTTPException {
|
|
||||||
var $httpcode = 418;
|
|
||||||
var $httpdesc = "I'm A Teapot";
|
|
||||||
}
|
|
||||||
|
|
||||||
class BadRequestException extends HTTPException {
|
|
||||||
var $httpcode = 400;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5xx
|
|
||||||
|
|
||||||
class ServiceUnavaiableException extends HTTPException {
|
|
||||||
var $httpcode = 503;
|
|
||||||
}
|
|
||||||
|
|
||||||
class BadGatewayException extends HTTPException {
|
|
||||||
var $httpcode = 502;
|
|
||||||
}
|
|
||||||
|
|
||||||
class GatewayTimeoutException extends HTTPException {
|
|
||||||
var $httpcode = 504;
|
|
||||||
}
|
|
||||||
|
|
||||||
class NotImplementedException extends HTTPException {
|
|
||||||
var $httpcode = 501;
|
|
||||||
}
|
|
||||||
|
|
||||||
class InternalServerErrorException extends HTTPException {
|
|
||||||
var $httpcode = 500;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,19 @@ use Friendica\Core\Config;
|
||||||
use Friendica\Core\NotificationsManager;
|
use Friendica\Core\NotificationsManager;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
use Friendica\Database\DBM;
|
use Friendica\Database\DBM;
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
use Friendica\Network\HTTPException\BadRequestException;
|
||||||
|
use Friendica\Network\HTTPException\ForbiddenException;
|
||||||
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||||
|
use Friendica\Network\HTTPException\MethodNotAllowedException;
|
||||||
|
use Friendica\Network\HTTPException\NotFoundException;
|
||||||
|
use Friendica\Network\HTTPException\NotImplementedException;
|
||||||
|
use Friendica\Network\HTTPException\UnauthorizedException;
|
||||||
|
use Friendica\Network\HTTPException\TooManyRequestsException;
|
||||||
use Friendica\Object\Contact;
|
use Friendica\Object\Contact;
|
||||||
use Friendica\Protocol\Diaspora;
|
use Friendica\Protocol\Diaspora;
|
||||||
use Friendica\Util\XML;
|
use Friendica\Util\XML;
|
||||||
|
|
||||||
require_once 'include/HTTPExceptions.php';
|
|
||||||
require_once 'include/bbcode.php';
|
require_once 'include/bbcode.php';
|
||||||
require_once 'include/datetime.php';
|
require_once 'include/datetime.php';
|
||||||
require_once 'include/conversation.php';
|
require_once 'include/conversation.php';
|
||||||
|
|
27
src/Network/HTTPException.php
Normal file
27
src/Network/HTTPException.php
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throwable exceptions to return HTTP status code
|
||||||
|
*
|
||||||
|
* This list of Exception has be extracted from
|
||||||
|
* here http://racksburg.com/choosing-an-http-status-code/
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Friendica\Network;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class HTTPException extends Exception
|
||||||
|
{
|
||||||
|
var $httpcode = 200;
|
||||||
|
var $httpdesc = "";
|
||||||
|
|
||||||
|
public function __construct($message = '', $code = 0, Exception $previous = null)
|
||||||
|
{
|
||||||
|
if ($this->httpdesc == '') {
|
||||||
|
$classname = str_replace('Exception', '', str_replace('Friendica\Network\HTTPException\\', '', get_class($this)));
|
||||||
|
$this->httpdesc = preg_replace("|([a-z])([A-Z])|",'$1 $2', $classname);
|
||||||
|
}
|
||||||
|
parent::__construct($message, $code, $previous);
|
||||||
|
}
|
||||||
|
}
|
10
src/Network/HTTPException/BadGatewayException.php
Normal file
10
src/Network/HTTPException/BadGatewayException.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class BadGatewayException extends HTTPException
|
||||||
|
{
|
||||||
|
var $httpcode = 502;
|
||||||
|
}
|
10
src/Network/HTTPException/BadRequestException.php
Normal file
10
src/Network/HTTPException/BadRequestException.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class BadRequestException extends HTTPException
|
||||||
|
{
|
||||||
|
var $httpcode = 400;
|
||||||
|
}
|
10
src/Network/HTTPException/ConflictException.php
Normal file
10
src/Network/HTTPException/ConflictException.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class ConflictException extends HTTPException
|
||||||
|
{
|
||||||
|
var $httpcode = 409;
|
||||||
|
}
|
10
src/Network/HTTPException/ExpectationFailedException.php
Normal file
10
src/Network/HTTPException/ExpectationFailedException.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class ExpectationFailedException extends HTTPException
|
||||||
|
{
|
||||||
|
var $httpcode = 417;
|
||||||
|
}
|
10
src/Network/HTTPException/ForbiddenException.php
Normal file
10
src/Network/HTTPException/ForbiddenException.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class ForbiddenException extends HTTPException
|
||||||
|
{
|
||||||
|
var $httpcode = 403;
|
||||||
|
}
|
10
src/Network/HTTPException/GatewayTimeoutException.php
Normal file
10
src/Network/HTTPException/GatewayTimeoutException.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class GatewayTimeoutException extends HTTPException
|
||||||
|
{
|
||||||
|
var $httpcode = 504;
|
||||||
|
}
|
10
src/Network/HTTPException/GoneException.php
Normal file
10
src/Network/HTTPException/GoneException.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class GoneException extends HTTPException
|
||||||
|
{
|
||||||
|
var $httpcode = 410;
|
||||||
|
}
|
11
src/Network/HTTPException/ImATeapotException.php
Normal file
11
src/Network/HTTPException/ImATeapotException.php
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class ImATeapotException extends HTTPException
|
||||||
|
{
|
||||||
|
var $httpcode = 418;
|
||||||
|
var $httpdesc = "I'm A Teapot";
|
||||||
|
}
|
10
src/Network/HTTPException/InternalServerErrorException.php
Normal file
10
src/Network/HTTPException/InternalServerErrorException.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class InternalServerErrorException extends HTTPException
|
||||||
|
{
|
||||||
|
var $httpcode = 500;
|
||||||
|
}
|
10
src/Network/HTTPException/LenghtRequiredException.php
Normal file
10
src/Network/HTTPException/LenghtRequiredException.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class LenghtRequiredException extends HTTPException
|
||||||
|
{
|
||||||
|
var $httpcode = 411;
|
||||||
|
}
|
10
src/Network/HTTPException/MethodNotAllowedException.php
Normal file
10
src/Network/HTTPException/MethodNotAllowedException.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class MethodNotAllowedException extends HTTPException
|
||||||
|
{
|
||||||
|
var $httpcode = 405;
|
||||||
|
}
|
10
src/Network/HTTPException/NonAcceptableException.php
Normal file
10
src/Network/HTTPException/NonAcceptableException.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class NonAcceptableException extends HTTPException
|
||||||
|
{
|
||||||
|
var $httpcode = 406;
|
||||||
|
}
|
9
src/Network/HTTPException/NotFoundException.php
Normal file
9
src/Network/HTTPException/NotFoundException.php
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class NotFoundException extends HTTPException {
|
||||||
|
var $httpcode = 404;
|
||||||
|
}
|
10
src/Network/HTTPException/NotImplementedException.php
Normal file
10
src/Network/HTTPException/NotImplementedException.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class NotImplementedException extends HTTPException
|
||||||
|
{
|
||||||
|
var $httpcode = 501;
|
||||||
|
}
|
10
src/Network/HTTPException/PreconditionFailedException.php
Normal file
10
src/Network/HTTPException/PreconditionFailedException.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class PreconditionFailedException extends HTTPException
|
||||||
|
{
|
||||||
|
var $httpcode = 412;
|
||||||
|
}
|
10
src/Network/HTTPException/ServiceUnavaiableException.php
Normal file
10
src/Network/HTTPException/ServiceUnavaiableException.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class ServiceUnavaiableException extends HTTPException
|
||||||
|
{
|
||||||
|
var $httpcode = 503;
|
||||||
|
}
|
10
src/Network/HTTPException/TooManyRequestsException.php
Normal file
10
src/Network/HTTPException/TooManyRequestsException.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class TooManyRequestsException extends HTTPException
|
||||||
|
{
|
||||||
|
var $httpcode = 429;
|
||||||
|
}
|
10
src/Network/HTTPException/UnauthorizedException.php
Normal file
10
src/Network/HTTPException/UnauthorizedException.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class UnauthorizedException extends HTTPException
|
||||||
|
{
|
||||||
|
var $httpcode = 401;
|
||||||
|
}
|
10
src/Network/HTTPException/UnprocessableEntityException.php
Normal file
10
src/Network/HTTPException/UnprocessableEntityException.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class UnprocessableEntityException extends HTTPException
|
||||||
|
{
|
||||||
|
var $httpcode = 422;
|
||||||
|
}
|
10
src/Network/HTTPException/UnsupportedMediaTypeException.php
Normal file
10
src/Network/HTTPException/UnsupportedMediaTypeException.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class UnsupportedMediaTypeException extends HTTPException
|
||||||
|
{
|
||||||
|
var $httpcode = 415;
|
||||||
|
}
|
Loading…
Reference in a new issue