public function _api_request_cmd($cmd) { try { if (null === self::$_db) { self::$_db = \frdl\DB::_(array('driver' => $this->data['config']['db-driver'], 'host' => $this->data['config']['db-host'], 'dbname' => $this->data['config']['db-dbname'], 'user' => $this->data['config']['db-user'], 'password' => $this->data['config']['db-pwd'], 'pfx' => $this->data['config']['db-pfx']), false); } } catch (\Exception $e) { /* no explicit need of DB connection here */ } foreach ($this->data['settings']->cli as $cmdpfx => $console) { $t = $console['cli.cmd.cli']; $l = strlen($t); if (substr($cmd, 0, $l) === $t) { $cmd = substr($cmd, $l, strlen($cmd)); if (is_subclass_of($console['cli.class'], $console['cli.class.required.parent']) && is_subclass_of($console['cli.class'], '\\frdl\\aSQL\\Engines\\Terminal\\CLI')) { $this->Console = new $console['cli.class'](); $this->Console->applyApp($this); $this->Console->exe($cmd); return $this->_api_response($this->Console->dump()); } else { \webdof\wResponse::status(501); trigger_error('No valid Console SubClass.', E_USER_NOTICE); continue; } } } \webdof\wResponse::status(404); die('API cli not found'); }
protected function _test_database() { if (true !== $this->loadConfigFromFile(true)) { $this->result->out = 'set config ERROR: cannot readf config file'; return; } ini_set('display_errors', 0); error_reporting(E_ALL); try { $db = \frdl\DB::_(array('driver' => $this->data['config']['db-driver'], 'host' => $this->data['config']['db-host'], 'dbname' => $this->data['config']['db-dbname'], 'user' => $this->data['config']['db-user'], 'password' => $this->data['config']['db-pwd'], 'pfx' => $this->data['config']['db-pfx']), true); } catch (\Exception $e) { $this->result->out = $e->getMessage(); if (isset($this->argtoks['flags']['h'])) { $this->Console->HALT(); } return; } if ($db->connected) { $this->result->code = 200; $this->result->out = 'Ok'; } else { $this->result->code = 409; $this->result->out = 'Error'; } return $this->result; }