Introduce UsageException
This commit is contained in:
committed by
Gilles Crettenand
parent
7e0a38e989
commit
34161ba282
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace BSR\Lib;
|
||||
|
||||
use BSR\Lib\Exception\UsageException;
|
||||
use BSR\Lib\Exception\WebException;
|
||||
use BSR\Lib\Renderer;
|
||||
|
||||
abstract class WebService
|
||||
{
|
||||
@@ -74,18 +74,18 @@ abstract class WebService
|
||||
|
||||
$params = empty($_GET) ? $_POST : $_GET;
|
||||
if (empty($params)) {
|
||||
throw new WebException ("CallArgument", "arguments error", -1);
|
||||
throw new UsageException("CallArgument", "arguments error", -1);
|
||||
}
|
||||
|
||||
if (!array_key_exists("func", $params)) {
|
||||
throw new WebException ("CallArgFunction", "no 'func' specified", -2);
|
||||
throw new UsageException("CallArgFunction", "no 'func' specified", -2);
|
||||
}
|
||||
|
||||
$this->func = $params["func"];
|
||||
unset($params['func']);
|
||||
|
||||
if (!is_callable(array($this, $this->func))) {
|
||||
throw new WebException ("CallFunction", "'func' method not available", -3);
|
||||
throw new UsageException("CallFunction", "'func' method not available", -3);
|
||||
}
|
||||
|
||||
$rm = new \ReflectionMethod($this, $this->func);
|
||||
@@ -95,10 +95,10 @@ abstract class WebService
|
||||
|
||||
/* Check the number of arguments. */
|
||||
if ($nbParams < $nbArgsFix) {
|
||||
throw new WebException ("CallArgNumber", "you must provide at least " . $nbArgsFix . " arguments", 4);
|
||||
throw new UsageException("CallArgNumber", "you must provide at least " . $nbArgsFix . " arguments", 4);
|
||||
}
|
||||
if ($nbParams > $nbArgs) {
|
||||
throw new WebException ("CallArgNumber", "you must provide at most " . $nbArgs . " arguments", 4);
|
||||
throw new UsageException("CallArgNumber", "you must provide at most " . $nbArgs . " arguments", 4);
|
||||
}
|
||||
|
||||
$this->log("Calling '".$this->func."'");
|
||||
|
||||
Reference in New Issue
Block a user