Changed scope
authorMichael <heluecht@pirati.ca>
Sun, 31 Oct 2021 04:54:24 +0000 (04:54 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 31 Oct 2021 04:54:24 +0000 (04:54 +0000)
33 files changed:
include/api.php
src/Module/Debug/Probe.php
src/Module/Debug/WebFinger.php
src/Module/Search/Index.php
src/Module/Special/HTTPException.php
src/Network/HTTPException.php
src/Network/HTTPException/AcceptedException.php
src/Network/HTTPException/BadGatewayException.php
src/Network/HTTPException/BadRequestException.php
src/Network/HTTPException/ConflictException.php
src/Network/HTTPException/ExpectationFailedException.php
src/Network/HTTPException/ForbiddenException.php
src/Network/HTTPException/FoundException.php
src/Network/HTTPException/GatewayTimeoutException.php
src/Network/HTTPException/GoneException.php
src/Network/HTTPException/ImATeapotException.php
src/Network/HTTPException/InternalServerErrorException.php
src/Network/HTTPException/LenghtRequiredException.php
src/Network/HTTPException/MethodNotAllowedException.php
src/Network/HTTPException/MovedPermanently.php
src/Network/HTTPException/NoContentException.php
src/Network/HTTPException/NonAcceptableException.php
src/Network/HTTPException/NotFoundException.php
src/Network/HTTPException/NotImplementedException.php
src/Network/HTTPException/NotModifiedException.php
src/Network/HTTPException/OKException.php
src/Network/HTTPException/PreconditionFailedException.php
src/Network/HTTPException/ServiceUnavailableException.php
src/Network/HTTPException/TemporaryRedirectException.php
src/Network/HTTPException/TooManyRequestsException.php
src/Network/HTTPException/UnauthorizedException.php
src/Network/HTTPException/UnprocessableEntityException.php
src/Network/HTTPException/UnsupportedMediaTypeException.php

index fc73ae8500b365830350c76d59981daf3682b7c4..b6869a2b132053682e60a72fa2a6d12b9193e2cb 100644 (file)
@@ -371,7 +371,7 @@ function api_call(App $a, App\Arguments $args = null)
                Logger::warning(API_LOG_PREFIX . 'not implemented', ['module' => 'api', 'action' => 'call', 'query' => DI::args()->getQueryString()]);
                throw new NotFoundException();
        } catch (HTTPException $e) {
-               header("HTTP/1.1 {$e->getCode()} {$e->httpdesc}");
+               header("HTTP/1.1 {$e->getCode()} {$e->getDescription()}");
                return api_error($type, $e, $args);
        }
 }
