/** * @Skip */ public function testDeserializeEmbeddedMaps() { // $this->markTestSkipped(); $x = 'V@"b":[{"xx":{"xxx":[1,2,"abc"]}}],"c":[{"yy":{"yyy":[3,4,"cde"]}}]'; $result = CSV::unserialize($x); $this->assertEquals(["oClass" => 'V', 'b' => [['xx' => ['xxx' => [1, 2, 'abc']]]], 'c' => [['yy' => ['yyy' => [3, 4, 'cde']]]]], $result); }
public function testNodeInitialization() { $jsonNodes = CSV::unserialize($this->stringCSVNodeList); /** * @var $node Record */ foreach ($jsonNodes['members'] as $node) { $orientNode = OrientNode::fromConfig($node->getOData()); $this->assertInstanceOf('PhpOrient\\Protocols\\Common\\OrientNode', $orientNode); $this->assertNotEmpty($orientNode->id); $this->assertNotEmpty($orientNode->name); $this->assertNotEmpty($orientNode->host); $this->assertNotEmpty($orientNode->port); } }
/** * Read the response from the socket. * * @return int The session id. */ protected function _read() { $payloads = []; $status = $this->_readByte(); if ($status != 0) { $payload = []; // a normal record if ($this->_transport->getProtocolVersion() > 27) { $type = $this->_readChar(); $version = $this->_readInt(); if ($type == 'b') { $data[] = $this->_readString(); } else { $data = CSV::unserialize($this->_readString()); } } else { $string = $this->_readString(); $data = CSV::unserialize($string); $version = $this->_readInt(); $type = $this->_readChar(); if ($type == 'b') { $data = $string; } } $payload['rid'] = new ID($this->cluster_id, $this->cluster_position); $payload['type'] = $type; $payload['version'] = $version; if (isset($data['oClass'])) { $payload['oClass'] = $data['oClass']; unset($data['oClass']); } $payload['oData'] = $data; $record = Record::fromConfig($payload); $payloads[] = $record; $prefetched = $this->_read_prefetch_record(); # read cache and prefetch with callback $payloads = array_merge($payloads, $prefetched); } return $payloads; }
/** * The format depends if a RID is passed or an entire * record with its content. * * In case of null record then -2 as short is passed. * * In case of RID -3 is passes as short and then the RID: * (-3:short)(cluster-id:short)(cluster-position:long). * * In case of record: * (0:short)(record-type:byte)(cluster-id:short) * (cluster-position:long)(record-version:int)(record-content:bytes) * * @return array * @throws SocketException */ protected function _readRecord() { $classId = $this->_readShort(); $record = ['classId' => $classId]; if ($classId === -1) { throw new SocketException('No class for record, cannot proceed!'); } elseif ($classId === -2) { // null record $record['bytes'] = null; } elseif ($classId === -3) { // reference $record['type'] = 'd'; $cluster = $this->_readShort(); $position = $this->_readLong(); $record['rid'] = new ID($cluster, $position); } else { $record['type'] = $this->_readChar(); $cluster = $this->_readShort(); $position = $this->_readLong(); $record['version'] = $this->_readInt(); $data = CSV::unserialize($this->_readBytes()); $record['oClass'] = @$data['oClass']; $record['rid'] = new ID($cluster, $position); unset($data['oClass']); $record['oData'] = $data; } return $record; }
/** * Read the response from the socket. * * @return int The session id. */ protected function _read() { $sessionId = $this->_readInt(); $this->_transport->setSessionId($sessionId); $this->_transport->databaseOpened = true; $this->_transport->databaseName = $this->database; $this->_transport->connected = false; if ($this->_transport->getProtocolVersion() > 26) { $token = $this->_readString(); # token if (empty($token)) { $this->_transport->setRequestToken(false); } $this->_transport->setToken($token); } $totalClusters = $this->_readShort(); $dataClusters = []; for ($i = 0; $i < $totalClusters; $i++) { if ($this->_transport->getProtocolVersion() < 24) { $dataClusters[] = ['name' => $this->_readString(), 'id' => $this->_readShort(), 'type' => $this->_readString(), 'dataSegment' => $this->_readShort()]; } else { $dataClusters[] = ['name' => $this->_readString(), 'id' => $this->_readShort()]; } } # cluster config string ( -1 ) # cluster release $cluster_list = ['sessionId' => $sessionId, 'dataClusters' => $dataClusters, 'servers' => CSV::unserialize($this->_readString()), 'release' => $this->_readString()]; $this->_transport->setClustersMap(ClustersMap::fromConfig($cluster_list)); if (!empty($cluster_list['servers'])) { $list = []; foreach ($cluster_list['servers']['members'] as $node) { $list[] = new OrientNode($node); } $this->_transport->setNodesList($list); # LIST WITH THE NEW CLUSTER CFG } $this->_transport->setOrientVersion(OrientVersion::fromConfig($cluster_list)); return $this->_transport->getClusterMap(); }