director = isset($this->Request['director']) ? $this->Request['director'] : null; $this->user = isset($this->Request['user']) ? $this->Request['user'] : null; if(is_null($this->user) && $this->Application->getModule('configuration')->isApplicationConfig() === true) { $appConfig = ConfigurationManager::getApplicationConfig(); // @TOFIX: Baculum API layer should not use $_SERVER variables. $this->user = isset($_SERVER['PHP_AUTH_USER']) && $_SERVER['PHP_AUTH_USER'] != $appConfig['baculum']['login'] ? $_SERVER['PHP_AUTH_USER'] : null; } switch($_SERVER['REQUEST_METHOD']) { case self::PUT_METHOD: { try { $this->put(); } catch(TDbException $e) { $this->Application->getModule('logging')->log(__FUNCTION__, $e, Logging::CATEGORY_APPLICATION, __FILE__, __LINE__); $this->output = DatabaseError::MSG_ERROR_DB_CONNECTION_PROBLEM; $this->error = DatabaseError::ERROR_DB_CONNECTION_PROBLEM; } break; } case self::GET_METHOD: { try { $this->get(); } catch(TDbException $e) { $this->Application->getModule('logging')->log(__FUNCTION__, $e, Logging::CATEGORY_APPLICATION, __FILE__, __LINE__); $this->output = DatabaseError::MSG_ERROR_DB_CONNECTION_PROBLEM; $this->error = DatabaseError::ERROR_DB_CONNECTION_PROBLEM; } break; } case self::POST_METHOD: { try { $this->post(); } catch(TDbException $e) { $this->Application->getModule('logging')->log(__FUNCTION__, $e, Logging::CATEGORY_APPLICATION, __FILE__, __LINE__); $this->output = DatabaseError::MSG_ERROR_DB_CONNECTION_PROBLEM; $this->error = DatabaseError::ERROR_DB_CONNECTION_PROBLEM; } break; } case self::DELETE_METHOD: { try { $this->delete(); } catch(TDbException $e) { $this->Application->getModule('logging')->log(__FUNCTION__, $e, Logging::CATEGORY_APPLICATION, __FILE__, __LINE__); $this->output = DatabaseError::MSG_ERROR_DB_CONNECTION_PROBLEM; $this->error = DatabaseError::ERROR_DB_CONNECTION_PROBLEM; } break; } } } private function getOutput() { $output = array('output' => $this->output, 'error' => $this->error); return json_encode($output); } public function onLoad($params) { parent::onLoad($params); echo $this->getOutput(); } abstract protected function get(); private function put() { $id = isset($this->Request['id']) ? $this->Request['id'] : null; if(is_array($this->Request['update']) && count($this->Request['update']) > 0) { $params = (object)$this->Request['update']; $this->set($id, $params); } else { parse_str(file_get_contents("php://input"),$responseData); if(is_array($responseData) && array_key_exists('update', $responseData)) { $params = (object)$responseData['update']; $this->set($id, $params); } else { $this->set($id, array()); //@TOVERIFY //$this->output = GenericError::MSG_ERROR_INVALID_COMMAND; //$this->error = GenericError::ERROR_INVALID_COMMAND; } } } private function post() { if(is_array($this->Request['create']) && count($this->Request['create']) > 0) { $params = (object)$this->Request['create']; $this->create($params); } } private function delete() { if(isset($this->Request['id'])) { $id = intval($this->Request['id']); $this->remove($id); } } public function getModule($name) { return $this->Application->getModule($name); } } ?>