public static function toLegacy($value)
{
switch (true) {
case $value instanceof BSON\Type:
return self::convertBSONObjectToLegacy($value);
case is_array($value):
case is_object($value):
$result = [];
foreach ($value as $key => $item) {
$result[$key] = self::toLegacy($item);
}
return $result;
default:
return $value;
}
}
/** * @link http://php.net/manual/en/mongocode.construct.php * @param string $code A string of code * @param array $scope The scope to use for the code */ public function __construct($code, array $scope = []) { if ($code instanceof \MongoDB\BSON\Javascript) { $javascript = $code; $code = $javascript->getCode(); $scope = TypeConverter::toLegacy($javascript->getScope()); } $this->code = $code; $this->scope = $scope; }