Introduce UsageException
This commit is contained in:
committed by
Gilles Crettenand
parent
7e0a38e989
commit
34161ba282
5
Lib/Exception/UsageException.php
Normal file
5
Lib/Exception/UsageException.php
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BSR\Lib\Exception;
|
||||||
|
|
||||||
|
class UsageException extends WebException {}
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace BSR\Lib;
|
namespace BSR\Lib;
|
||||||
|
|
||||||
|
use BSR\Lib\Exception\UsageException;
|
||||||
use BSR\Lib\Exception\WebException;
|
use BSR\Lib\Exception\WebException;
|
||||||
use BSR\Lib\Renderer;
|
|
||||||
|
|
||||||
abstract class WebService
|
abstract class WebService
|
||||||
{
|
{
|
||||||
@@ -74,18 +74,18 @@ abstract class WebService
|
|||||||
|
|
||||||
$params = empty($_GET) ? $_POST : $_GET;
|
$params = empty($_GET) ? $_POST : $_GET;
|
||||||
if (empty($params)) {
|
if (empty($params)) {
|
||||||
throw new WebException ("CallArgument", "arguments error", -1);
|
throw new UsageException("CallArgument", "arguments error", -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!array_key_exists("func", $params)) {
|
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"];
|
$this->func = $params["func"];
|
||||||
unset($params['func']);
|
unset($params['func']);
|
||||||
|
|
||||||
if (!is_callable(array($this, $this->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);
|
$rm = new \ReflectionMethod($this, $this->func);
|
||||||
@@ -95,10 +95,10 @@ abstract class WebService
|
|||||||
|
|
||||||
/* Check the number of arguments. */
|
/* Check the number of arguments. */
|
||||||
if ($nbParams < $nbArgsFix) {
|
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) {
|
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."'");
|
$this->log("Calling '".$this->func."'");
|
||||||
|
|||||||
Reference in New Issue
Block a user