diff --git a/src/Webservice/WebService.php b/src/Webservice/WebService.php index 683ef01..acd3a8c 100644 --- a/src/Webservice/WebService.php +++ b/src/Webservice/WebService.php @@ -10,6 +10,7 @@ use Bsr\Utils\Logger\Logger; abstract class WebService { private $func = null; + private $status = 200; private $version = null; @@ -33,11 +34,12 @@ abstract class WebService $data = array(); try { + $result = $this->call($sendSession); $data["result"][$this->func] = $result; - // Logger::log(print_r($result, true)); } catch (WebException $e) { + $data["error"]["code"] = $e->getCode(); $data["error"]["reason"] = $e->getMessage(); $data["error"]["name"] = $e->getName(); @@ -47,12 +49,15 @@ abstract class WebService $this->status = 400; Logger::info($e->getName(), 'error'); + } catch (\Exception $e) { + $data["failure"]["code"] = $e->getCode(); $data["failure"]["reason"] = $e->getMessage(); $this->status = 500; Logger::info($e->getMessage(), 'error'); + } Logger::stop(array('status' => $this->status)); @@ -75,14 +80,17 @@ abstract class WebService } $params = empty($_GET) ? $_POST : $_GET; + if (empty($params)) { throw new UsageException("NoArguments", "No arguments specified.", UsageException::NO_ARGS); } - if (!array_key_exists("func", $params)) { + if (!isset($params["func"])) { throw new UsageException("MissingMethod", "No method specified.", UsageException::MISSING_METHOD); } + $params = $this->filterParams($params); + $this->func = $params["func"]; unset($params['func']); @@ -109,4 +117,13 @@ abstract class WebService return call_user_func_array(array($this, $this->func), $params); } + + /** + * Allow subclasses to filter params by overriding this + * @param $params + */ + protected function filterParams($params) + { + return $params; + } }