Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

PHP-659: Add method prototypes for GridFS classes

  • Loading branch information...
commit cd439c3c96babd5eb50b99ec0d037f6f2ce05c75 1 parent ba485c8
Jeremy Mikola authored March 28, 2013 bjori committed March 28, 2013
45  gridfs/gridfs.c
@@ -71,6 +71,8 @@ typedef struct {
71 71
 static int setup_file_fields(zval *zfile, char *filename, int size TSRMLS_DC);
72 72
 static zval* insert_chunk(zval *chunks, zval *zid, int chunk_num, char *buf, int chunk_size, zval *options TSRMLS_DC);
73 73
 
  74
+/* {{{ proto MongoGridFS::__construct(MongoDB db [, string prefix = "fs.files" [, string chunks = "fs.chunks"]])
  75
+   Creates a new MongoGridFS object */
74 76
 PHP_METHOD(MongoGridFS, __construct)
75 77
 {
76 78
 	zval *zdb, *files = 0, *chunks = 0, *zchunks;
@@ -138,6 +140,7 @@ PHP_METHOD(MongoGridFS, __construct)
138 140
 	zval_ptr_dtor(&files);
139 141
 	zval_ptr_dtor(&chunks);
140 142
 }
  143
+/* }}} */
141 144
 
142 145
 void php_mongo_ensure_gridfs_index(zval *return_value, zval *this_ptr TSRMLS_DC)
143 146
 {
@@ -160,6 +163,8 @@ void php_mongo_ensure_gridfs_index(zval *return_value, zval *this_ptr TSRMLS_DC)
160 163
 	zval_ptr_dtor(&options);
161 164
 }
162 165
 
  166
+/* {{{ proto array MongoGridFS::drop()
  167
+   Drops the files and chunks collections */
163 168
 PHP_METHOD(MongoGridFS, drop)
164 169
 {
165 170
 	zval *temp;
@@ -171,7 +176,10 @@ PHP_METHOD(MongoGridFS, drop)
171 176
 
172 177
 	MONGO_METHOD(MongoCollection, drop, return_value, getThis());
173 178
 }
  179
+/* }}} */
174 180
 
  181
+/* {{{ proto MongoGridFSCursor MongoGridFS::find([array|object query = array() [, array fields = array()]])
  182
+   Queries for files */
175 183
 PHP_METHOD(MongoGridFS, find)
176 184
 {
177 185
 	zval temp;
@@ -208,7 +216,7 @@ PHP_METHOD(MongoGridFS, find)
208 216
 	zval_ptr_dtor(&zquery);
209 217
 	zval_ptr_dtor(&zfields);
210 218
 }
211  
-
  219
+/* }}} */
212 220
 
213 221
 static int get_chunk_size(zval *array TSRMLS_DC)
214 222
 {
@@ -392,13 +400,8 @@ static void cleanup_stale_chunks(INTERNAL_FUNCTION_PARAMETERS, zval *cleanup_ids
392 400
 	RETVAL_FALSE;
393 401
 }
394 402
 
395  
-/*
396  
- * Stores an array of bytes that may not have a filename, such as data from a
397  
- * socket or stream.
398  
- *
399  
- * Still somewhat limited atm, as the string has to fit in memory.  It would be
400  
- * better if it could take a fh or something.
401  
- */
  403
+/* {{{ proto mixed MongoGridFS::storeBytes(string bytes [, array|object metadata = array() [, array options = array()]])
  404
+   Stores a string of bytes in the database */
402 405
 PHP_METHOD(MongoGridFS, storeBytes)
403 406
 {
404 407
 	char *bytes = 0;
@@ -528,6 +531,7 @@ PHP_METHOD(MongoGridFS, storeBytes)
528 531
 	zval_ptr_dtor(&options);
529 532
 	zval_ptr_dtor(&cleanup_ids);
530 533
 }
  534
+/* }}} */
531 535
 
532 536
 /* add extra fields required for files:
533 537
  * - filename
@@ -620,6 +624,8 @@ static zval* insert_chunk(zval *chunks, zval *zid, int chunk_num, char *buf, int
620 624
 	return zretval;
621 625
 }
622 626
 
  627
+/* {{{ proto mixed MongoGridFS::storeFile(string|resource filename [, array metadata = array() [, array options = array()]])
  628
+   Stores a file in the database */
623 629
 PHP_METHOD(MongoGridFS, storeFile)
624 630
 {
625 631
 	zval *fh, *extra = 0, *options = 0;
@@ -850,7 +856,11 @@ PHP_METHOD(MongoGridFS, storeFile)
850 856
 
851 857
 	zval_ptr_dtor(&options);
852 858
 }
  859
+/* }}} */
853 860
 
  861
+/* {{{ proto MongoGridFSFile MongoGridFS::findOne([array|string query = array() [, array|object fields = array()]])
  862
+   Returns a single file matching the criteria. If $query is a string, it will
  863
+   be used to match documents by the filename field, which may not be unique. */
854 864
 PHP_METHOD(MongoGridFS, findOne)
855 865
 {
856 866
 	zval *zquery = 0, *zfields = 0, *file;
@@ -900,7 +910,11 @@ PHP_METHOD(MongoGridFS, findOne)
900 910
 	zval_ptr_dtor(&zquery);
901 911
 	zval_ptr_dtor(&zfields);
902 912
 }
  913
+/* }}} */
903 914
 
  915
+/* {{{ proto mixed MongoGridFS::remove([array|string criteria = array() [, array options = array()]])
  916
+   Removes files and corresponding chunks. If $query is a string, it will be
  917
+   used to match documents by the filename field, which may not be unique. */
904 918
 PHP_METHOD(MongoGridFS, remove)
905 919
 {
906 920
 	zval *criteria = 0, *options = 0, *zfields, *zcursor, *chunks, *next, temp;
@@ -996,7 +1010,11 @@ PHP_METHOD(MongoGridFS, remove)
996 1010
 	zval_ptr_dtor(&criteria);
997 1011
 	zval_ptr_dtor(&options);
998 1012
 }
  1013
+/* }}} */
999 1014
 
  1015
+/* {{{ proto mixed MongoGridFS::storeUpload(string name [, array|string metadata = array()])
  1016
+   Stores an uploaded file in the database. If $metadata is a string, it will be
  1017
+   used as the filename field for the stored file. */
1000 1018
 PHP_METHOD(MongoGridFS, storeUpload)
1001 1019
 {
1002 1020
 	zval *extra = 0, *h, **file, **temp, **name = 0, *extra_param = 0;
@@ -1085,10 +1103,14 @@ PHP_METHOD(MongoGridFS, storeUpload)
1085 1103
 		zend_throw_exception(mongo_ce_GridFSException, "tmp_name was not a string or an array", 13 TSRMLS_CC);
1086 1104
 	}
1087 1105
 }
  1106
+/* }}} */
1088 1107
 
1089 1108
 /*
1090 1109
  * New GridFS API
1091 1110
  */
  1111
+
  1112
+/* {{{ proto bool MongoGridFS::delete(mixed id)
  1113
+   Delete a file from the database */
1092 1114
 PHP_METHOD(MongoGridFS, delete)
1093 1115
 {
1094 1116
 	zval *id, *criteria;
@@ -1107,7 +1129,10 @@ PHP_METHOD(MongoGridFS, delete)
1107 1129
 
1108 1130
 	zval_ptr_dtor(&criteria);
1109 1131
 }
  1132
+/* }}} */
1110 1133
 
  1134
+/* {{{ proto MongoGridFSFile MongoGridFS::get(mixed id)
  1135
+   Retrieve a file from the database */
1111 1136
 PHP_METHOD(MongoGridFS, get)
1112 1137
 {
1113 1138
 	zval *id, *criteria;
@@ -1125,11 +1150,15 @@ PHP_METHOD(MongoGridFS, get)
1125 1150
 
1126 1151
 	zval_ptr_dtor(&criteria);
1127 1152
 }
  1153
+/* }}} */
1128 1154
 
  1155
+/* {{{ proto mixed MongoGridFS::put(string|resource filename [, array metadata = array() [, array options = array()]])
  1156
+   Stores a file in the database */
1129 1157
 PHP_METHOD(MongoGridFS, put)
1130 1158
 {
1131 1159
 	MONGO_METHOD_BASE(MongoGridFS, storeFile)(ZEND_NUM_ARGS(), return_value, NULL, getThis(), 0 TSRMLS_CC);
1132 1160
 }
  1161
+/* }}} */
1133 1162
 
1134 1163
 ZEND_BEGIN_ARG_INFO_EX(arginfo_find, 0, ZEND_RETURN_VALUE, 0)
1135 1164
 	ZEND_ARG_INFO(0, query)
9  gridfs/gridfs_cursor.c
@@ -29,6 +29,8 @@ extern zend_class_entry *mongo_ce_GridFSFile;
29 29
 
30 30
 zend_class_entry *mongo_ce_GridFSCursor = NULL;
31 31
 
  32
+/* {{{ proto MongoGridFSCursor::__construct(MongoGridFS gridfs, resource connection, string ns, array query, array fields)
  33
+   Creates a new MongoGridFSCursor object */
32 34
 PHP_METHOD(MongoGridFSCursor, __construct)
33 35
 {
34 36
 	zval temp;
@@ -44,13 +46,19 @@ PHP_METHOD(MongoGridFSCursor, __construct)
44 46
 
45 47
 	MONGO_METHOD4(MongoCursor, __construct, &temp, getThis(), connection, ns, query, fields);
46 48
 }
  49
+/* }}} */
47 50
 
  51
+/* {{{ proto MongoGridFSFile MongoGridFSCursor::getNext()
  52
+   Return the next file to which this cursor points, and advance the cursor */
48 53
 PHP_METHOD(MongoGridFSCursor, getNext)
49 54
 {
50 55
 	MONGO_METHOD(MongoCursor, next, return_value, getThis());
51 56
 	MONGO_METHOD(MongoGridFSCursor, current, return_value, getThis());
52 57
 }
  58
+/* }}} */
53 59
 
  60
+/* {{{ proto MongoGridFSFile MongoGridFSCursor::current()
  61
+   Returns the current file */
54 62
 PHP_METHOD(MongoGridFSCursor, current)
55 63
 {
56 64
 	zval temp;
@@ -73,6 +81,7 @@ PHP_METHOD(MongoGridFSCursor, current)
73 81
 	MONGO_METHOD3(MongoGridFSFile, __construct, &temp, return_value, gridfs, cursor->current, flags);
74 82
 	zval_ptr_dtor(&flags);
75 83
 }
  84
+/* }}} */
76 85
 
77 86
 static zend_function_entry MongoGridFSCursor_methods[] = {
78 87
 	PHP_ME(MongoGridFSCursor, __construct, NULL, ZEND_ACC_PUBLIC)
18  gridfs/gridfs_file.c
@@ -36,6 +36,8 @@ static int apply_to_cursor(zval *cursor, apply_copy_func_t apply_copy_func, void
36 36
 static int copy_bytes(void *to, char *from, int len);
37 37
 static int copy_file(void *to, char *from, int len);
38 38
 
  39
+/* {{{ proto MongoGridFSFile::__construct(MongoGridFS gridfs, array file)
  40
+   Creates a new MongoGridFSFile object */
39 41
 PHP_METHOD(MongoGridFSFile, __construct)
40 42
 {
41 43
 	zval *gridfs = 0, *file = 0;
@@ -52,7 +54,10 @@ PHP_METHOD(MongoGridFSFile, __construct)
52 54
 	zend_update_property(mongo_ce_GridFSFile, getThis(), "file", strlen("file"), file TSRMLS_CC);
53 55
 	zend_update_property_long(mongo_ce_GridFSFile, getThis(), "flags", strlen("flags"), flags TSRMLS_CC);
54 56
 }
  57
+/* }}} */
55 58
 
  59
+/* {{{ proto string MongoGridFSFile::getFilename()
  60
+   Returns this file's filename */
56 61
 PHP_METHOD(MongoGridFSFile, getFilename)
57 62
 {
58 63
 	zval *file = zend_read_property(mongo_ce_GridFSFile, getThis(), "file", strlen("file"), NOISY TSRMLS_CC);
@@ -62,7 +67,10 @@ PHP_METHOD(MongoGridFSFile, getFilename)
62 67
 	}
63 68
 	RETURN_NULL();
64 69
 }
  70
+/* }}} */
65 71
 
  72
+/* {{{ proto int MongoGridFSFile::getSize()
  73
+   Returns this file's size */
66 74
 PHP_METHOD(MongoGridFSFile, getSize)
67 75
 {
68 76
 	zval *file = zend_read_property(mongo_ce_GridFSFile, getThis(), "file", strlen("file"), NOISY TSRMLS_CC);
@@ -72,7 +80,10 @@ PHP_METHOD(MongoGridFSFile, getSize)
72 80
 	}
73 81
 	RETURN_NULL();
74 82
 }
  83
+/* }}} */
75 84
 
  85
+/* {{{ proto int MongoGridFSFile::write([string filename = null])
  86
+   Writes this file to the filesystem */
76 87
 PHP_METHOD(MongoGridFSFile, write)
77 88
 {
78 89
 	char *filename = 0;
@@ -163,7 +174,10 @@ PHP_METHOD(MongoGridFSFile, write)
163 174
 
164 175
 	RETURN_LONG(total);
165 176
 }
  177
+/* }}} */
166 178
 
  179
+/* {{{ proto stream MongoGridFSFile::getResource()
  180
+   Returns a resource that can be used to read the stored file */
167 181
 PHP_METHOD(MongoGridFSFile, getResource)
168 182
 {
169 183
 	php_stream * stream;
@@ -176,7 +190,10 @@ PHP_METHOD(MongoGridFSFile, getResource)
176 190
 
177 191
 	php_stream_to_zval(stream, return_value);
178 192
 }
  193
+/* }}} */
179 194
 
  195
+/* {{{ proto string MongoGridFSFile::getBytes()
  196
+   Returns this file's contents as a string of bytes */
180 197
 PHP_METHOD(MongoGridFSFile, getBytes)
181 198
 {
182 199
 	zval *file, *gridfs, *chunks, *query, *cursor, *sort, *temp;
@@ -265,6 +282,7 @@ PHP_METHOD(MongoGridFSFile, getBytes)
265 282
 
266 283
 	RETURN_STRINGL(str_ptr, len, 0);
267 284
 }
  285
+/* }}} */
268 286
 
269 287
 static int copy_bytes(void *to, char *from, int len)
270 288
 {

0 notes on commit cd439c3

Please sign in to comment.
Something went wrong with that request. Please try again.