Skip to content

Commit cc317b3

Browse files
committed
Merged pull request #932
2 parents 605469f + 87096da commit cc317b3

11 files changed

+130
-7
lines changed

config.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ if test "$PHP_MONGODB" != "no"; then
136136
src/MongoDB/Command.c \
137137
src/MongoDB/Cursor.c \
138138
src/MongoDB/CursorId.c \
139+
src/MongoDB/CursorInterface.c \
139140
src/MongoDB/Manager.c \
140141
src/MongoDB/Query.c \
141142
src/MongoDB/ReadConcern.c \

config.w32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ if (PHP_MONGODB != "no") {
8888
EXTENSION("mongodb", "php_phongo.c phongo_compat.c", null, PHP_MONGODB_CFLAGS);
8989
ADD_SOURCES(configure_module_dirname + "/src", "bson.c bson-encode.c", "mongodb");
9090
ADD_SOURCES(configure_module_dirname + "/src/BSON", "Binary.c BinaryInterface.c DBPointer.c Decimal128.c Decimal128Interface.c Int64.c Javascript.c JavascriptInterface.c MaxKey.c MaxKeyInterface.c MinKey.c MinKeyInterface.c ObjectId.c ObjectIdInterface.c Persistable.c Regex.c RegexInterface.c Serializable.c Symbol.c Timestamp.c TimestampInterface.c Type.c Undefined.c Unserializable.c UTCDateTime.c UTCDateTimeInterface.c functions.c", "mongodb");
91-
ADD_SOURCES(configure_module_dirname + "/src/MongoDB", "BulkWrite.c Command.c Cursor.c CursorId.c Manager.c Query.c ReadConcern.c ReadPreference.c Server.c Session.c WriteConcern.c WriteConcernError.c WriteError.c WriteResult.c", "mongodb");
91+
ADD_SOURCES(configure_module_dirname + "/src/MongoDB", "BulkWrite.c Command.c Cursor.c CursorId.c CursorInterface.c Manager.c Query.c ReadConcern.c ReadPreference.c Server.c Session.c WriteConcern.c WriteConcernError.c WriteError.c WriteResult.c", "mongodb");
9292
ADD_SOURCES(configure_module_dirname + "/src/MongoDB/Exception", "AuthenticationException.c BulkWriteException.c CommandException.c ConnectionException.c ConnectionTimeoutException.c Exception.c ExecutionTimeoutException.c InvalidArgumentException.c LogicException.c RuntimeException.c ServerException.c SSLConnectionException.c UnexpectedValueException.c WriteException.c", "mongodb");
9393
ADD_SOURCES(configure_module_dirname + "/src/MongoDB/Monitoring", "CommandFailedEvent.c CommandStartedEvent.c CommandSubscriber.c CommandSucceededEvent.c Subscriber.c functions.c", "mongodb");
9494
ADD_SOURCES(configure_module_dirname + "/src/libmongoc/src/common", PHP_MONGODB_COMMON_SOURCES, "mongodb");

php_phongo.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2971,6 +2971,8 @@ PHP_MINIT_FUNCTION(mongodb)
29712971
php_phongo_timestamp_init_ce(INIT_FUNC_ARGS_PASSTHRU);
29722972
php_phongo_undefined_init_ce(INIT_FUNC_ARGS_PASSTHRU);
29732973
php_phongo_utcdatetime_init_ce(INIT_FUNC_ARGS_PASSTHRU);
2974+
2975+
php_phongo_cursor_interface_init_ce(INIT_FUNC_ARGS_PASSTHRU);
29742976

29752977
php_phongo_bulkwrite_init_ce(INIT_FUNC_ARGS_PASSTHRU);
29762978
php_phongo_command_init_ce(INIT_FUNC_ARGS_PASSTHRU);

php_phongo_classes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ extern zend_class_entry* php_phongo_writeconcernerror_ce;
294294
extern zend_class_entry* php_phongo_writeerror_ce;
295295
extern zend_class_entry* php_phongo_writeresult_ce;
296296

297+
extern zend_class_entry* php_phongo_cursor_interface_ce;
298+
297299
extern zend_class_entry* php_phongo_exception_ce;
298300
extern zend_class_entry* php_phongo_logicexception_ce;
299301
extern zend_class_entry* php_phongo_runtimeexception_ce;
@@ -386,6 +388,8 @@ extern void php_phongo_writeconcernerror_init_ce(INIT_FUNC_ARGS);
386388
extern void php_phongo_writeerror_init_ce(INIT_FUNC_ARGS);
387389
extern void php_phongo_writeresult_init_ce(INIT_FUNC_ARGS);
388390

391+
extern void php_phongo_cursor_interface_init_ce(INIT_FUNC_ARGS);
392+
389393
extern void php_phongo_authenticationexception_init_ce(INIT_FUNC_ARGS);
390394
extern void php_phongo_bulkwriteexception_init_ce(INIT_FUNC_ARGS);
391395
extern void php_phongo_commandexception_init_ce(INIT_FUNC_ARGS);

src/MongoDB/Cursor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,14 +560,14 @@ void php_phongo_cursor_init_ce(INIT_FUNC_ARGS) /* {{{ */
560560
PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_cursor_ce);
561561
php_phongo_cursor_ce->get_iterator = php_phongo_cursor_get_iterator;
562562

