Exemplo n.º 1
0
 /**
  * @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);
 }
Exemplo n.º 2
0
 /**
  * Write the data to the socket.
  */
 protected function _write()
 {
     if ($this->_transport->getProtocolVersion() < 24) {
         $this->_writeInt($this->segment);
     }
     $this->_writeShort($this->cluster_id);
     $this->_writeBytes(CSV::serialize($this->record));
     // record type
     $this->_writeChar($this->record_type);
     $this->_writeByte($this->mode);
 }
Exemplo n.º 3
0
 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);
     }
 }
Exemplo n.º 4
0
 /**
  * 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;
 }
Exemplo n.º 5
0
 /**
  * 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;
 }
Exemplo n.º 6
0
 /**
  * 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();
 }
Exemplo n.º 7
0
 /**
  * Write the data to the socket.
  */
 protected function _write()
 {
     if (!empty($this->rid) && $this->rid instanceof ID) {
         $this->cluster_id = $this->rid->cluster;
         $this->cluster_position = $this->rid->position;
     }
     $this->record->setRid(new ID($this->cluster_id, $this->cluster_position));
     $this->_writeShort($this->cluster_id);
     $this->_writeLong($this->cluster_position);
     if ($this->_transport->getProtocolVersion() >= 23) {
         $this->_writeBoolean($this->update_content);
     }
     $this->_writeBytes(CSV::serialize($this->record));
     $this->_writeInt($this->record_version_policy);
     $this->_writeChar($this->record_type);
     $this->_writeBoolean($this->mode);
 }
Exemplo n.º 8
0
 public function attach(Operation $operation)
 {
     if ($operation instanceof RecordUpdate) {
         $operationPayload = [['_writeByte', 1], ['_writeShort', $operation->cluster_id], ['_writeLong', (string) $operation->cluster_position], ['_writeChar', $operation->record_type], ['_writeInt', $operation->record_version], ['_writeString', CSV::serialize($operation->record)]];
         if ($this->_transport->getProtocolVersion() >= 23) {
             $operationPayload[] = ['_writeBoolean', $operation->update_content];
         }
         $this->_operation_stack[] = $operationPayload;
         $this->_pre_operation_records[$operation->cluster_position] = $operation;
     } elseif ($operation instanceof RecordDelete) {
         $this->_operation_stack[] = [['_writeByte', 2], ['_writeShort', $operation->cluster_id], ['_writeLong', (string) $operation->cluster_position], ['_writeChar', $operation->record_type], ['_writeInt', $operation->record_version]];
     } elseif ($operation instanceof RecordCreate) {
         $this->_operation_stack[] = [['_writeByte', 3], ['_writeShort', -1], ['_writeLong', (string) $this->_temp_cluster_position_seq], ['_writeChar', $operation->record_type], ['_writeString', CSV::serialize($operation->record)]];
         $this->_pre_operation_records[$this->_temp_cluster_position_seq] = $operation;
         $this->_temp_cluster_position_seq--;
     } else {
         throw new PhpOrientBadMethodCallException("Wrong command type " . get_class($operation));
     }
     return $this;
 }