From 92d9435bba44ee7114aaf2d0fc51e4292fc9acf4 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Fri, 15 Feb 2013 16:29:00 +0000 Subject: [PATCH] Added method to get the exception type --- src/OAuth2/AuthServer.php | 13 ++++++++++++- tests/authentication/AuthServerTest.php | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/OAuth2/AuthServer.php b/src/OAuth2/AuthServer.php index 69a78831..82f464fa 100644 --- a/src/OAuth2/AuthServer.php +++ b/src/OAuth2/AuthServer.php @@ -67,7 +67,7 @@ class AuthServer * Exception error codes * @var array */ - protected $exceptionCodes = array( + protected static $exceptionCodes = array( 0 => 'invalid_request', 1 => 'unauthorized_client', 2 => 'access_denied', @@ -110,6 +110,17 @@ class AuthServer return self::$exceptionMessages[$error]; } + /** + * Get an exception code + * + * @param integer $code The exception code + * @return string The exception code type + */ + public static function getExceptionType($code = 0) + { + return self::$exceptionCodes[$code]; + } + /** * Create a new OAuth2 authentication server * diff --git a/tests/authentication/AuthServerTest.php b/tests/authentication/AuthServerTest.php index a6b2b1b3..f8f3e35e 100644 --- a/tests/authentication/AuthServerTest.php +++ b/tests/authentication/AuthServerTest.php @@ -45,6 +45,11 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase $this->assertEquals($v['access_denied'], $m); } + public function test_getExceptionCode() + { + $this->assertEquals('access_denied', OAuth2\AuthServer::getExceptionType(2)); + } + public function test_hasGrantType() { $this->assertFalse(OAuth2\AuthServer::hasGrantType('test'));