Skip to content

Commit 7ea0da3

Browse files
committed
PHPCAS-109 Add try&catch around all the runtime errors. If we run in cli (phunit mode) we rethrow them again and during normal webserver mode we simply exit()
git-svn-id: https://source.jasig.org/cas-clients/phpcas/trunk@24935 f5dbab47-78f9-eb45-b975-e544023573eb
1 parent ec741fe commit 7ea0da3

File tree

4 files changed

+561
-458
lines changed

4 files changed

+561
-458
lines changed

source/CAS.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,20 @@ public static function setNoClearTicketsFromUrl() {
16351635
$PHPCAS_CLIENT->setNoClearTicketsFromUrl();
16361636
phpCAS :: traceEnd();
16371637
}
1638+
1639+
/**
1640+
*
1641+
* Force phpcas to thow Exceptions instead of calling exit()
1642+
*/
1643+
public static function throwExceptionsInsteadOfExiting(){
1644+
global $PHPCAS_CLIENT;
1645+
phpCAS :: traceBegin();
1646+
if (!is_object($PHPCAS_CLIENT)) {
1647+
phpCAS :: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
1648+
}
1649+
$PHPCAS_CLIENT->throwExceptionsInsteadOfExiting();
1650+
phpCAS :: traceEnd();
1651+
}
16381652

16391653
/** @} */
16401654

source/CAS/AuthenticationException.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,22 @@ public function __construct($client,$failure,$cas_url,$no_response,$bad_response
4646
phpCAS::trace('CAS response: '.$cas_response);
4747
}
4848
$client->printHTMLFooter();
49-
phpCAS::traceExit();
49+
phpCAS::traceEnd();
50+
}
51+
52+
/**
53+
* Decide what to do with the exception
54+
* @param CAS_Client $client
55+
*/
56+
public function handleException(CAS_Client $client){
57+
phpCAS::traceBegin();
58+
if($client->isThrowingExceptionsEnabled() || php_sapi_name() === 'cli'){
59+
phpCAS::traceEnd();
60+
throw $this;
61+
}else{
62+
phpCAS::traceExit();
63+
exit();
64+
}
5065
}
5166

5267
}

0 commit comments

Comments
 (0)