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 authored and acoulton committed Mar 6, 2018
1 parent 9bd4ba9 commit 700a7fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ You're really going to want to read this.

## Unreleased

* Relax typehint for error handlers to support PHP7 exceptions / throwables
* Refactor Request_Client_Internal to support extension of code that loads and executes controllers.
Note: now calls `->execute()` directly : no longer uses ReflectionMethod->invoke() - may cause a fatal
if you somehow route a request to a class that is not a controller.
Expand Down
30 changes: 20 additions & 10 deletions classes/Kohana/Kohana/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ public function __toString()
* exception, and the stack trace of the error.
*
* @uses Kohana_Exception::response
* @param Exception $e
* @param Throwable|Exception $e
* @return void
*/
public static function handler(Exception $e)
public static function handler($e)
{
$response = Kohana_Exception::_handler($e);

Expand All @@ -96,10 +96,10 @@ public static function handler(Exception $e)
* for display.
*
* @uses Kohana_Exception::response
* @param Exception $e
* @param Throwable|Exception $e
* @return Response
*/
public static function _handler(Exception $e)
public static function _handler($e)
{
try
{
Expand Down Expand Up @@ -133,11 +133,11 @@ public static function _handler(Exception $e)
* Logs an exception.
*
* @uses Kohana_Exception::text
* @param Exception $e
* @param Throwable|Exception $e
* @param int $level
* @return void
*/
public static function log(Exception $e, $level = Log::EMERGENCY)
public static function log($e, $level = Log::EMERGENCY)
{
if (is_object(Kohana::$log))
{
Expand All @@ -157,11 +157,16 @@ public static function log(Exception $e, $level = Log::EMERGENCY)
*
* Error [ Code ]: Message ~ File [ Line ]
*
* @param Exception $e
* @param Throwable|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 @@ -170,11 +175,16 @@ public static function text(Exception $e)
* Get a Response object representing the exception
*
* @uses Kohana_Exception::text
* @param Exception $e
* @param Throwable|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

0 comments on commit 700a7fb

Please sign in to comment.