public static function convertProjection($fields)
    {
        if (! is_array($fields) || $fields === []) {
            return null;
        }

        if (! TypeConverter::isNumericArray($fields)) {
            $projection = TypeConverter::fromLegacy($fields);
        } else {
            $projection = array_fill_keys(
                array_map(function ($field) {
                    if (!is_string($field)) {
                        throw new \MongoException('field names must be strings', 8);
                    }

                    return $field;
                }, $fields),
                true
            );
        }

        return TypeConverter::fromLegacy($projection);
    }
public static function convertProjection($fields)
    {
        if (! is_array($fields) || $fields === []) {
            return null;
        }

        if (! TypeConverter::isNumericArray($fields)) {
            $projection = TypeConverter::fromLegacy($fields);
        } else {
            $projection = array_fill_keys(
                array_map(function ($field) {
                    if (!is_string($field)) {
                        throw new \MongoException('field names must be strings', 8);
                    }

                    return $field;
                }, $fields),
                true
            );
        }

        return TypeConverter::fromLegacy($projection);
    }
public static function convertProjection ( $ fields ) { if ( ! is_array ( $ fields ) || $ fields === [ ] ) { return null ; } if ( ! TypeConverter :: isNumericArray ( $ fields ) ) { $ projection = TypeConverter :: fromLegacy ( $ fields ) ; } else { $ projection = array_fill_keys ( array_map ( function ( $ field ) { if ( ! is_string ( $ field ) ) { throw new \ MongoException ( 'field names must be strings' , 8 ) ; } return $ field ; } , $ fields ) , true ) ; } return TypeConverter :: fromLegacy ( $ projection ) ; }
Converts a projection used in find queries.

This method handles conversion from the legacy syntax (e.g. ['x', 'y', 'z'])
to the new syntax (e.g. ['x' => true, 'y' => true, 'z' => true]). While
this was never documented, the legacy driver applied the same conversion.

@param array $fields
@return array|null

@throws \MongoException
Converts a projection used in find queries .