PhpOrient\Protocols\Binary\Serialization\CSV::serialize PHP Method

serialize() public static method

Serialize a value.
public static serialize ( mixed $value, boolean $embedded = false ) : string
$value mixed The value to serialize.
$embedded boolean Whether this is a value embedded in another.
return string The serialized value.
    public static function serialize($value, $embedded = false)
    {
        if ($value === null) {
            return '';
        }
        if (is_string($value)) {
            return '"' . str_replace('"', '\\"', str_replace('\\', '\\\\', $value)) . '"';
        } elseif (is_float($value)) {
            //this because float suffix "f"
            // cut the numbers to the second decimal number
            // if the field in OrientDB is set as double
            return $value . 'd';
        } elseif (is_int($value)) {
            return $value;
        } elseif (is_bool($value)) {
            return $value ? 'true' : 'false';
        } elseif (is_array($value)) {
            return self::serializeArray($value);
        } elseif ($value instanceof SerializableInterface) {
            return self::serializeDocument($value, $embedded);
        } elseif ($value instanceof \DateTime) {
            return $value->getTimestamp() . '000t';
        } elseif ($value instanceof ID) {
            return $value->__toString();
        } elseif ($value instanceof Bag) {
            /*
             * This line works the same, but transforms the edges list to a linkSet
             * //    return self::serializeArray( $value->getRids() );
             *
             * From:
             *
             * ----+-----+------+------+--------+---------
             * #   |@RID |@CLASS|script|out_    |in_
             * ----+-----+------+------+--------+---------
             * 0   |#9:0 |V     |true  |[size=1]|[size=1]
             * ----+-----+------+------+--------+---------
             *
             * To:
             *
             * ----+-----+------+------+--------+---------
             * #   |@RID |@CLASS|script|out_    |in_
             * ----+-----+------+------+--------+---------
             * 0   |#9:0 |V     |true  |[1]     |[1]
             * ----+-----+------+------+--------+---------
             *
             */
            return $value->getRawBagContent();
        } else {
            return '';
        }
    }

Usage Example

Example #1
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);
 }
All Usage Examples Of PhpOrient\Protocols\Binary\Serialization\CSV::serialize