Skip to content

Commit cd2660b

Browse files
committed
PHPC-233: Mark the ctor as private for internally created value objects
1 parent 569c01e commit cd2660b

File tree

7 files changed

+11
-72
lines changed

7 files changed

+11
-72
lines changed

php_phongo_classes.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,10 @@ extern PHONGO_API zend_class_entry *php_phongo_regex_ce;
218218
extern PHONGO_API zend_class_entry *php_phongo_timestamp_ce;
219219
extern PHONGO_API zend_class_entry *php_phongo_utcdatetime_ce;
220220

221-
/* Shared accross all MongoDB\Driver objects to disable unserialize() */
221+
/* Shared across all MongoDB\Driver objects to disable unserialize() */
222222
PHP_METHOD(Manager, __wakeUp);
223+
/* Shared across all final MongoDB\Driver value objects, only possible to construct them internally */
224+
PHP_METHOD(Server, __construct);
223225

224226
PHP_MINIT_FUNCTION(Command);
225227
PHP_MINIT_FUNCTION(Cursor);

src/MongoDB/Cursor.c

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,6 @@ PHONGO_API zend_class_entry *php_phongo_cursor_ce;
4848

4949
zend_object_handlers php_phongo_handler_cursor;
5050

51-
/* {{{ proto MongoDB\Driver\Cursor Cursor::__construct(MongoDB\Driver\Server $server, array|object $responseDocument)
52-
Constructs a new Cursor */
53-
PHP_METHOD(Cursor, __construct)
54-
{
55-
php_phongo_cursor_t *intern;
56-
zend_error_handling error_handling;
57-
zval *server;
58-
zval *responseDocument;
59-
(void)return_value; (void)return_value_ptr; (void)return_value_used;
60-
61-
62-
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
63-
intern = (php_phongo_cursor_t *)zend_object_store_get_object(getThis() TSRMLS_CC);
64-
65-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OA", &server, php_phongo_server_ce, &responseDocument) == FAILURE) {
66-
zend_restore_error_handling(&error_handling TSRMLS_CC);
67-
return;
68-
}
69-
zend_restore_error_handling(&error_handling TSRMLS_CC);
70-
71-
}
72-
/* }}} */
73-
7451
/* {{{ proto void Cursor::setTypeMap(array $typemap)
7552
Sets a type map to use for BSON unserialization */
7653
PHP_METHOD(Cursor, setTypeMap)
@@ -186,11 +163,6 @@ PHP_METHOD(Cursor, isDead)
186163

187164
/* {{{ MongoDB\Driver\Cursor */
188165

189-
ZEND_BEGIN_ARG_INFO_EX(ai_Cursor___construct, 0, 0, 2)
190-
ZEND_ARG_OBJ_INFO(0, server, MongoDB\\Driver\\Server, 0)
191-
ZEND_ARG_INFO(0, responseDocument)
192-
ZEND_END_ARG_INFO();
193-
194166
ZEND_BEGIN_ARG_INFO_EX(ai_Cursor_setTypeMap, 0, 0, 1)
195167
ZEND_ARG_ARRAY_INFO(0, typemap, 0)
196168
ZEND_END_ARG_INFO();
@@ -209,7 +181,7 @@ ZEND_END_ARG_INFO();
209181

210182

