]> git.sur5r.net Git - bacula/bacula/commitdiff
baculum: Make get method definition not obligatory
authorMarcin Haba <marcin.haba@bacula.pl>
Sun, 28 May 2017 04:43:51 +0000 (06:43 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Sun, 28 May 2017 18:58:33 +0000 (20:58 +0200)
gui/baculum/protected/API/Class/BaculumAPIServer.php

index f3365ffc90d3ab46be3275a9619503d6147f9a31..9d35db4fd9ad4694e90a976ec696915170a5df86 100644 (file)
@@ -138,7 +138,6 @@ abstract class BaculumAPIServer extends TPage {
                        $this->error = AuthorizationError::ERROR_AUTHORIZATION_TO_API_PROBLEM;
                        return;
                }
-
                try {
                        switch($_SERVER['REQUEST_METHOD']) {
                                case self::GET_METHOD: {
@@ -225,15 +224,6 @@ abstract class BaculumAPIServer extends TPage {
                echo $this->getOutput();
        }
 
-       /**
-        * Each of API module should have get() method defined.
-        * Designed to getting data from API.
-        *
-        * @access protected
-        * @return none
-        */
-       abstract protected function get();
-
        /**
         * Changing/updating values via API.
         *
@@ -241,7 +231,7 @@ abstract class BaculumAPIServer extends TPage {
         * @return none
         */
        private function put() {
-               $id = isset($this->Request['id']) ? $this->Request['id'] : null;
+               $id = $this->Request->contains('id') ? $this->Request['id'] : null;
 
                /**
                 * Check if it is possible to read PUT method data.
@@ -250,7 +240,7 @@ abstract class BaculumAPIServer extends TPage {
                 * not possible to ready by superglobal $_REQUEST variable, then is try to
                 * read PUT data by PHP input stream.
                 */
-               if (is_array($this->Request['update']) && count($this->Request['update']) > 0) {
+               if ($this->Request->contains('update') && is_array($this->Request['update']) && count($this->Request['update']) > 0) {
                        // $_REQUEST available to read
                        $params = (object)$this->Request['update'];
                        $this->set($id, $params);
@@ -296,10 +286,11 @@ abstract class BaculumAPIServer extends TPage {
         * @return none
         */
        private function post() {
-               if (is_array($this->Request['create']) && count($this->Request['create']) > 0) {
+               $params = null;
+               if ($this->Request->contains('create') && is_array($this->Request['create']) && count($this->Request['create']) > 0) {
                        $params = (object)$this->Request['create'];
-                       $this->create($params);
                }
+               $this->create($params);
        }
 
        /**
@@ -309,10 +300,11 @@ abstract class BaculumAPIServer extends TPage {
         * @return none
         */
        private function delete() {
-               if (isset($this->Request['id'])) {
+               $id = null;
+               if ($this->Request->contains('id')) {
                        $id = intval($this->Request['id']);
-                       $this->remove($id);
                }
+               $this->remove($id);
        }
 
        /**