563+
zend_class_implements(php_phongo_cursor_ce TSRMLS_CC, 1, php_phongo_cursor_interface_ce);
564+
563565
memcpy(&php_phongo_handler_cursor, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
564566
php_phongo_handler_cursor.get_debug_info = php_phongo_cursor_get_debug_info;
565567
#if PHP_VERSION_ID >= 70000
566568
php_phongo_handler_cursor.free_obj = php_phongo_cursor_free_object;
567569
php_phongo_handler_cursor.offset = XtOffsetOf(php_phongo_cursor_t, std);
568570
#endif
569-
570-
zend_class_implements(php_phongo_cursor_ce TSRMLS_CC, 1, zend_ce_traversable);
571571
} /* }}} */
572572

573573
/*

src/MongoDB/CursorInterface.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2018 MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifdef HAVE_CONFIG_H
18+
#include "config.h"
19+
#endif
20+
21+
#include <php.h>
22+
#include <Zend/zend_interfaces.h>
23+
24+
#include "phongo_compat.h"
25+
#include "php_phongo.h"
26+
27+
zend_class_entry* php_phongo_cursor_interface_ce;
28+
29+
/* {{{ MongoDB\BSON\CursorInterface function entries */
30+
ZEND_BEGIN_ARG_INFO_EX(ai_CursorInterface_setTypeMap, 0, 0, 1)
31+
ZEND_ARG_ARRAY_INFO(0, typemap, 0)
32+
ZEND_END_ARG_INFO()
33+
34+
ZEND_BEGIN_ARG_INFO_EX(ai_CursorInterface_void, 0, 0, 0)
35+
ZEND_END_ARG_INFO()
36+
37+
static zend_function_entry php_phongo_cursor_interface_me[] = {
38+
/* clang-format off */
39+
ZEND_ABSTRACT_ME(CursorInterface, getId, ai_CursorInterface_void)
40+
ZEND_ABSTRACT_ME(CursorInterface, getServer, ai_CursorInterface_void)
41+
ZEND_ABSTRACT_ME(CursorInterface, isDead, ai_CursorInterface_void)
42+
ZEND_ABSTRACT_ME(CursorInterface, setTypeMap, ai_CursorInterface_setTypeMap)
43+
ZEND_ABSTRACT_ME(CursorInterface, toArray, ai_CursorInterface_void)
44+
PHP_FE_END
45+
/* clang-format on */
46+
};
47+
/* }}} */
48+
49+
void php_phongo_cursor_interface_init_ce(INIT_FUNC_ARGS) /* {{{ */
50+
{
51+
zend_class_entry ce;
52+
53+
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "CursorInterface", php_phongo_cursor_interface_me);
54+
php_phongo_cursor_interface_ce = zend_register_internal_interface(&ce TSRMLS_CC);
55+
56+
zend_class_implements(php_phongo_cursor_interface_ce TSRMLS_CC, 1, zend_ce_traversable);
57+
} /* }}} */
58+
59+
/*
60+
* Local variables:
61+
* tab-width: 4
62+
* c-basic-offset: 4
63+
* End:
64+
* vim600: noet sw=4 ts=4 fdm=marker
65+
* vim<600: noet sw=4 ts=4
66+
*/

