Clean up some exceptions, phpdoc
This commit is contained in:
15
Lib/Exception/AuthenticationException.php
Normal file
15
Lib/Exception/AuthenticationException.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace BSR\Lib\Exception;
|
||||
|
||||
/**
|
||||
* This exception should be raised when an error
|
||||
* related to the authentication mechanism arise.
|
||||
*
|
||||
* @package BSR\Lib\Exception
|
||||
*/
|
||||
class AuthenticationException extends WebException {
|
||||
const USER_NOT_FOUND = 200;
|
||||
const BAD_LOGIN = 201;
|
||||
const AUTHENTICATION_FAILED = 202;
|
||||
}
|
||||
@@ -2,8 +2,14 @@
|
||||
|
||||
namespace BSR\Lib\Exception;
|
||||
|
||||
/**
|
||||
* This exception should be raised when trying to access or
|
||||
* manipulate a non-existing book.
|
||||
*
|
||||
* @package BSR\Lib\Exception
|
||||
*/
|
||||
class BookNotFoundException extends WebException {
|
||||
public function __construct($code) {
|
||||
parent::__construct('BookNotFound', "The book with code $code was not found", -404);
|
||||
parent::__construct('BookNotFound', "The book with code $code was not found.", 404);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,4 +2,18 @@
|
||||
|
||||
namespace BSR\Lib\Exception;
|
||||
|
||||
class UsageException extends WebException {}
|
||||
/**
|
||||
* This exception should be raised by the WebService engine when
|
||||
* there is an error preventing the correct calling of a method.
|
||||
*
|
||||
* @package BSR\Lib\Exception
|
||||
*/
|
||||
class UsageException extends WebException {
|
||||
const NO_ARGS = 100;
|
||||
|
||||
const MISSING_METHOD = 101;
|
||||
const BAD_METHOD = 102;
|
||||
|
||||
const TOO_FEW_ARGS = 103;
|
||||
const TOO_MANY_ARGS = 104;
|
||||
}
|
||||
@@ -74,18 +74,18 @@ abstract class WebService
|
||||
|
||||
$params = empty($_GET) ? $_POST : $_GET;
|
||||
if (empty($params)) {
|
||||
throw new UsageException("CallArgument", "arguments error", -1);
|
||||
throw new UsageException("NoArguments", "No arguments specified.", UsageException::NO_ARGS);
|
||||
}
|
||||
|
||||
if (!array_key_exists("func", $params)) {
|
||||
throw new UsageException("CallArgFunction", "no 'func' specified", -2);
|
||||
throw new UsageException("MissingMethod", "No method specified.", UsageException::MISSING_METHOD);
|
||||
}
|
||||
|
||||
$this->func = $params["func"];
|
||||
unset($params['func']);
|
||||
|
||||
if (!is_callable(array($this, $this->func))) {
|
||||
throw new UsageException("CallFunction", "'func' method not available", -3);
|
||||
throw new UsageException("BadMethod", "Method {$this->func} does not exists.", UsageException::BAD_METHOD);
|
||||
}
|
||||
|
||||
$rm = new \ReflectionMethod($this, $this->func);
|
||||
@@ -95,10 +95,10 @@ abstract class WebService
|
||||
|
||||
/* Check the number of arguments. */
|
||||
if ($nbParams < $nbArgsFix) {
|
||||
throw new UsageException("CallArgNumber", "you must provide at least " . $nbArgsFix . " arguments", 4);
|
||||
throw new UsageException("TooManyArgs", "You must provide at least $nbArgsFix arguments.", UsageException::TOO_MANY_ARGS);
|
||||
}
|
||||
if ($nbParams > $nbArgs) {
|
||||
throw new UsageException("CallArgNumber", "you must provide at most " . $nbArgs . " arguments", 4);
|
||||
throw new UsageException("TooFewArgs", "You must provide at most $nbArgs arguments.", UsageException::TOO_FEW_ARGS);
|
||||
}
|
||||
|
||||
$this->log("Calling '".$this->func."'");
|
||||
|
||||
Reference in New Issue
Block a user