PHPLIB-242: Refactor Aggregate to use field path syntax in type map

parent b8c159da
...@@ -27,7 +27,6 @@ use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException; ...@@ -27,7 +27,6 @@ use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\Exception\UnexpectedValueException; use MongoDB\Exception\UnexpectedValueException;
use MongoDB\Exception\UnsupportedException; use MongoDB\Exception\UnsupportedException;
use MongoDB\Model\TypeMapArrayIterator;
use ArrayIterator; use ArrayIterator;
use stdClass; use stdClass;
use Traversable; use Traversable;
...@@ -280,16 +279,16 @@ class Aggregate implements Executable ...@@ -280,16 +279,16 @@ class Aggregate implements Executable
return $cursor; return $cursor;
} }
if (isset($this->options['typeMap'])) {
$cursor->setTypeMap(\MongoDB\create_field_path_type_map($this->options['typeMap'], 'result.$'));
}
$result = current($cursor->toArray()); $result = current($cursor->toArray());
if ( ! isset($result->result) || ! is_array($result->result)) { if ( ! isset($result->result) || ! is_array($result->result)) {
throw new UnexpectedValueException('aggregate command did not return a "result" array'); throw new UnexpectedValueException('aggregate command did not return a "result" array');
} }
if (isset($this->options['typeMap'])) {
return new TypeMapArrayIterator($result->result, $this->options['typeMap']);
}
return new ArrayIterator($result->result); return new ArrayIterator($result->result);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment