Skip to content

Commit

Permalink
PHP 7: Relax typehint constraint on Exception handling methods
Browse files Browse the repository at this point in the history
  • Loading branch information
enov committed Jan 15, 2016
1 parent a74e5b9 commit 6b2d085
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions classes/Kohana/Kohana/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
{
Expand Down Expand Up @@ -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))
{
Expand All @@ -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());
}
Expand All @@ -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
Expand Down

2 comments on commit 6b2d085

@gnovaro
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use Throwable
exception_hierarchy

@acoulton
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gnovaro this doesn't use Throwable because that was only added in PHP7 and this is intended to also support 5.x

Please sign in to comment.