/** * Read sync command payloads * * @return array|null * @throws PhpOrientBadMethodCallException * @throws PhpOrientException * @throws SocketException */ public function _read_sync() { # type of response # decode body char with flag continue ( Header already read ) $response_type = $this->_readChar(); $res = []; switch ($response_type) { case 'n': # get end Line \x00 $this->_readChar(); $res = array(null); break; case $response_type == 'r' || $response_type == 'w': $res = [Record::fromConfig($this->_readRecord())]; # get end Line \x00 $this->_readChar(); break; case 'a': $res = [$this->_readString()]; # get end Line \x00 $this->_readChar(); break; case 'l': $list_len = $this->_readInt(); for ($n = 0; $n < $list_len; $n++) { $res[] = Record::fromConfig($this->_readRecord()); } # async-result-type can be: # 0: no records remain to be fetched # 1: a record is returned as a result set # 2: a record is returned as pre-fetched to be loaded in client's # cache only. It's not part of the result set but the client # knows that it's available for later access $cached_results = $this->_read_prefetch_record(); $res = array_merge($res, $cached_results); # cache = cached_results['cached'] break; default: # debug errors if (!Constants::$LOGGING) { throw new PhpOrientException('Unknown payload type ' . $response_type); } $msg = ''; $m = $this->_transport->getSocket()->read(1); while ($m != '') { $msg .= $m; $this->_transport->hexDump($msg); $m = $this->_transport->getSocket()->read(1); } break; } return $res; }
/** * Create a transport instance. * * @param TransportInterface|null $transport * * @return Protocols\Binary\SocketTransport the transport interface * @throws Exceptions\TransportException */ protected function createTransport($transport = null) { if (!$transport instanceof TransportInterface) { if (is_string($transport)) { $_transport = new $transport(); if (!$_transport instanceof TransportInterface) { throw new TransportException($transport . " is not a valid TransportInterface instance"); } } else { //override with default $_transport = new SocketTransport(); } $_transport->configure(array('hostname' => $this->hostname, 'port' => $this->port, 'username' => $this->username, 'password' => $this->password)); } else { $_transport = $transport; } return $_transport; }
/** * @param $transport * * @throws PhpOrientException */ protected function _checkConditions(SocketTransport $transport) { if (!$transport->connected && !$transport->isRequestToken()) { throw new PhpOrientException('Can not perform ' . join('', array_slice(explode('\\', get_class($this)), -1)) . ' operation without a connection.'); } }