From 88897fbfbd0337370ec31860088863b78a2c46b8 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Tue, 23 Aug 2022 13:03:24 +0200 Subject: [PATCH 1/2] PHPC-2128: Create stub file for functions --- php_phongo.c | 42 +------------- src/BSON/functions.c | 12 ++-- src/BSON/functions.h | 30 ---------- src/MongoDB/Monitoring/functions.c | 4 +- src/MongoDB/Monitoring/functions.h | 25 --------- src/functions.stub.php | 33 +++++++++++ src/functions_arginfo.h | 89 ++++++++++++++++++++++++++++++ 7 files changed, 133 insertions(+), 102 deletions(-) delete mode 100644 src/BSON/functions.h delete mode 100644 src/MongoDB/Monitoring/functions.h create mode 100644 src/functions.stub.php create mode 100644 src/functions_arginfo.h diff --git a/php_phongo.c b/php_phongo.c index e93f54c20..0c7fbc02f 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -28,8 +28,7 @@ #include "src/phongo_client.h" #include "src/phongo_error.h" #include "src/phongo_ini.h" -#include "src/BSON/functions.h" -#include "src/MongoDB/Monitoring/functions.h" +#include "src/functions_arginfo.h" ZEND_DECLARE_MODULE_GLOBALS(mongodb) #if defined(ZTS) && defined(COMPILE_DL_MONGODB) @@ -482,42 +481,7 @@ PHP_FUNCTION(MongoDB_disabled___wakeup) /* {{{ */ } /* }}} */ /* }}} */ -/* {{{ Extension functions, module dependencies, and module entry */ -ZEND_BEGIN_ARG_INFO_EX(ai_bson_fromPHP, 0, 0, 1) - ZEND_ARG_INFO(0, value) -ZEND_END_ARG_INFO(); - -ZEND_BEGIN_ARG_INFO_EX(ai_bson_toPHP, 0, 0, 1) - ZEND_ARG_INFO(0, bson) - ZEND_ARG_ARRAY_INFO(0, typemap, 0) -ZEND_END_ARG_INFO(); - -ZEND_BEGIN_ARG_INFO_EX(ai_bson_toJSON, 0, 0, 1) - ZEND_ARG_INFO(0, bson) -ZEND_END_ARG_INFO(); - -ZEND_BEGIN_ARG_INFO_EX(ai_bson_fromJSON, 0, 0, 1) - ZEND_ARG_INFO(0, json) -ZEND_END_ARG_INFO(); - -ZEND_BEGIN_ARG_INFO_EX(ai_mongodb_driver_monitoring_subscriber, 0, 0, 1) - ZEND_ARG_OBJ_INFO(0, subscriber, MongoDB\\Driver\\Monitoring\\Subscriber, 0) -ZEND_END_ARG_INFO(); - -static const zend_function_entry mongodb_functions[] = { - /* clang-format off */ - ZEND_NS_NAMED_FE("MongoDB\\BSON", fromPHP, PHP_FN(MongoDB_BSON_fromPHP), ai_bson_fromPHP) - ZEND_NS_NAMED_FE("MongoDB\\BSON", toPHP, PHP_FN(MongoDB_BSON_toPHP), ai_bson_toPHP) - ZEND_NS_NAMED_FE("MongoDB\\BSON", toJSON, PHP_FN(MongoDB_BSON_toJSON), ai_bson_toJSON) - ZEND_NS_NAMED_FE("MongoDB\\BSON", toCanonicalExtendedJSON, PHP_FN(MongoDB_BSON_toCanonicalExtendedJSON), ai_bson_toJSON) - ZEND_NS_NAMED_FE("MongoDB\\BSON", toRelaxedExtendedJSON, PHP_FN(MongoDB_BSON_toRelaxedExtendedJSON), ai_bson_toJSON) - ZEND_NS_NAMED_FE("MongoDB\\BSON", fromJSON, PHP_FN(MongoDB_BSON_fromJSON), ai_bson_fromJSON) - ZEND_NS_NAMED_FE("MongoDB\\Driver\\Monitoring", addSubscriber, PHP_FN(MongoDB_Driver_Monitoring_addSubscriber), ai_mongodb_driver_monitoring_subscriber) - ZEND_NS_NAMED_FE("MongoDB\\Driver\\Monitoring", removeSubscriber, PHP_FN(MongoDB_Driver_Monitoring_removeSubscriber), ai_mongodb_driver_monitoring_subscriber) - PHP_FE_END - /* clang-format on */ -}; - +/* {{{ Module dependencies and module entry */ static const zend_module_dep mongodb_deps[] = { /* clang-format off */ ZEND_MOD_REQUIRED("date") @@ -533,7 +497,7 @@ zend_module_entry mongodb_module_entry = { NULL, mongodb_deps, "mongodb", - mongodb_functions, + ext_functions, PHP_MINIT(mongodb), PHP_MSHUTDOWN(mongodb), PHP_RINIT(mongodb), diff --git a/src/BSON/functions.c b/src/BSON/functions.c index e95921c9f..3b31dc468 100644 --- a/src/BSON/functions.c +++ b/src/BSON/functions.c @@ -30,7 +30,7 @@ typedef enum { /* {{{ proto string MongoDB\BSON\fromPHP(array|object $value) Returns the BSON representation of a PHP value */ -PHP_FUNCTION(MongoDB_BSON_fromPHP) +PHP_FUNCTION(fromPHP) { zval* data; bson_t* bson; @@ -48,7 +48,7 @@ PHP_FUNCTION(MongoDB_BSON_fromPHP) /* {{{ proto array|object MongoDB\BSON\toPHP(string $bson [, array $typemap = array()]) Returns the PHP representation of a BSON value, optionally converting it into a custom class */ -PHP_FUNCTION(MongoDB_BSON_toPHP) +PHP_FUNCTION(toPHP) { char* data; size_t data_len; @@ -80,7 +80,7 @@ PHP_FUNCTION(MongoDB_BSON_toPHP) /* {{{ proto string MongoDB\BSON\fromJSON(string $json) Returns the BSON representation of a JSON value */ -PHP_FUNCTION(MongoDB_BSON_fromJSON) +PHP_FUNCTION(fromJSON) { char* json; size_t json_len; @@ -148,21 +148,21 @@ static void phongo_bson_to_json(INTERNAL_FUNCTION_PARAMETERS, php_phongo_json_mo /* {{{ proto string MongoDB\BSON\toJSON(string $bson) Returns the legacy extended JSON representation of a BSON value */ -PHP_FUNCTION(MongoDB_BSON_toJSON) +PHP_FUNCTION(toJSON) { phongo_bson_to_json(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHONGO_JSON_MODE_LEGACY); } /* }}} */ /* {{{ proto string MongoDB\BSON\toCanonicalExtendedJSON(string $bson) Returns the canonical extended JSON representation of a BSON value */ -PHP_FUNCTION(MongoDB_BSON_toCanonicalExtendedJSON) +PHP_FUNCTION(toCanonicalExtendedJSON) { phongo_bson_to_json(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHONGO_JSON_MODE_CANONICAL); } /* }}} */ /* {{{ proto string MongoDB\BSON\toRelaxedExtendedJSON(string $bson) Returns the relaxed extended JSON representation of a BSON value */ -PHP_FUNCTION(MongoDB_BSON_toRelaxedExtendedJSON) +PHP_FUNCTION(toRelaxedExtendedJSON) { phongo_bson_to_json(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHONGO_JSON_MODE_RELAXED); } /* }}} */ diff --git a/src/BSON/functions.h b/src/BSON/functions.h deleted file mode 100644 index 83f2b5d70..000000000 --- a/src/BSON/functions.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2014-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. - */ - -#ifndef PHONGO_BSON_FUNCTIONS_H -#define PHONGO_BSON_FUNCTIONS_H - -#include - -PHP_FUNCTION(MongoDB_BSON_fromPHP); -PHP_FUNCTION(MongoDB_BSON_toPHP); - -PHP_FUNCTION(MongoDB_BSON_fromJSON); -PHP_FUNCTION(MongoDB_BSON_toJSON); -PHP_FUNCTION(MongoDB_BSON_toCanonicalExtendedJSON); -PHP_FUNCTION(MongoDB_BSON_toRelaxedExtendedJSON); - -#endif /* PHONGO_BSON_FUNCTIONS_H */ diff --git a/src/MongoDB/Monitoring/functions.c b/src/MongoDB/Monitoring/functions.c index b4108dcb9..2cae92d68 100644 --- a/src/MongoDB/Monitoring/functions.c +++ b/src/MongoDB/Monitoring/functions.c @@ -24,7 +24,7 @@ ZEND_EXTERN_MODULE_GLOBALS(mongodb) /* {{{ proto void MongoDB\Driver\Monitoring\addSubscriber(MongoDB\Driver\Monitoring\Subscriber $subscriber) Registers a global event subscriber */ -PHP_FUNCTION(MongoDB_Driver_Monitoring_addSubscriber) +PHP_FUNCTION(addSubscriber) { zval* subscriber; @@ -37,7 +37,7 @@ PHP_FUNCTION(MongoDB_Driver_Monitoring_addSubscriber) /* {{{ proto void MongoDB\Driver\Monitoring\removeSubscriber(MongoDB\Driver\Monitoring\Subscriber $subscriber) Unregisters a global event subscriber */ -PHP_FUNCTION(MongoDB_Driver_Monitoring_removeSubscriber) +PHP_FUNCTION(removeSubscriber) { zval* subscriber; diff --git a/src/MongoDB/Monitoring/functions.h b/src/MongoDB/Monitoring/functions.h deleted file mode 100644 index 9696d659d..000000000 --- a/src/MongoDB/Monitoring/functions.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2016-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. - */ - -#ifndef PHONGO_MONITORING_FUNCTIONS_H -#define PHONGO_MONITORING_FUNCTIONS_H - -#include - -PHP_FUNCTION(MongoDB_Driver_Monitoring_addSubscriber); -PHP_FUNCTION(MongoDB_Driver_Monitoring_removeSubscriber); - -#endif /* PHONGO_MONITORING_FUNCTIONS_H */ diff --git a/src/functions.stub.php b/src/functions.stub.php new file mode 100644 index 000000000..d07cec1b3 --- /dev/null +++ b/src/functions.stub.php @@ -0,0 +1,33 @@ += 80000 + function fromPHP(array|object $value): string {} +#else + /** @param array|object $value */ + function fromPHP($value): string {} +#endif + + function toCanonicalExtendedJSON(string $bson): string {} + + function toJSON(string $bson): string {} + +#if PHP_VERSION_ID >= 80000 + function toPHP(string $bson, ?array $typemap = null): array|object {} +#else + /** @return array|object */ + function toPHP(string $bson, ?array $typemap = null) {} +#endif + + function toRelaxedExtendedJSON(string $bson): string {} +} + +namespace MongoDB\Driver\Monitoring { + function addSubscriber(Subscriber $subscriber): void {} + + function removeSubscriber(Subscriber $subscriber): void {} +} diff --git a/src/functions_arginfo.h b/src/functions_arginfo.h new file mode 100644 index 000000000..cb9a50f19 --- /dev/null +++ b/src/functions_arginfo.h @@ -0,0 +1,89 @@ +/* This is a generated file, edit the .stub.php file instead. + * Stub hash: 964efb254b4bb8c11a46e51a3005507aabd8d726 */ + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_MongoDB_BSON_fromJSON, 0, 1, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, json, IS_STRING, 0) +ZEND_END_ARG_INFO() + +#if PHP_VERSION_ID >= 80000 +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_MongoDB_BSON_fromPHP, 0, 1, IS_STRING, 0) + ZEND_ARG_TYPE_MASK(0, value, MAY_BE_ARRAY|MAY_BE_OBJECT, NULL) +ZEND_END_ARG_INFO() +#endif + +#if !(PHP_VERSION_ID >= 80000) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_MongoDB_BSON_fromPHP, 0, 1, IS_STRING, 0) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO() +#endif + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_MongoDB_BSON_toCanonicalExtendedJSON, 0, 1, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, bson, IS_STRING, 0) +ZEND_END_ARG_INFO() + +#define arginfo_MongoDB_BSON_toJSON arginfo_MongoDB_BSON_toCanonicalExtendedJSON + +#if PHP_VERSION_ID >= 80000 +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_MongoDB_BSON_toPHP, 0, 1, MAY_BE_ARRAY|MAY_BE_OBJECT) + ZEND_ARG_TYPE_INFO(0, bson, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, typemap, IS_ARRAY, 1, "null") +ZEND_END_ARG_INFO() +#endif + +#if !(PHP_VERSION_ID >= 80000) +ZEND_BEGIN_ARG_INFO_EX(arginfo_MongoDB_BSON_toPHP, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, bson, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, typemap, IS_ARRAY, 1, "null") +ZEND_END_ARG_INFO() +#endif + +#define arginfo_MongoDB_BSON_toRelaxedExtendedJSON arginfo_MongoDB_BSON_toCanonicalExtendedJSON + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_MongoDB_Driver_Monitoring_addSubscriber, 0, 1, IS_VOID, 0) + ZEND_ARG_OBJ_INFO(0, subscriber, MongoDB\\Driver\\Monitoring\\Subscriber, 0) +ZEND_END_ARG_INFO() + +#define arginfo_MongoDB_Driver_Monitoring_removeSubscriber arginfo_MongoDB_Driver_Monitoring_addSubscriber + + +ZEND_FUNCTION(fromJSON); +#if PHP_VERSION_ID >= 80000 +ZEND_FUNCTION(fromPHP); +#endif +#if !(PHP_VERSION_ID >= 80000) +ZEND_FUNCTION(fromPHP); +#endif +ZEND_FUNCTION(toCanonicalExtendedJSON); +ZEND_FUNCTION(toJSON); +#if PHP_VERSION_ID >= 80000 +ZEND_FUNCTION(toPHP); +#endif +#if !(PHP_VERSION_ID >= 80000) +ZEND_FUNCTION(toPHP); +#endif +ZEND_FUNCTION(toRelaxedExtendedJSON); +ZEND_FUNCTION(addSubscriber); +ZEND_FUNCTION(removeSubscriber); + + +static const zend_function_entry ext_functions[] = { + ZEND_NS_FE("MongoDB\\BSON", fromJSON, arginfo_MongoDB_BSON_fromJSON) +#if PHP_VERSION_ID >= 80000 + ZEND_NS_FE("MongoDB\\BSON", fromPHP, arginfo_MongoDB_BSON_fromPHP) +#endif +#if !(PHP_VERSION_ID >= 80000) + ZEND_NS_FE("MongoDB\\BSON", fromPHP, arginfo_MongoDB_BSON_fromPHP) +#endif + ZEND_NS_FE("MongoDB\\BSON", toCanonicalExtendedJSON, arginfo_MongoDB_BSON_toCanonicalExtendedJSON) + ZEND_NS_FE("MongoDB\\BSON", toJSON, arginfo_MongoDB_BSON_toJSON) +#if PHP_VERSION_ID >= 80000 + ZEND_NS_FE("MongoDB\\BSON", toPHP, arginfo_MongoDB_BSON_toPHP) +#endif +#if !(PHP_VERSION_ID >= 80000) + ZEND_NS_FE("MongoDB\\BSON", toPHP, arginfo_MongoDB_BSON_toPHP) +#endif + ZEND_NS_FE("MongoDB\\BSON", toRelaxedExtendedJSON, arginfo_MongoDB_BSON_toRelaxedExtendedJSON) + ZEND_NS_FE("MongoDB\\Driver\\Monitoring", addSubscriber, arginfo_MongoDB_Driver_Monitoring_addSubscriber) + ZEND_NS_FE("MongoDB\\Driver\\Monitoring", removeSubscriber, arginfo_MongoDB_Driver_Monitoring_removeSubscriber) + ZEND_FE_END +}; From 821b57750cff3ad8828b9231d102702311aaf492 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 25 Aug 2022 09:13:06 +0200 Subject: [PATCH 2/2] Fix wrong phpdoc comment formatting --- src/BSON/Binary.stub.php | 6 +++--- src/BSON/BinaryInterface.stub.php | 6 +++--- src/BSON/BinaryInterface_arginfo.h | 2 +- src/BSON/Binary_arginfo.h | 2 +- src/BSON/DBPointer.stub.php | 6 +++--- src/BSON/DBPointer_arginfo.h | 2 +- src/BSON/Decimal128.stub.php | 6 +++--- src/BSON/Decimal128Interface.stub.php | 6 +++--- src/BSON/Decimal128Interface_arginfo.h | 2 +- src/BSON/Decimal128_arginfo.h | 2 +- src/BSON/Int64.stub.php | 6 +++--- src/BSON/Int64_arginfo.h | 2 +- src/BSON/Javascript.stub.php | 6 +++--- src/BSON/JavascriptInterface.stub.php | 6 +++--- src/BSON/JavascriptInterface_arginfo.h | 2 +- src/BSON/Javascript_arginfo.h | 2 +- src/BSON/MaxKey.stub.php | 6 +++--- src/BSON/MaxKeyInterface.stub.php | 6 +++--- src/BSON/MaxKeyInterface_arginfo.h | 2 +- src/BSON/MaxKey_arginfo.h | 2 +- src/BSON/MinKey.stub.php | 6 +++--- src/BSON/MinKeyInterface.stub.php | 6 +++--- src/BSON/MinKeyInterface_arginfo.h | 2 +- src/BSON/MinKey_arginfo.h | 2 +- src/BSON/ObjectId.stub.php | 6 +++--- src/BSON/ObjectIdInterface.stub.php | 6 +++--- src/BSON/ObjectIdInterface_arginfo.h | 2 +- src/BSON/ObjectId_arginfo.h | 2 +- src/BSON/Persistable.stub.php | 6 +++--- src/BSON/Persistable_arginfo.h | 2 +- src/BSON/Regex.stub.php | 6 +++--- src/BSON/RegexInterface.stub.php | 6 +++--- src/BSON/RegexInterface_arginfo.h | 2 +- src/BSON/Regex_arginfo.h | 2 +- src/BSON/Serializable.stub.php | 6 +++--- src/BSON/Serializable_arginfo.h | 2 +- src/BSON/Symbol.stub.php | 6 +++--- src/BSON/Symbol_arginfo.h | 2 +- src/BSON/Timestamp.stub.php | 6 +++--- src/BSON/TimestampInterface.stub.php | 6 +++--- src/BSON/TimestampInterface_arginfo.h | 2 +- src/BSON/Timestamp_arginfo.h | 2 +- src/BSON/Type.stub.php | 6 +++--- src/BSON/Type_arginfo.h | 2 +- src/BSON/UTCDateTime.stub.php | 6 +++--- src/BSON/UTCDateTimeInterface.stub.php | 6 +++--- src/BSON/UTCDateTimeInterface_arginfo.h | 2 +- src/BSON/UTCDateTime_arginfo.h | 2 +- src/BSON/Undefined.stub.php | 6 +++--- src/BSON/Undefined_arginfo.h | 2 +- src/BSON/Unserializable.stub.php | 6 +++--- src/BSON/Unserializable_arginfo.h | 2 +- 52 files changed, 104 insertions(+), 104 deletions(-) diff --git a/src/BSON/Binary.stub.php b/src/BSON/Binary.stub.php index 49701e900..46dbc545f 100644 --- a/src/BSON/Binary.stub.php +++ b/src/BSON/Binary.stub.php @@ -1,9 +1,9 @@ = 80000 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_BSON_Javascript___construct, 0, 0, 1) diff --git a/src/BSON/MaxKey.stub.php b/src/BSON/MaxKey.stub.php index 90cee0a15..8c8d90878 100644 --- a/src/BSON/MaxKey.stub.php +++ b/src/BSON/MaxKey.stub.php @@ -1,9 +1,9 @@ = 80000 ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(arginfo_class_MongoDB_BSON_Serializable_bsonSerialize, 0, 0, MAY_BE_ARRAY|MAY_BE_OBJECT) diff --git a/src/BSON/Symbol.stub.php b/src/BSON/Symbol.stub.php index de6548581..be43c75b9 100644 --- a/src/BSON/Symbol.stub.php +++ b/src/BSON/Symbol.stub.php @@ -1,9 +1,9 @@ = 80000 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_BSON_Timestamp___construct, 0, 0, 2) diff --git a/src/BSON/Type.stub.php b/src/BSON/Type.stub.php index 51f239163..5571fe9af 100644 --- a/src/BSON/Type.stub.php +++ b/src/BSON/Type.stub.php @@ -1,9 +1,9 @@ = 80000 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_BSON_UTCDateTime___construct, 0, 0, 0) diff --git a/src/BSON/Undefined.stub.php b/src/BSON/Undefined.stub.php index 5d5b38748..3fe0b92fa 100644 --- a/src/BSON/Undefined.stub.php +++ b/src/BSON/Undefined.stub.php @@ -1,9 +1,9 @@