Alcaeus\MongoDbAdapter\TypeConverter::fromLegacy PHP Method

fromLegacy() public static method

This method handles type conversion from ext-mongo to ext-mongodb: - For all types (MongoId, MongoDate, etc.) it returns the correct BSON object instance - For arrays and objects it iterates over properties and converts each item individually - For other types it returns the value unconverted
public static fromLegacy ( mixed $value ) : mixed
$value mixed
return mixed
    public static function fromLegacy($value)
    {
        switch (true) {
            case $value instanceof TypeInterface:
                return $value->toBSONType();
            case is_array($value):
            case is_object($value):
                $result = [];
                foreach ($value as $key => $item) {
                    $result[$key] = self::fromLegacy($item);
                }
                return self::ensureCorrectType($result, is_object($value));
            default:
                return $value;
        }
    }

Usage Example

 /**
  * @return \MongoDB\Driver\Cursor
  */
 protected function ensureCursor()
 {
     if ($this->cursor === null) {
         $convertedCommand = TypeConverter::fromLegacy($this->command);
         if (isset($convertedCommand->cursor)) {
             if ($convertedCommand->cursor === true || $convertedCommand->cursor === []) {
                 $convertedCommand->cursor = new \stdClass();
             }
         }
         $this->cursor = $this->db->command($convertedCommand, $this->getOptions());
     }
     return $this->cursor;
 }
All Usage Examples Of Alcaeus\MongoDbAdapter\TypeConverter::fromLegacy