/**
  * Converter method to convert a BSON object to its legacy type
  *
  * @param BSON\Type $value
  * @return mixed
  */
 private static function convertBSONObjectToLegacy(BSON\Type $value)
 {
     switch (true) {
         case $value instanceof BSON\ObjectID:
             return new \MongoId($value);
         case $value instanceof BSON\Binary:
             return new \MongoBinData($value);
         case $value instanceof BSON\Javascript:
             return new \MongoCode($value);
         case $value instanceof BSON\MaxKey:
             return new \MongoMaxKey();
         case $value instanceof BSON\MinKey:
             return new \MongoMinKey();
         case $value instanceof BSON\Regex:
             return new \MongoRegex($value);
         case $value instanceof BSON\Timestamp:
             return new \MongoTimestamp($value);
         case $value instanceof BSON\UTCDatetime:
             return new \MongoDate($value);
         case $value instanceof Model\BSONDocument:
         case $value instanceof Model\BSONArray:
             return array_map(['self', 'toLegacy'], $value->getArrayCopy());
         default:
             return $value;
     }
 }
 /**
  * Converts MongoDB BSON object to readable value.
  * @param Type $object MongoDB BSON object.
  * @return array|string object dump value.
  * @since 2.1
  */
 private function dumpBsonObject(Type $object)
 {
     if ($object instanceof Binary && in_array($object->getType(), [Binary::TYPE_MD5, Binary::TYPE_UUID, Binary::TYPE_OLD_UUID], true)) {
         return $object->getData();
     }
     if (method_exists($object, '__toString')) {
         return $object->__toString();
     }
     return ArrayHelper::toArray($object);
 }