signature = $this->signature . ' {source} {result} {--unn=}'; parent::__construct(); } public function __get($get) { if ($get == 'data') { return $this->prepareRaw(); } else { return null; } } private function prepareInput() { if($this->argument('source') != 'null') { $source_file = CORE_PATH . '/temp/' . $this->argument('source'); Log::debug(file_get_contents($source_file)); $data = parse_ini_file($source_file); if (isset($data['raw_result'])) { unset($data['raw_result']); } return $data; } return []; } private function prepareOutput() { if($this->argument('source') != 'null') { $source_file = CORE_PATH . '/temp/' . $this->argument('source'); $data = parse_ini_file($source_file); if (isset($data['raw_result'])) { return json_decode(base64_decode($data['raw_result']), true); } } return null; } public function save($result) { if($this->argument('result') != 'null') { $result_file = CORE_PATH . '/temp/' . $this->argument('result'); file_put_contents($result_file, json_encode($result)); } else { $this->info(json_encode($result)); } } private function getCoreConfig($name, $default = null) { $config = parse_ini_file(CORE_PATH . '/../../db.ini'); $config = array_change_key_case($config); return $config[$name] ?? $default; } public function initDB() { $code = $this->option('unn'); DB::disconnect('mysql'); Config::set('database.connections.mysql.username', $this->getCoreConfig('user', 'hrc')); Config::set('database.connections.mysql.password', $this->getCoreConfig('password', 'hrc.lan')); Config::set('database.connections.mysql.host', $this->getCoreConfig('server', '127.0.0.1')); Config::set('database.connections.mysql.port', $this->getCoreConfig('port', '3306')); Config::set('database.connections.mysql.database', $code); DB::reconnect(); } public function handle() { $input = $this->prepareInput(); $output = $this->prepareOutput(); try { $this->initDB(); $result = $this->command($input, $output); } catch (\Exception $e) { $result = [ 'status' => 'error', 'message' => $e->getMessage() ]; } $this->save($result); } }