diff --git a/AqlExpression.php b/AqlExpression.php new file mode 100644 index 0000000..fefaac1 --- /dev/null +++ b/AqlExpression.php @@ -0,0 +1,40 @@ +expression = $expression; + parent::__construct($config); + } + + /** + * The PHP magic function converting an object into a string. + * @return string the AQL expression. + */ + public function __toString() + { + return $this->expression; + } +} + \ No newline at end of file diff --git a/Query.php b/Query.php index ba9f9a3..a8a8a71 100644 --- a/Query.php +++ b/Query.php @@ -480,7 +480,7 @@ class Query extends Component implements QueryInterface public function insert($collection, $columns, $params = [], $db = null) { - $doc = Json::encode($columns); + $doc = Serializer::encode($columns); $clauses = [ "INSERT $doc IN {$this->quoteCollectionName($collection)}", @@ -587,7 +587,7 @@ class Query extends Component implements QueryInterface protected function buildUpdate($collection, $columns) { return 'UPDATE ' . $collection . ' WITH ' - . (is_array($columns) ? Json::encode($columns) : $columns) . ' IN ' + . Serializer::encode($columns) . ' IN ' . $this->quoteCollectionName($collection); } diff --git a/Serializer.php b/Serializer.php new file mode 100644 index 0000000..202e131 --- /dev/null +++ b/Serializer.php @@ -0,0 +1,59 @@ +expression; + + return $token; + } elseif ($data instanceof \JsonSerializable) { + $data = $data->jsonSerialize(); + } elseif ($data instanceof Arrayable) { + $data = $data->toArray(); + } else { + $result = []; + foreach ($data as $name => $value) { + $result[$name] = $value; + } + $data = $result; + } + + if ($data === []) { + return new \stdClass(); + } + } + + if (is_array($data)) { + foreach ($data as $key => $value) { + if (is_array($value) || is_object($value)) { + $data[$key] = static::processData($value, $expressions, $expPrefix); + } + } + } + + return $data; + } +} + \ No newline at end of file