示例#1
0
 public function testSerializeEmbeddedDocument()
 {
     $doc = new Document(new MockDatabase());
     $doc->setClass('OUser');
     $doc->setAttributes(['name' => 'Charles', 'status' => 'ACTIVE']);
     $input = ['doc' => $doc];
     $output = Serializer::serialize($input);
     $this->assertEquals('{"doc":(OUser@name:"Charles",status:"ACTIVE")}', $output);
 }
示例#2
0
 /**
  * Write the data to the socket.
  */
 protected function write()
 {
     $this->writeInt($this->segment);
     $this->writeShort($this->cluster);
     $this->writeBytes(Serializer::serialize($this->record));
     // record type
     if ($this->record instanceof DocumentInterface) {
         $this->writeChar('d');
     } else {
         $this->writeChar('b');
         // @todo determine from record
     }
     $this->writeByte($this->mode);
 }
示例#3
0
 /**
  * Write the data to the socket.
  */
 protected function write()
 {
     $id = $this->record->getId();
     $this->writeShort($id->cluster);
     $this->writeLong($id->position);
     $this->writeBytes(Serializer::serialize($this->record));
     $this->writeInt($this->record->getVersion());
     // record type
     if ($this->record instanceof DocumentInterface) {
         $this->writeChar('d');
     } else {
         $this->writeChar('b');
         // @todo determine from record
     }
     $this->writeByte($this->mode);
 }
示例#4
0
 /**
  * Serialize the parameters for the query.
  *
  * > Note: There is a bug in OrientDB where special kinds of string values
  * > need to be twice quoted *in parameters*. Hence the need for this specialist function.
  *
  * @return string The serialized parameters.
  */
 protected function serializeParams()
 {
     $collected = [];
     foreach ($this->params as $key => $value) {
         if (is_string($value) && strlen($value)) {
             $c = $value[0];
             $isQuotable = $c === '#' || $c === '<' || $c === '[' || $c === '(' || $c === '{' || $c === '0' || is_numeric($c);
             if ($isQuotable) {
                 $collected[$key] = '"' . $value . '"';
             } else {
                 $collected[$key] = $value;
             }
         } else {
             $collected[$key] = $value;
         }
     }
     $serialized = Serializer::serialize($collected);
     return "params:" . $serialized;
 }