211183
static zend_function_entry php_phongo_cursor_me[] = {
212-
PHP_ME(Cursor, __construct, ai_Cursor___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
184+
PHP_ME(Server, __construct, NULL, ZEND_ACC_FINAL|ZEND_ACC_PRIVATE)
213185
PHP_ME(Cursor, setTypeMap, ai_Cursor_setTypeMap, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
214186
PHP_ME(Cursor, toArray, ai_Cursor_toArray, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
215187
PHP_ME(Cursor, getId, ai_Cursor_getId, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)

src/MongoDB/CursorId.c

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,6 @@ PHONGO_API zend_class_entry *php_phongo_cursorid_ce;
4646

4747
zend_object_handlers php_phongo_handler_cursorid;
4848

49-
/* {{{ proto MongoDB\Driver\CursorId CursorId::__construct(string $id)
50-
Construct a new CursorId */
51-
PHP_METHOD(CursorId, __construct)
52-
{
53-
php_phongo_cursorid_t *intern;
54-
zend_error_handling error_handling;
55-
char *id;
56-
int id_len;
57-
(void)return_value; (void)return_value_ptr; (void)return_value_used;
58-
59-
60-
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
61-
intern = (php_phongo_cursorid_t *)zend_object_store_get_object(getThis() TSRMLS_CC);
62-
63-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &id, &id_len) == FAILURE) {
64-
zend_restore_error_handling(&error_handling TSRMLS_CC);
65-
return;
66-
}
67-
zend_restore_error_handling(&error_handling TSRMLS_CC);
68-
}
69-
/* }}} */
7049
/* {{{ proto string CursorId::__toString()
7150
Returns the string representation of the CursorId */
7251
PHP_METHOD(CursorId, __toString)
@@ -86,24 +65,14 @@ PHP_METHOD(CursorId, __toString)
8665
}
8766
/* }}} */
8867

89-
/**
90-
* Value object for the 64-bit cursor identifier.
91-
*
92-
* This is useful for compatibility with 32-bit platforms, and also allows
93-
* Cursor constructors to type-hint against a class.
94-
*/
9568
/* {{{ MongoDB\Driver\CursorId */
9669

97-
ZEND_BEGIN_ARG_INFO_EX(ai_CursorId___construct, 0, 0, 1)
98-
ZEND_ARG_INFO(0, id)
99-
ZEND_END_ARG_INFO();
100-
10170
ZEND_BEGIN_ARG_INFO_EX(ai_CursorId___toString, 0, 0, 0)
10271
ZEND_END_ARG_INFO();
10372

10473

10574
static zend_function_entry php_phongo_cursorid_me[] = {
106-
PHP_ME(CursorId, __construct, ai_CursorId___construct, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
75+
PHP_ME(Server, __construct, NULL, ZEND_ACC_FINAL|ZEND_ACC_PRIVATE)
10776
PHP_ME(CursorId, __toString, ai_CursorId___toString, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
10877
PHP_ME(Manager, __wakeUp, NULL, ZEND_ACC_PUBLIC)
10978
PHP_FE_END

src/MongoDB/Server.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ PHONGO_API zend_class_entry *php_phongo_server_ce;
4949
zend_object_handlers php_phongo_handler_server;
5050

5151

52-
/* {{{ proto MongoDB\Driver\Server Server::__construct(string $host, integer $port[, array $options = array()[, array $driverOptions = array()]])
53-
Constructs a new Server */
52+
/* {{{ proto MongoDB\Driver\Server Server::__construct()
53+
Throws exception -- can only be created internally */
5454
PHP_METHOD(Server, __construct)
5555
{
5656
(void)return_value; (void)return_value_used; (void)return_value_ptr; (void)ZEND_NUM_ARGS(); (void)getThis();
@@ -383,13 +383,6 @@ PHP_METHOD(Server, isPassive)
383383

384384
/* {{{ MongoDB\Driver\Server */
385385

386-
ZEND_BEGIN_ARG_INFO_EX(ai_Server___construct, 0, 0, 2)
387-
ZEND_ARG_INFO(0, host)
388-
ZEND_ARG_INFO(0, port)
389-
ZEND_ARG_ARRAY_INFO(0, options, 0)
390-
ZEND_ARG_ARRAY_INFO(0, driverOptions, 0)
391-
ZEND_END_ARG_INFO();
392-
393386
ZEND_BEGIN_ARG_INFO_EX(ai_Server_executeCommand, 0, 0, 2)
394387
ZEND_ARG_INFO(0, db)
395388
ZEND_ARG_OBJ_INFO(0, command, MongoDB\\Driver\\Command, 0)
@@ -440,7 +433,7 @@ ZEND_END_ARG_INFO();
440433

441434

442435
static zend_function_entry php_phongo_server_me[] = {
443-
PHP_ME(Server, __construct, ai_Server___construct, ZEND_ACC_FINAL|ZEND_ACC_PRIVATE)
436+
PHP_ME(Server, __construct, NULL, ZEND_ACC_FINAL|ZEND_ACC_PRIVATE)
444437
PHP_ME(Server, executeCommand, ai_Server_executeCommand, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
445438
PHP_ME(Server, executeQuery, ai_Server_executeQuery, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
446439
PHP_ME(Server, executeBulkWrite, ai_Server_executeBulkWrite, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)

src/MongoDB/WriteConcernError.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ ZEND_END_ARG_INFO();
115115

116116

117117
static zend_function_entry php_phongo_writeconcernerror_me[] = {
118+
PHP_ME(Server, __construct, NULL, ZEND_ACC_FINAL|ZEND_ACC_PRIVATE)
118119
PHP_ME(WriteConcernError, getCode, ai_WriteConcernError_getCode, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
119120
PHP_ME(WriteConcernError, getInfo, ai_WriteConcernError_getInfo, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
120121
PHP_ME(WriteConcernError, getMessage, ai_WriteConcernError_getMessage, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)

src/MongoDB/WriteError.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ ZEND_END_ARG_INFO();
136136

137137

138138
static zend_function_entry php_phongo_writeerror_me[] = {
139+
PHP_ME(Server, __construct, NULL, ZEND_ACC_FINAL|ZEND_ACC_PRIVATE)
139140
PHP_ME(WriteError, getCode, ai_WriteError_getCode, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
140141
PHP_ME(WriteError, getIndex, ai_WriteError_getIndex, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
141142
PHP_ME(WriteError, getMessage, ai_WriteError_getMessage, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)

src/MongoDB/WriteResult.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ ZEND_END_ARG_INFO();
368368

369369

370370
static zend_function_entry php_phongo_writeresult_me[] = {
371+
PHP_ME(Server, __construct, NULL, ZEND_ACC_FINAL|ZEND_ACC_PRIVATE)
371372
PHP_ME(WriteResult, getInsertedCount, ai_WriteResult_getInsertedCount, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
372373
PHP_ME(WriteResult, getMatchedCount, ai_WriteResult_getMatchedCount, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
373374
PHP_ME(WriteResult, getModifiedCount, ai_WriteResult_getModifiedCount, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)

0 commit comments

Comments
 (0)