-
Notifications
You must be signed in to change notification settings - Fork 208
PHPC-1893: Implement TopologyOpeningEvent class #1250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* Copyright 2021-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <php.h> | ||
#include <Zend/zend_interfaces.h> | ||
|
||
#ifdef HAVE_CONFIG_H | ||
#include "config.h" | ||
#endif | ||
|
||
#include "phongo_compat.h" | ||
#include "php_phongo.h" | ||
|
||
zend_class_entry* php_phongo_topologyopeningevent_ce; | ||
|
||
/* {{{ proto MongoDB\BSON\ObjectId TopologyOpeningEvent::getTopologyId() | ||
Returns this event's topology id */ | ||
static PHP_METHOD(TopologyOpeningEvent, getTopologyId) | ||
{ | ||
php_phongo_objectid_t* topology_id; | ||
php_phongo_topologyopeningevent_t* intern = Z_TOPOLOGYOPENINGEVENT_OBJ_P(getThis()); | ||
|
||
PHONGO_PARSE_PARAMETERS_NONE(); | ||
|
||
object_init_ex(return_value, php_phongo_objectid_ce); | ||
|
||
topology_id = Z_OBJECTID_OBJ_P(return_value); | ||
bson_oid_to_string(&intern->topology_id, topology_id->oid); | ||
topology_id->initialized = true; | ||
} /* }}} */ | ||
|
||
/* {{{ MongoDB\Driver\Monitoring\TopologyOpeningEvent function entries */ | ||
ZEND_BEGIN_ARG_INFO_EX(ai_TopologyOpeningEvent_void, 0, 0, 0) | ||
ZEND_END_ARG_INFO() | ||
|
||
static zend_function_entry php_phongo_topologyopeningevent_me[] = { | ||
/* clang-format off */ | ||
ZEND_NAMED_ME(__construct, PHP_FN(MongoDB_disabled___construct), ai_TopologyOpeningEvent_void, ZEND_ACC_PRIVATE | ZEND_ACC_FINAL) | ||
PHP_ME(TopologyOpeningEvent, getTopologyId, ai_TopologyOpeningEvent_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL) | ||
ZEND_NAMED_ME(__wakeup, PHP_FN(MongoDB_disabled___wakeup), ai_TopologyOpeningEvent_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL) | ||
PHP_FE_END | ||
/* clang-format on */ | ||
}; | ||
/* }}} */ | ||
|
||
/* {{{ MongoDB\Driver\Monitoring\TopologyOpeningEvent object handlers */ | ||
static zend_object_handlers php_phongo_handler_topologyopeningevent; | ||
|
||
static void php_phongo_topologyopeningevent_free_object(zend_object* object) /* {{{ */ | ||
{ | ||
php_phongo_topologyopeningevent_t* intern = Z_OBJ_TOPOLOGYOPENINGEVENT(object); | ||
|
||
zend_object_std_dtor(&intern->std); | ||
} /* }}} */ | ||
|
||
static zend_object* php_phongo_topologyopeningevent_create_object(zend_class_entry* class_type) /* {{{ */ | ||
{ | ||
php_phongo_topologyopeningevent_t* intern = NULL; | ||
|
||
intern = PHONGO_ALLOC_OBJECT_T(php_phongo_topologyopeningevent_t, class_type); | ||
|
||
zend_object_std_init(&intern->std, class_type); | ||
object_properties_init(&intern->std, class_type); | ||
|
||
intern->std.handlers = &php_phongo_handler_topologyopeningevent; | ||
|
||
return &intern->std; | ||
} /* }}} */ | ||
|
||
static HashTable* php_phongo_topologyopeningevent_get_debug_info(phongo_compat_object_handler_type* object, int* is_temp) /* {{{ */ | ||
{ | ||
php_phongo_topologyopeningevent_t* intern; | ||
zval retval = ZVAL_STATIC_INIT; | ||
char topology_id[25]; | ||
|
||
intern = Z_OBJ_TOPOLOGYOPENINGEVENT(PHONGO_COMPAT_GET_OBJ(object)); | ||
*is_temp = 1; | ||
array_init_size(&retval, 1); | ||
|
||
bson_oid_to_string(&intern->topology_id, topology_id); | ||
ADD_ASSOC_STRING(&retval, "topologyId", topology_id); | ||
|
||
return Z_ARRVAL(retval); | ||
} /* }}} */ | ||
/* }}} */ | ||
|
||
void php_phongo_topologyopeningevent_init_ce(INIT_FUNC_ARGS) /* {{{ */ | ||
{ | ||
zend_class_entry ce; | ||
(void) type; | ||
(void) module_number; | ||
|
||
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver\\Monitoring", "TopologyOpeningEvent", php_phongo_topologyopeningevent_me); | ||
php_phongo_topologyopeningevent_ce = zend_register_internal_class(&ce); | ||
php_phongo_topologyopeningevent_ce->create_object = php_phongo_topologyopeningevent_create_object; | ||
PHONGO_CE_FINAL(php_phongo_topologyopeningevent_ce); | ||
PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_topologyopeningevent_ce); | ||
|
||
memcpy(&php_phongo_handler_topologyopeningevent, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); | ||
php_phongo_handler_topologyopeningevent.get_debug_info = php_phongo_topologyopeningevent_get_debug_info; | ||
php_phongo_handler_topologyopeningevent.free_obj = php_phongo_topologyopeningevent_free_object; | ||
php_phongo_handler_topologyopeningevent.offset = XtOffsetOf(php_phongo_topologyopeningevent_t, std); | ||
|
||
return; | ||
} /* }}} */ | ||
|
||
/* | ||
* Local variables: | ||
* tab-width: 4 | ||
* c-basic-offset: 4 | ||
* End: | ||
* vim600: noet sw=4 ts=4 fdm=marker | ||
* vim<600: noet sw=4 ts=4 | ||
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--TEST-- | ||
MongoDB\Driver\Monitoring\TopologyOpeningEvent | ||
--SKIPIF-- | ||
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> | ||
<?php skip_if_not_live(); ?> | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . "/../utils/basic.inc"; | ||
|
||
$m = create_test_manager(); | ||
|
||
class MySubscriber implements MongoDB\Driver\Monitoring\SDAMSubscriber | ||
{ | ||
public function topologyChanged(MongoDB\Driver\Monitoring\TopologyChangedEvent $event) {} | ||
|
||
public function topologyOpening(MongoDB\Driver\Monitoring\TopologyOpeningEvent $event) | ||
{ | ||
echo "- getTopologyId() returns an ObjectId: ", ($event->getTopologyId() instanceof MongoDB\BSON\ObjectId) ? 'yes' : 'no', "\n"; | ||
} | ||
} | ||
|
||
$subscriber = new MySubscriber; | ||
MongoDB\Driver\Monitoring\addSubscriber($subscriber); | ||
|
||
$command = new MongoDB\Driver\Command(['ping' => 1]); | ||
$m->executeCommand(DATABASE_NAME, $command); | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECT-- | ||
- getTopologyId() returns an ObjectId: yes | ||
===DONE=== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize this wasn't done in the previous PR for TopologyChangedEvent, but it occurred to me that we have no tests (and therefore no code coverage) for the event object's debug handler. Would you mind making a ticket within the epic so we don't forget to add those? Something like "Create tests for event object debug handlers" should suffice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://jira.mongodb.org/browse/PHPC-1953