tests/cursor/cursor-001.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
MongoDB\Driver\Cursor implements MongoDB\Driver\CursorInterface and Traversable
3+
--FILE--
4+
<?php
5+
var_dump(in_array('Traversable', class_implements('MongoDB\Driver\Cursor')));
6+
var_dump(in_array('MongoDB\Driver\CursorInterface', class_implements('MongoDB\Driver\Cursor')));
7+
?>
8+
===DONE===
9+
<?php exit(0); ?>
10+
--EXPECT--
11+
bool(true)
12+
bool(true)
13+
===DONE===

tests/cursor/cursorinterface-001.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
MongoDB\Driver\CursorInterface is implemented by MongoDB\Driver\Cursor
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_live(); ?>
6+
<?php skip_if_not_clean(); ?>
7+
--FILE--
8+
<?php
9+
require_once __DIR__ . "/../utils/basic.inc";
10+
11+
$manager = new MongoDB\Driver\Manager(URI);
12+
13+
$bulk = new MongoDB\Driver\BulkWrite();
14+
$bulk->insert(array('_id' => 1, 'x' => 1));
15+
$bulk->insert(array('_id' => 2, 'x' => 1));
16+
$manager->executeBulkWrite(NS, $bulk);
17+
18+
$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query(array("x" => 1)));
19+
var_dump($cursor instanceof MongoDB\Driver\CursorInterface);
20+
21+
?>
22+
===DONE===
23+
<?php exit(0); ?>
24+
--EXPECT--
25+
bool(true)
26+
===DONE===

tests/cursor/cursorinterface-002.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
MongoDB\Driver\CursorInterface is extending Traversable
3+
--FILE--
4+
<?php
5+
var_dump(in_array('Traversable', class_implements('MongoDB\Driver\CursorInterface')));
6+
?>
7+
===DONE===
8+
<?php exit(0); ?>
9+
--EXPECT--
10+
bool(true)
11+
===DONE===

tests/session/session-startTransaction_error-002.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ foreach ($options as $txnOptions) {
4848
<?php exit(0); ?>
4949
--EXPECTF--
5050
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
51-
Expected "readConcern" option to be MongoDB\Driver\ReadConcern, integer given
51+
Expected "readConcern" option to be MongoDB\Driver\ReadConcern, int%S given
5252
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
5353
Expected "readConcern" option to be MongoDB\Driver\ReadConcern, stdClass given
5454
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
5555
Expected "readConcern" option to be MongoDB\Driver\ReadConcern, MongoDB\Driver\WriteConcern given
5656
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
57-
Expected "readPreference" option to be MongoDB\Driver\ReadPreference, integer given
57+
Expected "readPreference" option to be MongoDB\Driver\ReadPreference, int%S given
5858
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
5959
Expected "readPreference" option to be MongoDB\Driver\ReadPreference, stdClass given
6060
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
6161
Expected "readPreference" option to be MongoDB\Driver\ReadPreference, MongoDB\Driver\ReadConcern given
6262
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
63-
Expected "writeConcern" option to be MongoDB\Driver\WriteConcern, integer given
63+
Expected "writeConcern" option to be MongoDB\Driver\WriteConcern, int%S given
6464
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
6565
Expected "writeConcern" option to be MongoDB\Driver\WriteConcern, stdClass given
6666
OK: Got MongoDB\Driver\Exception\InvalidArgumentException

tests/session/session-startTransaction_error-003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ foreach ($options as $txnOptions) {
2525
===DONE===
2626
<?php exit(0); ?>
2727
--EXPECTF--
28-
Warning: MongoDB\Driver\Session::startTransaction() expects parameter 1 to be array, integer given in %s on line %d
28+
Warning: MongoDB\Driver\Session::startTransaction() expects parameter 1 to be array, int%S given in %s on line %d
2929

3030
Warning: MongoDB\Driver\Session::startTransaction() expects parameter 1 to be array, object given in %s on line %d
3131
===DONE===

0 commit comments

Comments
 (0)