/** * Execute command * * @return \LWMail\Protocol (this) */ protected final function exec() { $this->data = array(); $this->raw_data = array(); $this->has_error = false; foreach ($this->command_stack as $name => $data) { $result = ""; $response = ""; $commands = $data['commands']; $eof = $data['eof']; if (!is_array($commands) || empty($commands)) { continue; } $eol = $this->getOption('eol', "\r\n"); if ($result = $this->stream->send(join($eol, $commands) . $eol)) { $result = $this->stream->getline($response, $eof); } $this->has_error = !$result || $this->has_error; $this->raw_data[$name] = $response; $method = "parse" . join('', array_map('ucfirst', explode('_', strtolower($name)))); if (method_exists($this, $method)) { $result = $this->{$method}($response, $this->data[$name]); $this->has_error = !$result || $this->has_error; } } $this->command_stack = array(); return $this; }
/** * 发送数据给服务端 * * @param string $method * @param array $arguments */ public function sendData($method, $arguments) { $bin_data = JsonProtocol::encode(array('class' => $this->serviceName, 'method' => $method, 'param_array' => $arguments)) . "\r\n"; $this->openConnection(); if (self::$useSwoole) { return $this->swooleClient->send($bin_data); } else { return fwrite($this->connection, $bin_data) == strlen($bin_data); } }
/** * Check that the file hasn't already been seen * @param array $info The music files tag data * @return boolean */ function duplicate_check($info) { $query = strtolower($info['artist'] . '/' . $info['album'] . '/' . $info['title']); if (in_array($query, $this->musicDuplicates)) { $this->Output->send(' %5- Duplicate Song File%n'); return TRUE; } else { $this->musicDuplicates[] = $query; return FALSE; } }
/** * Create folders recursively * @param string $finalFolder The files destined location * @param string $niceFolderName The string to remove to shorten the folder name when sent to screen * @return string */ function recursive_mkDir($finalFolder, $niceFolderName = '') { //Create the new folders if and where required $finalFolder = str_replace($this->illegalChars, '', $finalFolder); $finalFolder = explode('/', substr($finalFolder, 0, strrpos($finalFolder, '/'))); $appendFolder = ''; foreach ($finalFolder as $folder) { $mkDir = $appendFolder . $folder; if ($mkDir != '' && file_exists($mkDir) == FALSE) { mkdir($mkDir); $this->Output->send('%3Making folder: ' . str_replace($niceFolderName, '', $mkDir) . '%n'); } $appendFolder .= $folder . '/'; } return $appendFolder; }
/** * Desconnects from SMSC/SMS gateway gracefully * @access public * @return boolean Always TRUE */ public function disconnect() { if ($this->state == ESS_BIND_TX || $this->state == ESS_BIND_RX) { l('ESME sending UNBIND command...'); $this->sock->send($this->form_pdu(UNBIND)); $pdu = $this->sock->pdu_wait_for(UNBIND | ACK, $this->sqn); $res = $this->parse_pdu_header(substr($pdu, 0, 16)); if ($res['stat'] !== 0) { l('UNBIND failed: ' . $res['stat'] . '.', L_WARN); } else { l('UNBIND done.'); } } $this->state = ESS_DISCONNECTED; $this->sock->disconnect(); return true; }
/** * Logs the current command * * @access public * @param resource $rpc_conn The connection resource * @param array $auth Array of authentication information (email, password) * @param string $command The command used to run this script. */ function log($rpc_conn, $auth, $command) { $command = base64_encode($command); $msg = new XML_RPC_Message("logCommand", array(new XML_RPC_Value($auth[0], 'string'), new XML_RPC_Value($auth[1], 'string'), new XML_RPC_Value($command, 'string'))); $result = $rpc_conn->send($msg); if ($result->faultCode()) { Command_Line::quit($result->faultString()); } }