index 6c2891c0be6345bdbe95b62d27e639dde1928d71..304096b2ec0e57b337fc0cbe4a1470b347836ee1 100644 (file)
@@ -35,9 +35,7 @@ class Probe extends BaseModule
        public static function content(array $parameters = [])
        {
                if (!local_user()) {
-                       $e           = new HTTPException\ForbiddenException(DI::l10n()->t('Only logged in users are permitted to perform a probing.'));
-                       $e->httpdesc = DI::l10n()->t('Public access denied.');
-                       throw $e;
+                       throw new HTTPException\ForbiddenException(DI::l10n()->t('Only logged in users are permitted to perform a probing.'));
                }
 
                $addr = $_GET['addr'] ?? '';
index ace1c1f9a46e89c6d1c9bf7aed76c5582de9ca9d..e8a619f0b9dedca12222592b867afadb37b15e34 100644 (file)
@@ -34,9 +34,7 @@ class WebFinger extends BaseModule
        public static function content(array $parameters = [])
        {
                if (!local_user()) {
-                       $e           = new \Friendica\Network\HTTPException\ForbiddenException(DI::l10n()->t('Only logged in users are permitted to perform a probing.'));
-                       $e->httpdesc = DI::l10n()->t('Public access denied.');
-                       throw $e;
+                       throw new \Friendica\Network\HTTPException\ForbiddenException(DI::l10n()->t('Only logged in users are permitted to perform a probing.'));
                }
 
                $addr = $_GET['addr'] ?? '';
index 7be5058c2b27041354234fd58e045997fa0b66f7..5220317bf9e21c131cdeea46b70700a877f6aec0 100644 (file)
@@ -51,9 +51,7 @@ class Index extends BaseSearch
                }
 
                if (DI::config()->get('system', 'local_search') && !Session::isAuthenticated()) {
-                       $e = new HTTPException\ForbiddenException(DI::l10n()->t('Only logged in users are permitted to perform a search.'));
-                       $e->httpdesc = DI::l10n()->t('Public access denied.');
-                       throw $e;
+                       throw new HTTPException\ForbiddenException(DI::l10n()->t('Only logged in users are permitted to perform a search.'));
                }
 
                if (DI::config()->get('system', 'permit_crawling') && !Session::isAuthenticated()) {
index 137b72b36e1be692b93d5e24ae9c812a7ff1ff62..8fe4c8ce5752054c5d462340bb2b66a35b07223f 100644 (file)
@@ -45,8 +45,8 @@ class HTTPException
        {
                // Explanations are mostly taken from https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
                $vars = [
-                       '$title' => $e->httpdesc ?: 'Error ' . $e->getCode(),
-                       '$message' => $e->getMessage() ?: $e->explanation,
+                       '$title' => $e->getDescription() ?: 'Error ' . $e->getCode(),
+                       '$message' => $e->getMessage() ?: $e->getExplanation(),
                        '$back' => DI::l10n()->t('Go back'),
                        '$stack_trace' => DI::l10n()->t('Stack trace:'),
                ];
@@ -74,7 +74,7 @@ class HTTPException
                        $content = Renderer::replaceMacros($tpl, self::getVars($e));
                }
 
-               System::httpExit($e->getCode(), $e->httpdesc, $content);
+               System::httpExit($e->getCode(), $e->getDescription(), $content);
        }
 
        /**
@@ -86,10 +86,10 @@ class HTTPException
         */
        public static function content(\Friendica\Network\HTTPException $e)
        {
-               header($_SERVER["SERVER_PROTOCOL"] . ' ' . $e->getCode() . ' ' . $e->httpdesc);
+               header($_SERVER["SERVER_PROTOCOL"] . ' ' . $e->getCode() . ' ' . $e->getDescription());
 
                if ($e->getCode() >= 400) {
-                       Logger::debug('Exit with error', ['code' => $e->getCode(), 'description' => $e->httpdesc, 'query' => DI::args()->getQueryString(), 'callstack' => System::callstack(20), 'method' => $_SERVER['REQUEST_METHOD'], 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']);
+                       Logger::debug('Exit with error', ['code' => $e->getCode(), 'description' => $e->getDescription(), 'query' => DI::args()->getQueryString(), 'callstack' => System::callstack(20), 'method' => $_SERVER['REQUEST_METHOD'], 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']);
                }
 
                $tpl = Renderer::getMarkupTemplate('exception.tpl');
index 1ca6bd36df1e52d6f1de5ede8e26373f239c31aa..a0cdcdf6af3ceabd8c467a48184424b1e0c896eb 100644 (file)
@@ -31,11 +31,21 @@ use Exception;
  */
 abstract class HTTPException extends Exception
 {
-       public $httpdesc    = '';
-       public $explanation = '';
+       protected $httpdesc    = '';
+       protected $explanation = '';
 
        public function __construct($message = '', Exception $previous = null)
        {
                parent::__construct($message, $this->code, $previous);
        }
+
+       public function getDescription()
+       {
+               return $this->httpdesc;
+       }
+
+       public function getExplanation()
+       {
+               return $this->explanation;
+       }
 }
index e7a8e5a3e0097f69760503656b8e49cddc16dcee..3c42802ed79e48bb6d1aa26cc05e3541ffee52b4 100644 (file)
@@ -25,6 +25,6 @@ use Friendica\Network\HTTPException;
 
 class AcceptedException extends HTTPException
 {
-       protected $code = 202;
-       var $httpdesc   = 'Accepted';
+       protected $code     = 202;
+       protected $httpdesc = 'Accepted';
 }
index d2f6c3fbebc477b7ed114466b861f7b705d4968d..c80202a41ac7b8f2c25b23540ed03e9339687079 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
 
 class BadGatewayException extends HTTPException
 {
-       protected $code  = 502;
-       var $httpdesc    = 'Bad Gateway';
-       var $explanation = 'The server was acting as a gateway or proxy and received an invalid response from the upstream server.';
+       protected $code        = 502;
+       protected $httpdesc    = 'Bad Gateway';
+       protected $explanation = 'The server was acting as a gateway or proxy and received an invalid response from the upstream server.';
 }
index c2fe816afc907dca900ba1402e3609892d9ac224..fef39c1c16add5051f135f2e2ac1d005dc50c35d 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
 
 class BadRequestException extends HTTPException
 {
-       protected $code  = 400;
-       var $httpdesc    = 'Bad Request';
-       var $explanation = 'The server cannot or will not process the request due to an apparent client error.';
+       protected $code        = 400;
+       protected $httpdesc    = 'Bad Request';
+       protected $explanation = 'The server cannot or will not process the request due to an apparent client error.';
 }
index 01cfc8dce0428ce26ce34c57bfd05b834c4948f6..2f7a892e2597bc3f1995082e10358819808bc3e4 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
 
 class ConflictException extends HTTPException
 {
-       protected $code  = 409;
-       var $httpdesc    = 'Conflict ';
-       var $explanation = 'Indicates that the request could not be processed because of conflict in the current state of the resource, such as an edit conflict between multiple simultaneous updates.';
+       protected $code        = 409;
+       protected $httpdesc    = 'Conflict ';
+       protected $explanation = 'Indicates that the request could not be processed because of conflict in the current state of the resource, such as an edit conflict between multiple simultaneous updates.';
 }
index 9ae58bcc81ccb15ab7ac327ce3c7de7848aa4188..5c1bc6ab7f7cbdab8449380612a28c9ce30e15a7 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
 
 class ExpectationFailedException extends HTTPException
 {
-       protected $code  = 417;
-       var $httpdesc    = 'Expectation Failed';
-       var $explanation = 'The server cannot meet the requirements of the Expect request-header field.';
+       protected $code        = 417;
+       protected $httpdesc    = 'Expectation Failed';
+       protected $explanation = 'The server cannot meet the requirements of the Expect request-header field.';
 }
index a1dafa9a5ba33474e76463e4e8a5c24c55aba8dd..2d6598706454f5542cd75c61b31f6063afa792c1 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
 
 class ForbiddenException extends HTTPException
 {
-       protected $code  = 403;
-       var $httpdesc    = 'Forbidden';
-       var $explanation = 'The request was valid, but the server is refusing action. The user might not have the necessary permissions for a resource, or may need an account.';
+       protected $code        = 403;
+       protected $httpdesc    = 'Forbidden';
+       protected $explanation = 'The request was valid, but the server is refusing action. The user might not have the necessary permissions for a resource, or may need an account.';
 }
index c60a5f8c837a7b1e6e71a05687b2ae1a744e1c5d..8fcaceb773d4d3fe1ab170ec76ec6b4b3f7bb88c 100644 (file)
@@ -25,6 +25,6 @@ use Friendica\Network\HTTPException;
 
 class FoundException extends HTTPException
 {
-       protected $code = 302;
-       var $httpdesc   = 'Found (Moved Temporarily)';
+       protected $code     = 302;
+       protected $httpdesc = 'Found (Moved Temporarily)';
 }
index 2f674b2dcd05e77339008d30da30161f0079d88b..695616f0d7a09334d35943563d0048b0d38ac10d 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
 
 class GatewayTimeoutException extends HTTPException
 {
-       protected $code  = 504;
-       var $httpdesc    = 'Gateway Timeout';
-       var $explanation = 'The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.';
+       protected $code        = 504;
+       protected $httpdesc    = 'Gateway Timeout';
+       protected $explanation = 'The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.';
 }
index 73eedcb671fb7b4fff7e0ca747f2ae22b04910b7..400bbc23e4f64f0f4753eb37952ef92bda15275a 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
 
 class GoneException extends HTTPException
 {
-       protected $code  = 410;
-       var $httpdesc    = 'Gone';
-       var $explanation = 'Indicates that the resource requested is no longer available and will not be available again.';
+       protected $code        = 410;
+       protected $httpdesc    = 'Gone';
+       protected $explanation = 'Indicates that the resource requested is no longer available and will not be available again.';
 }
index dcfd72de0455fd5014cc4a7369cbd616c2b8e444..33f7a641b2acb03eec7d4ab3af03a780070d5c7c 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
 
 class ImATeapotException extends HTTPException
 {
-       protected $code  = 418;
-       var $httpdesc    = "I'm A Teapot";
-       var $explanation = 'This is a teapot that is requested to brew coffee.';
+       protected $code        = 418;
+       protected $httpdesc    = "I'm A Teapot";
+       protected $explanation = 'This is a teapot that is requested to brew coffee.';
 }
index d5df8fdd3a7754fe8e49a30dc4332c46078aaa0c..4638d5c8496923583ac482d383d795ca2f1a4794 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
 
 class InternalServerErrorException extends HTTPException
 {
-       protected $code  = 500;
-       var $httpdesc    = 'Internal Server Error';
-       var $explanation = 'An unexpected condition was encountered and no more specific message is suitable.';
+       protected $code        = 500;
+       protected $httpdesc    = 'Internal Server Error';
+       protected $explanation = 'An unexpected condition was encountered and no more specific message is suitable.';
 }
index 3818f681aea3c9661c6ad9de43b89b5aff2b0862..dd0c02f8d7e7ed02965821d07fa066010d2f4faf 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
 
 class LenghtRequiredException extends HTTPException
 {
-       protected $code  = 411;
-       var $httpdesc    = 'Length Required';
-       var $explanation = 'The request did not specify the length of its content, which is required by the requested resource.';
+       protected $code        = 411;
+       protected $httpdesc    = 'Length Required';
+       protected $explanation = 'The request did not specify the length of its content, which is required by the requested resource.';
 }
index d09c0fe318113bc2ea37ae3475aea2f4cbd941f7..03841e5e5fae559125e547b343b96de26fd54132 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
 
 class MethodNotAllowedException extends HTTPException
 {
-       protected $code  = 405;
-       var $httpdesc    = 'Method Not Allowed';
-       var $explanation = 'A request method is not supported for the requested resource; for example, a GET request on a form that requires data to be presented via POST, or a PUT request on a read-only resource.';
+       protected $code        = 405;
+       protected $httpdesc    = 'Method Not Allowed';
+       protected $explanation = 'A request method is not supported for the requested resource; for example, a GET request on a form that requires data to be presented via POST, or a PUT request on a read-only resource.';
 }
index ef78f87bd6eb79ba06e7e2346667a7a8e149a800..7ded3847a3c0ca73a845af6e2c15f53c0cf3390f 100644 (file)
@@ -25,6 +25,6 @@ use Friendica\Network\HTTPException;
 
 class MovedPermanentlyException extends HTTPException
 {
-       protected $code = 301;
-       var $httpdesc   = 'Moved Permanently';
+       protected $code     = 301;
+       protected $httpdesc = 'Moved Permanently';
 }
index 90d9d2ae6aa73334f5e8215acbcc2c32a731bebe..f652b66211095aeb3a1e7a517f69e76089afc664 100644 (file)
@@ -25,6 +25,6 @@ use Friendica\Network\HTTPException;
 
 class NoContentException extends HTTPException
 {
-       protected $code = 204;
-       var $httpdesc   = 'No Content';
+       protected $code     = 204;
+       protected $httpdesc = 'No Content';
 }
index c9811ddb79db754cb8709b9385d50e0061b02107..3b1c1538af193a4fb7236e01bd6aa8f1472df838 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
 
 class NonAcceptableException extends HTTPException
 {
-       protected $code  = 406;
-       var $httpdesc    = 'Not Acceptable';
-       var $explanation = 'The requested resource is capable of generating only content not acceptable according to the Accept headers sent in the request.';
+       protected $code        = 406;
+       protected $httpdesc    = 'Not Acceptable';
+       protected $explanation = 'The requested resource is capable of generating only content not acceptable according to the Accept headers sent in the request.';
 }
index 9acc32031dbd69a3a653951fdb057252ed88780b..33731bd1c10f8af872eb674517d403ef2fd8cecf 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
 
 class NotFoundException extends HTTPException
 {
-       protected $code  = 404;
-       var $httpdesc    = 'Not Found';
-       var $explanation = 'The requested resource could not be found but may be available in the future.';
+       protected $code        = 404;
+       protected $httpdesc    = 'Not Found';
+       protected $explanation = 'The requested resource could not be found but may be available in the future.';
 }
index 6c2d1e25e64b48393ca50209197c5bdb93079704..94e7af09164887eea90a928321bd808c11be1c51 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
 
 class NotImplementedException extends HTTPException
 {
-       protected $code  = 501;
-       var $httpdesc    = 'Not Implemented';
-       var $explanation = 'The server either does not recognize the request method, or it lacks the ability to fulfil the request. Usually this implies future availability (e.g., a new feature of a web-service API).';
+       protected $code        = 501;
+       protected $httpdesc    = 'Not Implemented';
+       protected $explanation = 'The server either does not recognize the request method, or it lacks the ability to fulfil the request. Usually this implies future availability (e.g., a new feature of a web-service API).';
 }
index 431b2096a3c8dd58018f9dd6b4fd29e9b334903e..9bdec60f0832f7a82abd23a0c7991ea085efbc21 100644 (file)
@@ -25,6 +25,6 @@ use Friendica\Network\HTTPException;
 
 class NotModifiedException extends HTTPException
 {
-       protected $code = 304;
-       var $httpdesc   = 'Not Modified';
+       protected $code     = 304;
+       protected $httpdesc = 'Not Modified';
 }
index e4b409ce0f1dd0c26c0c54e045ef993dee3e02eb..5daa199a94ceaf1b05899bed2201361174ad6d0e 100644 (file)
@@ -25,6 +25,6 @@ use Friendica\Network\HTTPException;
 
 class OKException extends HTTPException
 {
-       protected $code = 200;
-       var $httpdesc   = 'OK';
+       protected $code     = 200;
+       protected $httpdesc = 'OK';
 }
index fe4ebcb123957309e5a9a436f4dfcc88da9048aa..7a62ca7d56605b2c78780c4175b460265cd6fd11 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
 
 class PreconditionFailedException extends HTTPException
 {
-       protected $code  = 412;
-       var $httpdesc    = 'Precondition Failed';
-       var $explanation = 'The server does not meet one of the preconditions that the requester put on the request header fields.';
+       protected $code        = 412;
+       protected $httpdesc    = 'Precondition Failed';
+       protected $explanation = 'The server does not meet one of the preconditions that the requester put on the request header fields.';
 }
index a88390e6a719a05be65bde02ab306194bbc02904..d520a9df0fed1e337194e473fd35a8cb51c9e373 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
 
 class ServiceUnavailableException extends HTTPException
 {
-       protected $code  = 503;
-       var $httpdesc    = 'Service Unavailable';
-       var $explanation = 'The server is currently unavailable (because it is overloaded or down for maintenance). Please try again later.';
+       protected $code        = 503;
+       protected $httpdesc    = 'Service Unavailable';
+       protected $explanation = 'The server is currently unavailable (because it is overloaded or down for maintenance). Please try again later.';
 }
index cae4be72813a31c536952abb0497fd76f5970036..008e3798cea3798c602f45c3c61bc7c9560a6a03 100644 (file)
@@ -25,6 +25,6 @@ use Friendica\Network\HTTPException;
 
 class TemporaryRedirectException extends HTTPException
 {
-       protected $code = 307;
-       var $httpdesc   = 'Temporary Redirect';
+       protected $code     = 307;
+       protected $httpdesc = 'Temporary Redirect';
 }
index c94679af72b80ebc0ff83633d956076c2ee466f3..0861aaefc7515e0970f634a60d36d020eaaa8533 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
 
 class TooManyRequestsException extends HTTPException
 {
-       protected $code  = 429;
-       var $httpdesc    = 'Too Many Requests';
-       var $explanation = 'The user has sent too many requests in a given amount of time.';
+       protected $code        = 429;
+       protected $httpdesc    = 'Too Many Requests';
+       protected $explanation = 'The user has sent too many requests in a given amount of time.';
 }
index ad6adfd4234aa62f74a85409025a258220c6c21f..4bb2e862856b569d0438532b04aaa9a446bedfbe 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
 
 class UnauthorizedException extends HTTPException
 {
-       protected $code  = 401;
-       var $httpdesc    = 'Unauthorized';
-       var $explanation = 'Authentication is required and has failed or has not yet been provided.';
+       protected $code        = 401;
+       protected $httpdesc    = 'Unauthorized';
+       protected $explanation = 'Authentication is required and has failed or has not yet been provided.';
 }
index 29b0d3158efe36949fd2e29f2f74baf0b12b3f93..9c78b7377012406e40ca8b905e8ad80c47d4bfa5 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
 
 class UnprocessableEntityException extends HTTPException
 {
-       protected $code  = 422;
-       var $httpdesc    = 'Unprocessable Entity';
-       var $explanation = 'The request was well-formed but was unable to be followed due to semantic errors.';
+       protected $code        = 422;
+       protected $httpdesc    = 'Unprocessable Entity';
+       protected $explanation = 'The request was well-formed but was unable to be followed due to semantic errors.';
 }
index adf008d0155ee72d6ec87a43359ddfb7ddd58749..fad8d9f7e779011db225901f35f600b375a74e87 100644 (file)
@@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
 
 class UnsupportedMediaTypeException extends HTTPException
 {
-       protected $code  = 415;
-       var $httpdesc    = 'Unsupported Media Type';
-       var $explanation = 'The request entity has a media type which the server or resource does not support. For example, the client uploads an image as image/svg+xml, but the server requires that images use a different format.';
+       protected $code        = 415;
+       protected $httpdesc    = 'Unsupported Media Type';
+       protected $explanation = 'The request entity has a media type which the server or resource does not support. For example, the client uploads an image as image/svg+xml, but the server requires that images use a different format.';
 }