@@ -575,7 +575,7 @@ PHP_METHOD(MongoDB, dropCollection)
575
575
}
576
576
/* }}} */
577
577
578
- void mongo_db_list_collections_command (zval * this_ptr , int include_system_collections , int full_collection_object , zval * return_value TSRMLS_DC )
578
+ void mongo_db_list_collections_command (zval * this_ptr , int include_system_collections , int return_type , zval * return_value TSRMLS_DC )
579
579
{
580
580
zval * z_cmd , * list , * * collections ;
581
581
mongo_db * db ;
@@ -634,11 +634,20 @@ void mongo_db_list_collections_command(zval *this_ptr, int include_system_collec
634
634
continue ;
635
635
}
636
636
637
- if (full_collection_object ) {
638
- c = php_mongo_db_selectcollection (this_ptr , Z_STRVAL_PP (collection_name ), Z_STRLEN_PP (collection_name ) TSRMLS_CC );
639
- add_next_index_zval (list , c );
640
- } else {
641
- add_next_index_string (list , Z_STRVAL_PP (collection_name ), 1 );
637
+ switch (return_type ) {
638
+ case MONGO_COLLECTION_RETURN_TYPE_NAME :
639
+ add_next_index_string (list , Z_STRVAL_PP (collection_name ), 1 );
640
+ break ;
641
+
642
+ case MONGO_COLLECTION_RETURN_TYPE_OBJECT :
643
+ c = php_mongo_db_selectcollection (this_ptr , Z_STRVAL_PP (collection_name ), Z_STRLEN_PP (collection_name ) TSRMLS_CC );
644
+ add_next_index_zval (list , c );
645
+ break ;
646
+
647
+ case MONGO_COLLECTION_RETURN_TYPE_INFO_ARRAY :
648
+ Z_ADDREF_P (* collection_doc );
649
+ add_assoc_zval (list , Z_STRVAL_PP (collection_name ), * collection_doc );
650
+ break ;
642
651
}
643
652
}
644
653
}
@@ -648,7 +657,7 @@ void mongo_db_list_collections_command(zval *this_ptr, int include_system_collec
648
657
RETURN_ZVAL (list , 0 , 1 );
649
658
}
650
659
651
- void mongo_db_list_collections_legacy (zval * this_ptr , int include_system_collections , int full_collection_object , zval * return_value TSRMLS_DC )
660
+ void mongo_db_list_collections_legacy (zval * this_ptr , int include_system_collections , int return_type , zval * return_value TSRMLS_DC )
652
661
{
653
662
zval * z_system_collection , * z_cursor , * list ;
654
663
mongo_cursor * cursor ;
@@ -728,13 +737,22 @@ void mongo_db_list_collections_legacy(zval *this_ptr, int include_system_collect
728
737
continue ;
729
738
}
730
739
731
- if (full_collection_object ) {
732
- c = php_mongo_db_selectcollection (this_ptr , name , strlen (name ) TSRMLS_CC );
733
- /* No need to test for c here, as this was already covered in
734
- * system_collection above */
735
- add_next_index_zval (list , c );
736
- } else {
737
- add_next_index_string (list , name , 1 );
740
+ switch (return_type ) {
741
+ case MONGO_COLLECTION_RETURN_TYPE_NAME :
742
+ add_next_index_string (list , name , 1 );
743
+ break ;
744
+
745
+ case MONGO_COLLECTION_RETURN_TYPE_OBJECT :
746
+ c = php_mongo_db_selectcollection (this_ptr , name , strlen (name ) TSRMLS_CC );
747
+ /* No need to test for c here, as this was already covered in
748
+ * system_collection above */
749
+ add_next_index_zval (list , c );
750
+ break ;
751
+
752
+ case MONGO_COLLECTION_RETURN_TYPE_INFO_ARRAY :
753
+ Z_ADDREF_P (cursor -> current );
754
+ add_assoc_zval (list , name , cursor -> current );
755
+ break ;
738
756
}
739
757
740
758
php_mongocursor_advance (cursor TSRMLS_CC );
@@ -746,7 +764,12 @@ void mongo_db_list_collections_legacy(zval *this_ptr, int include_system_collect
746
764
RETURN_ZVAL (list , 0 , 1 );
747
765
}
748
766
749
- static void php_mongo_enumerate_collections (INTERNAL_FUNCTION_PARAMETERS , int full_collection_object )
767
+ /* Return types:
768
+ * 0: Collection name
769
+ * 1: MongoCollection object
770
+ * 2: Array containing collection name and options
771
+ */
772
+ static void php_mongo_enumerate_collections (INTERNAL_FUNCTION_PARAMETERS , int return_type )
750
773
{
751
774
zend_bool include_system_collections = 0 ;
752
775
mongo_connection * connection ;
@@ -765,9 +788,9 @@ static void php_mongo_enumerate_collections(INTERNAL_FUNCTION_PARAMETERS, int fu
765
788
}
766
789
767
790
if (php_mongo_api_connection_min_server_version (connection , 2 , 7 , 5 )) {
768
- mongo_db_list_collections_command (getThis (), include_system_collections , full_collection_object , return_value TSRMLS_CC );
791
+ mongo_db_list_collections_command (getThis (), include_system_collections , return_type , return_value TSRMLS_CC );
769
792
} else {
770
- mongo_db_list_collections_legacy (getThis (), include_system_collections , full_collection_object , return_value TSRMLS_CC );
793
+ mongo_db_list_collections_legacy (getThis (), include_system_collections , return_type , return_value TSRMLS_CC );
771
794
}
772
795
}
773
796
@@ -776,6 +799,11 @@ PHP_METHOD(MongoDB, listCollections)
776
799
php_mongo_enumerate_collections (INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 );
777
800
}
778
801
802
+ PHP_METHOD (MongoDB , getCollectionInfo )
803
+ {
804
+ php_mongo_enumerate_collections (INTERNAL_FUNCTION_PARAM_PASSTHRU , 2 );
805
+ }
806
+
779
807
PHP_METHOD (MongoDB , getCollectionNames )
780
808
{
781
809
php_mongo_enumerate_collections (INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 );
@@ -1336,6 +1364,7 @@ static zend_function_entry MongoDB_methods[] = {
1336
1364
PHP_ME (MongoDB , dropCollection , arginfo_dropCollection , ZEND_ACC_PUBLIC )
1337
1365
PHP_ME (MongoDB , listCollections , arginfo_systemCollections , ZEND_ACC_PUBLIC )
1338
1366
PHP_ME (MongoDB , getCollectionNames , arginfo_systemCollections , ZEND_ACC_PUBLIC )
1367
+ PHP_ME (MongoDB , getCollectionInfo , arginfo_systemCollections , ZEND_ACC_PUBLIC )
1339
1368
PHP_ME (MongoDB , createDBRef , arginfo_createDBRef , ZEND_ACC_PUBLIC )
1340
1369
PHP_ME (MongoDB , getDBRef , arginfo_getDBRef , ZEND_ACC_PUBLIC )
1341
1370
PHP_ME (MongoDB , execute , arginfo_execute , ZEND_ACC_PUBLIC )
0 commit comments