/** * Tests Cmd::addOptionIfNotEmpty */ public function testAddOptionIfEmptyAsValue() { $cmd = new Cmd('foo'); $cmd->addOptionIfNotEmpty('-bar', ''); $this->assertEquals('foo', (string) $cmd, 'option should not be added'); $cmd->addOptionIfNotEmpty('-bar', 'fiz'); $this->assertEquals('foo -bar=\'fiz\'', (string) $cmd, 'option should be added'); }
/** * Tests Process::isOutputRedirected */ public function testRedirect() { $cmd = new Cmd('echo'); $cmd->addArgument('foo'); $process = new Process(); $process->addCommand($cmd); $this->assertFalse($process->isOutputRedirected()); $process->redirectOutputTo('/tmp/foo'); $this->assertTrue($process->isOutputRedirected()); $this->assertEquals('/tmp/foo', $process->getRedirectPath()); }
function __construct($completekey = 'tab', $stdin = false, $stdout = false) { $this->intro = sprintf(<<<EOT PHP %s (%s), on %s Type "help" for more information EOT , PHP_VERSION, PHP_SAPI, PHP_OS); parent::__construct($completekey, $stdin, $stdout); }
/** * * Configure the root directory for an object implementing the RootDirectory interface. * * @params \apf\iface\RootDirectoryInterface An object implementing the root directory interface. * @params \apf\iface\Log An object implementing the log interface. * */ public static function configureSubDirectories(SubDirectoriesInterface &$config, LogInterface &$log) { do { try { Cmd::clear(); $log->info('[ Please specify the subs directory ]'); $log->repeat('-', 80, 'light_purple'); $log->info('Press \'<\' to go back | Press \'!\' to reset this option'); $log->repeat('-', 80, 'light_purple'); $dir = $config->getSubsDirectory(); if ($dir) { $log->success("Current value: {$config->getSubsDirectory()}"); $log->repeat('-', 80, 'light_purple'); } if (!$dir) { $dir = new Dir(realpath(getcwd())); if ($config instanceof NameableInterface) { $dir->addPath($config->getName()); } } $opt = trim(Cmd::readWithDefault('>', $dir, $log)); if ($opt == '<') { return; } if ($opt == '!') { $config->unsetSubsDirectory(); continue; } $config->setSubsDirectory(new Dir($opt)); } catch (\Exception $e) { $log->error($e->getMessage()); Cmd::readInput('Press enter to continue ...'); } } while (!$config->getSubsDirectory()); return TRUE; }
/** * 向master发送对应命令字的结果 * 协议如下char<cmd>/unsigned int<pack_len>/string<serialize(result)> * @param char $cmd * @param mix $result * @return false/int */ protected function reportToMaster($cmd, $result) { $pack_data = Cmd::encodeForWorker($cmd, $result); return $this->blockWrite($this->channel, $pack_data); }
/** * 向特定的worker发送命令 * @param char $cmd * @param int $pid * @return boolean|string|mixed */ protected static function sendCmdToWorker($cmd, $pid) { // 如果是ping心跳包,则计数 if ($cmd == Cmd::CMD_PING) { if (!isset(self::$pingInfo[$pid])) { self::$pingInfo[$pid] = 0; } self::$pingInfo[$pid]++; } // 写入命令 if (!@fwrite(self::$channels[$pid], Cmd::encodeForMaster($cmd), 1)) { self::notice("send cmd:{$cmd} to pid:{$pid} fail"); self::monitorWorkers(); } }
<?php require_once 'pb_proto_cmd.php'; require_once 'pb_proto_result.php'; // 建立与服务端的链接 $socket = stream_socket_client("tcp://192.168.1.248:8490", $err_no, $err_msg); if (!$socket) { exit($err_msg); } // 设置为阻塞模式 stream_set_blocking($socket, true); $cmd = new Cmd(); //登录 //$cmd->setObj('\Server\Member'); //$cmd->setMethod('authLogin'); //$cmd->appendParams('moxiaobai'); //$cmd->appendParams('rxg622124'); //在线数据 $cmd->setObj('\\Server\\Online'); $cmd->setMethod('addUserOnline'); $cmd->appendParams('1'); $cmd->appendParams('爱琴海'); $cmd->appendParams('13392'); //$cmd->setMethod('deleteUserOnline'); //$cmd->appendParams('1'); //$cmd->appendParams('13392'); $buffer = $cmd->SerializeToString(); $total_length = 4 + strlen($buffer); $buffer = pack('N', $total_length) . $buffer; stream_socket_sendto($socket, $buffer); // 读取服务端返回的数据
/** * Executer une commande. * @param string $cmdText La commande. * @param Terminal $terminal Le terminal ou exeuter la commande. */ public function execute($cmdText, $terminal) { $cmd = new Cmd($this->webos, $this->webos->getAuthorization(), $cmdText, $terminal); $cmd->run(); }
<?php require_once 'pb_proto_cmd.php'; require_once 'pb_proto_result.php'; // 建立与服务端的链接 $socket = stream_socket_client("tcp://192.168.1.248:8480", $err_no, $err_msg); if (!$socket) { exit($err_msg); } // 设置为阻塞模式 stream_set_blocking($socket, true); $cmd = new Cmd(); $cmd->setObj('\\Server\\Member'); $cmd->setMethod('getPbUserInfo'); $cmd->appendParams('13392'); $buffer = $cmd->SerializeToString(); $total_length = 4 + strlen($buffer); $buffer = pack('N', $total_length) . $buffer; stream_socket_sendto($socket, $buffer); // 读取服务端返回的数据 $result = stream_socket_recvfrom($socket, 65535); $result = substr($result, 4); $rs = new Result(); try { $rs->parseFromString($result); } catch (Exception $e) { exit($e->getMessage()); } $rs->dump(); // 关闭链接 fclose($socket);
public function CompileArduino($_AID = '') { $arduidomRadioCmd = $this->getCmd(null, 'arduidom'); if (!is_object($arduidomRadioCmd)) { $arduidomRadioCmd = new Cmd(); } $arduidomRadioCmd->setName(__('Test', __FILE__)); $arduidomRadioCmd->setLogicalId('arduidom'); $arduidomRadioCmd->setEqLogic_id($this->getId()); $arduidomRadioCmd->setUnite('DATS'); $arduidomRadioCmd->setType('info'); $arduidomRadioCmd->setEventOnly(1); $arduidomRadioCmd->setSubType('numeric'); $arduidomRadioCmd->save(); }
<?php session_start(); require_once 'engine/config.php'; include_once 'engine/database.engine.php'; $database = new Database(); include_once 'engine/shoutbox.engine.php'; $shoutbox = new Shoutbox(); include_once 'engine/cmd.engine.php'; $cmd = new Cmd(); if (@$_POST['a'] == 'getstatus') { include_once 'engine/users.engine.php'; $users = new Users(); $users->getAllStatut(); } if (@$_POST['a'] == 'updatestatus' && is_numeric(@$_POST['s'])) { include_once 'engine/users.engine.php'; $users = new Users(); $users->updateStatut(@$_POST['s']); } if (@$_POST['a'] == 'getnewshout' && is_numeric(@$_POST['i'])) { $new_count = count($database->getAllShout()); $lastest = $new_count - @$_POST['i']; if ($lastest <= 0) { $lastest = 0; echo '-1'; } else { echo $shoutbox->getLastShout($lastest); } } if (@$_POST['a'] == 'postnewshout' && @$_POST['m'] != "") {