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 '';
}
}