Skip to content

Commit 88897fb

Browse files
committed
PHPC-2128: Create stub file for functions
1 parent 28b4d46 commit 88897fb

File tree

7 files changed

+133
-102
lines changed

7 files changed

+133
-102
lines changed

php_phongo.c

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
#include "src/phongo_client.h"
2929
#include "src/phongo_error.h"
3030
#include "src/phongo_ini.h"
31-
#include "src/BSON/functions.h"
32-
#include "src/MongoDB/Monitoring/functions.h"
31+
#include "src/functions_arginfo.h"
3332

3433
ZEND_DECLARE_MODULE_GLOBALS(mongodb)
3534
#if defined(ZTS) && defined(COMPILE_DL_MONGODB)
@@ -482,42 +481,7 @@ PHP_FUNCTION(MongoDB_disabled___wakeup) /* {{{ */
482481
} /* }}} */
483482
/* }}} */
484483

485-
/* {{{ Extension functions, module dependencies, and module entry */
486-
ZEND_BEGIN_ARG_INFO_EX(ai_bson_fromPHP, 0, 0, 1)
487-
ZEND_ARG_INFO(0, value)
488-
ZEND_END_ARG_INFO();
489-
490-
ZEND_BEGIN_ARG_INFO_EX(ai_bson_toPHP, 0, 0, 1)
491-
ZEND_ARG_INFO(0, bson)
492-
ZEND_ARG_ARRAY_INFO(0, typemap, 0)
493-
ZEND_END_ARG_INFO();
494-
495-
ZEND_BEGIN_ARG_INFO_EX(ai_bson_toJSON, 0, 0, 1)
496-
ZEND_ARG_INFO(0, bson)
497-
ZEND_END_ARG_INFO();
498-
499-
ZEND_BEGIN_ARG_INFO_EX(ai_bson_fromJSON, 0, 0, 1)
500-
ZEND_ARG_INFO(0, json)
501-
ZEND_END_ARG_INFO();
502-
503-
ZEND_BEGIN_ARG_INFO_EX(ai_mongodb_driver_monitoring_subscriber, 0, 0, 1)
504-
ZEND_ARG_OBJ_INFO(0, subscriber, MongoDB\\Driver\\Monitoring\\Subscriber, 0)
505-
ZEND_END_ARG_INFO();
506-
507-
static const zend_function_entry mongodb_functions[] = {
508-
/* clang-format off */
509-
ZEND_NS_NAMED_FE("MongoDB\\BSON", fromPHP, PHP_FN(MongoDB_BSON_fromPHP), ai_bson_fromPHP)
510-
ZEND_NS_NAMED_FE("MongoDB\\BSON", toPHP, PHP_FN(MongoDB_BSON_toPHP), ai_bson_toPHP)
511-
ZEND_NS_NAMED_FE("MongoDB\\BSON", toJSON, PHP_FN(MongoDB_BSON_toJSON), ai_bson_toJSON)
512-
ZEND_NS_NAMED_FE("MongoDB\\BSON", toCanonicalExtendedJSON, PHP_FN(MongoDB_BSON_toCanonicalExtendedJSON), ai_bson_toJSON)
513-
ZEND_NS_NAMED_FE("MongoDB\\BSON", toRelaxedExtendedJSON, PHP_FN(MongoDB_BSON_toRelaxedExtendedJSON), ai_bson_toJSON)
514-
ZEND_NS_NAMED_FE("MongoDB\\BSON", fromJSON, PHP_FN(MongoDB_BSON_fromJSON), ai_bson_fromJSON)
515-
ZEND_NS_NAMED_FE("MongoDB\\Driver\\Monitoring", addSubscriber, PHP_FN(MongoDB_Driver_Monitoring_addSubscriber), ai_mongodb_driver_monitoring_subscriber)
516-
ZEND_NS_NAMED_FE("MongoDB\\Driver\\Monitoring", removeSubscriber, PHP_FN(MongoDB_Driver_Monitoring_removeSubscriber), ai_mongodb_driver_monitoring_subscriber)
517-
PHP_FE_END
518-
/* clang-format on */
519-
};
520-
484+
/* {{{ Module dependencies and module entry */
521485
static const zend_module_dep mongodb_deps[] = {
522486
/* clang-format off */
523487
ZEND_MOD_REQUIRED("date")
@@ -533,7 +497,7 @@ zend_module_entry mongodb_module_entry = {
533497
NULL,
534498
mongodb_deps,
535499
"mongodb",
536-
mongodb_functions,
500+
ext_functions,
537501
PHP_MINIT(mongodb),
538502
PHP_MSHUTDOWN(mongodb),
539503
PHP_RINIT(mongodb),

src/BSON/functions.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ typedef enum {
3030

3131
/* {{{ proto string MongoDB\BSON\fromPHP(array|object $value)
3232
Returns the BSON representation of a PHP value */
33-
PHP_FUNCTION(MongoDB_BSON_fromPHP)
33+
PHP_FUNCTION(fromPHP)
3434
{
3535
zval* data;
3636
bson_t* bson;
@@ -48,7 +48,7 @@ PHP_FUNCTION(MongoDB_BSON_fromPHP)
4848

4949
/* {{{ proto array|object MongoDB\BSON\toPHP(string $bson [, array $typemap = array()])
5050
Returns the PHP representation of a BSON value, optionally converting it into a custom class */
51-
PHP_FUNCTION(MongoDB_BSON_toPHP)
51+
PHP_FUNCTION(toPHP)
5252
{
5353
char* data;
5454
size_t data_len;
@@ -80,7 +80,7 @@ PHP_FUNCTION(MongoDB_BSON_toPHP)
8080

8181
/* {{{ proto string MongoDB\BSON\fromJSON(string $json)
8282
Returns the BSON representation of a JSON value */
83-
PHP_FUNCTION(MongoDB_BSON_fromJSON)
83+
PHP_FUNCTION(fromJSON)
8484
{
8585
char* json;
8686
size_t json_len;
@@ -148,21 +148,21 @@ static void phongo_bson_to_json(INTERNAL_FUNCTION_PARAMETERS, php_phongo_json_mo
148148

149149
/* {{{ proto string MongoDB\BSON\toJSON(string $bson)
150150
Returns the legacy extended JSON representation of a BSON value */
151-
PHP_FUNCTION(MongoDB_BSON_toJSON)
151+
PHP_FUNCTION(toJSON)
152152
{
153153
phongo_bson_to_json(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHONGO_JSON_MODE_LEGACY);
154154
} /* }}} */
155155

156156
/* {{{ proto string MongoDB\BSON\toCanonicalExtendedJSON(string $bson)
157157
Returns the canonical extended JSON representation of a BSON value */
158-
PHP_FUNCTION(MongoDB_BSON_toCanonicalExtendedJSON)
158+
PHP_FUNCTION(toCanonicalExtendedJSON)
159159
{
160160
phongo_bson_to_json(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHONGO_JSON_MODE_CANONICAL);
161161
} /* }}} */
162162

163163
/* {{{ proto string MongoDB\BSON\toRelaxedExtendedJSON(string $bson)
164164
Returns the relaxed extended JSON representation of a BSON value */
165-
PHP_FUNCTION(MongoDB_BSON_toRelaxedExtendedJSON)
165+
PHP_FUNCTION(toRelaxedExtendedJSON)
166166
{
167167
phongo_bson_to_json(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHONGO_JSON_MODE_RELAXED);
168168
} /* }}} */

src/BSON/functions.h

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/MongoDB/Monitoring/functions.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ZEND_EXTERN_MODULE_GLOBALS(mongodb)
2424

2525
/* {{{ proto void MongoDB\Driver\Monitoring\addSubscriber(MongoDB\Driver\Monitoring\Subscriber $subscriber)
2626
Registers a global event subscriber */
27-
PHP_FUNCTION(MongoDB_Driver_Monitoring_addSubscriber)
27+
PHP_FUNCTION(addSubscriber)
2828
{
2929
zval* subscriber;
3030

@@ -37,7 +37,7 @@ PHP_FUNCTION(MongoDB_Driver_Monitoring_addSubscriber)
3737

3838
/* {{{ proto void MongoDB\Driver\Monitoring\removeSubscriber(MongoDB\Driver\Monitoring\Subscriber $subscriber)
3939
Unregisters a global event subscriber */
40-
PHP_FUNCTION(MongoDB_Driver_Monitoring_removeSubscriber)
40+
PHP_FUNCTION(removeSubscriber)
4141
{
4242
zval* subscriber;
4343

src/MongoDB/Monitoring/functions.h

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/functions.stub.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/** @generate-function-entries */
4+
5+
namespace MongoDB\BSON {
6+
function fromJSON(string $json): string {}
7+
8+
#if PHP_VERSION_ID >= 80000
9+
function fromPHP(array|object $value): string {}
10+
#else
11+
/** @param array|object $value */
12+
function fromPHP($value): string {}
13+
#endif
14+
15+
function toCanonicalExtendedJSON(string $bson): string {}
16+
17+
function toJSON(string $bson): string {}
18+
19+
#if PHP_VERSION_ID >= 80000
20+
function toPHP(string $bson, ?array $typemap = null): array|object {}
21+
#else
22+
/** @return array|object */
23+
function toPHP(string $bson, ?array $typemap = null) {}
24+
#endif
25+
26+
function toRelaxedExtendedJSON(string $bson): string {}
27+
}
28+
29+
namespace MongoDB\Driver\Monitoring {
30+
function addSubscriber(Subscriber $subscriber): void {}
31+
32+
function removeSubscriber(Subscriber $subscriber): void {}
33+
}

src/functions_arginfo.h

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* This is a generated file, edit the .stub.php file instead.
2+
* Stub hash: 964efb254b4bb8c11a46e51a3005507aabd8d726 */
3+
4+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_MongoDB_BSON_fromJSON, 0, 1, IS_STRING, 0)
5+
ZEND_ARG_TYPE_INFO(0, json, IS_STRING, 0)
6+
ZEND_END_ARG_INFO()
7+
8+
#if PHP_VERSION_ID >= 80000
9+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_MongoDB_BSON_fromPHP, 0, 1, IS_STRING, 0)
10+
ZEND_ARG_TYPE_MASK(0, value, MAY_BE_ARRAY|MAY_BE_OBJECT, NULL)
11+
ZEND_END_ARG_INFO()
12+
#endif
13+
14+
#if !(PHP_VERSION_ID >= 80000)
15+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_MongoDB_BSON_fromPHP, 0, 1, IS_STRING, 0)
16+
ZEND_ARG_INFO(0, value)
17+
ZEND_END_ARG_INFO()
18+
#endif
19+
20+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_MongoDB_BSON_toCanonicalExtendedJSON, 0, 1, IS_STRING, 0)
21+
ZEND_ARG_TYPE_INFO(0, bson, IS_STRING, 0)
22+
ZEND_END_ARG_INFO()
23+
24+
#define arginfo_MongoDB_BSON_toJSON arginfo_MongoDB_BSON_toCanonicalExtendedJSON
25+
26+
#if PHP_VERSION_ID >= 80000
27+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_MongoDB_BSON_toPHP, 0, 1, MAY_BE_ARRAY|MAY_BE_OBJECT)
28+
ZEND_ARG_TYPE_INFO(0, bson, IS_STRING, 0)
29+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, typemap, IS_ARRAY, 1, "null")
30+
ZEND_END_ARG_INFO()
31+
#endif
32+
33+
#if !(PHP_VERSION_ID >= 80000)
34+
ZEND_BEGIN_ARG_INFO_EX(arginfo_MongoDB_BSON_toPHP, 0, 0, 1)
35+
ZEND_ARG_TYPE_INFO(0, bson, IS_STRING, 0)
36+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, typemap, IS_ARRAY, 1, "null")
37+
ZEND_END_ARG_INFO()
38+
#endif
39+
40+
#define arginfo_MongoDB_BSON_toRelaxedExtendedJSON arginfo_MongoDB_BSON_toCanonicalExtendedJSON
41+
42+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_MongoDB_Driver_Monitoring_addSubscriber, 0, 1, IS_VOID, 0)
43+
ZEND_ARG_OBJ_INFO(0, subscriber, MongoDB\\Driver\\Monitoring\\Subscriber, 0)
44+
ZEND_END_ARG_INFO()
45+
46+
#define arginfo_MongoDB_Driver_Monitoring_removeSubscriber arginfo_MongoDB_Driver_Monitoring_addSubscriber
47+
48+
49+
ZEND_FUNCTION(fromJSON);
50+
#if PHP_VERSION_ID >= 80000
51+
ZEND_FUNCTION(fromPHP);
52+
#endif
53+
#if !(PHP_VERSION_ID >= 80000)
54+
ZEND_FUNCTION(fromPHP);
55+
#endif
56+
ZEND_FUNCTION(toCanonicalExtendedJSON);
57+
ZEND_FUNCTION(toJSON);
58+
#if PHP_VERSION_ID >= 80000
59+
ZEND_FUNCTION(toPHP);
60+
#endif
61+
#if !(PHP_VERSION_ID >= 80000)
62+
ZEND_FUNCTION(toPHP);
63+
#endif
64+
ZEND_FUNCTION(toRelaxedExtendedJSON);
65+
ZEND_FUNCTION(addSubscriber);
66+
ZEND_FUNCTION(removeSubscriber);
67+
68+
69+
static const zend_function_entry ext_functions[] = {
70+
ZEND_NS_FE("MongoDB\\BSON", fromJSON, arginfo_MongoDB_BSON_fromJSON)
71+
#if PHP_VERSION_ID >= 80000
72+
ZEND_NS_FE("MongoDB\\BSON", fromPHP, arginfo_MongoDB_BSON_fromPHP)
73+
#endif
74+
#if !(PHP_VERSION_ID >= 80000)
75+
ZEND_NS_FE("MongoDB\\BSON", fromPHP, arginfo_MongoDB_BSON_fromPHP)
76+
#endif
77+
ZEND_NS_FE("MongoDB\\BSON", toCanonicalExtendedJSON, arginfo_MongoDB_BSON_toCanonicalExtendedJSON)
78+
ZEND_NS_FE("MongoDB\\BSON", toJSON, arginfo_MongoDB_BSON_toJSON)
79+
#if PHP_VERSION_ID >= 80000
80+
ZEND_NS_FE("MongoDB\\BSON", toPHP, arginfo_MongoDB_BSON_toPHP)
81+
#endif
82+
#if !(PHP_VERSION_ID >= 80000)
83+
ZEND_NS_FE("MongoDB\\BSON", toPHP, arginfo_MongoDB_BSON_toPHP)
84+
#endif
85+
ZEND_NS_FE("MongoDB\\BSON", toRelaxedExtendedJSON, arginfo_MongoDB_BSON_toRelaxedExtendedJSON)
86+
ZEND_NS_FE("MongoDB\\Driver\\Monitoring", addSubscriber, arginfo_MongoDB_Driver_Monitoring_addSubscriber)
87+
ZEND_NS_FE("MongoDB\\Driver\\Monitoring", removeSubscriber, arginfo_MongoDB_Driver_Monitoring_removeSubscriber)
88+
ZEND_FE_END
89+
};

0 commit comments

Comments
 (0)