diff --git a/src/ApiProblem/ApiProblem.php b/src/ApiProblem/ApiProblem.php index 95c54f6..5fee9d9 100644 --- a/src/ApiProblem/ApiProblem.php +++ b/src/ApiProblem/ApiProblem.php @@ -127,6 +127,18 @@ public function __construct($status, $detail, $title = '', $type = '', array $ad */ public static function fromException(Exception $exception, $title = '', $type = '', array $additionalDetails = []) { + return self::fromThrowable($exception, $title, $type, $additionalDetails); + } + + /** + * @param Throwable $throwable + * @param string $title + * @param string $type + * @param array $additionalDetails + * + * @return ApiProblem + */ + public static function fromThrowable(Throwable $throwable, $title = '', $type = '', array $additionalDetails = []) { $eCode = $exception->getCode(); $code = (!empty($eCode) && is_int($eCode)) ? $eCode : 500; diff --git a/src/ApiProblem/ApiProblemResponse.php b/src/ApiProblem/ApiProblemResponse.php index dfe80cf..4daab0e 100644 --- a/src/ApiProblem/ApiProblemResponse.php +++ b/src/ApiProblem/ApiProblemResponse.php @@ -72,6 +72,23 @@ public static function fromExceptionToJson( ) { return new self(new JsonPresenter(ApiProblem::fromException($exception, $title, $type, $additionalDetails))); } + + /** + * @param Throwable $throwable + * @param string $title + * @param string $type + * @param array $additionalDetails + * + * @return ApiProblemResponse + */ + public static function froThrowableToJson( + Throwable $throwable, + $title = '', + $type = '', + array $additionalDetails = [] + ) { + return new self(new JsonPresenter(ApiProblem::fromThrowable($throwable, $title, $type, $additionalDetails))); + } /** * @param $status @@ -103,4 +120,21 @@ public static function fromExceptionToXml( ) { return new self(new XmlPresenter(ApiProblem::fromException($exception, $title, $type, $additionalDetails))); } + + /** + * @param Throwable $throwable + * @param string $title + * @param string $type + * @param array $additionalDetails + * + * @return ApiProblemResponse + */ + public static function fromThroableToXml( + Throwable $throwable, + $title = '', + $type = '', + array $additionalDetails = [] + ) { + return new self(new XmlPresenter(ApiProblem::fromThrowable($throwable, $title, $type, $additionalDetails))); + } }