From 6b2d085063b0c63e6aadcfa9f16aaa183e27ccce Mon Sep 17 00:00:00 2001 From: Samuel Demirdjian Date: Fri, 15 Jan 2016 11:03:25 +0200 Subject: [PATCH] PHP 7: Relax typehint constraint on Exception handling methods --- classes/Kohana/Kohana/Exception.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/classes/Kohana/Kohana/Exception.php b/classes/Kohana/Kohana/Exception.php index 353beb794..4561ba40e 100644 --- a/classes/Kohana/Kohana/Exception.php +++ b/classes/Kohana/Kohana/Exception.php @@ -81,7 +81,7 @@ public function __toString() * @param Exception $e * @return void */ - public static function handler(Exception $e) + public static function handler($e) { $response = Kohana_Exception::_handler($e); @@ -99,7 +99,7 @@ public static function handler(Exception $e) * @param Exception $e * @return Response */ - public static function _handler(Exception $e) + public static function _handler($e) { try { @@ -137,7 +137,7 @@ public static function _handler(Exception $e) * @param string $level * @return void */ - public static function log(Exception $e, $level = \Psr\Log\LogLevel::EMERGENCY) + public static function log($e, $level = \Psr\Log\LogLevel::EMERGENCY) { if (is_object(Kohana::$log)) { @@ -162,8 +162,13 @@ public static function log(Exception $e, $level = \Psr\Log\LogLevel::EMERGENCY) * @param Exception $e * @return string */ - public static function text(Exception $e) + public static function text($e) { + if ( ! $e instanceof Exception AND ! $e instanceof Throwable) + { + throw InvalidArgumentException('Argument 1 passed to Kohana_Kohana_Exception::response() must be an instance of Exception or Throwable'); + } + return sprintf('%s [ %s ]: %s ~ %s [ %d ]', get_class($e), $e->getCode(), strip_tags($e->getMessage()), Debug::path($e->getFile()), $e->getLine()); } @@ -175,8 +180,13 @@ public static function text(Exception $e) * @param Exception $e * @return Response */ - public static function response(Exception $e) + public static function response($e) { + if ( ! $e instanceof Exception AND ! $e instanceof Throwable) + { + throw InvalidArgumentException('Argument 1 passed to Kohana_Kohana_Exception::response() must be an instance of Exception or Throwable'); + } + try { // Get the exception information