Skip to content

Commit 68527a7

Browse files
committed
Add stubs for some SAPIs
For apache2handler, fpm, litespeed, phpdbg, specifically. Partially implements GH-5295
1 parent 161ee11 commit 68527a7

15 files changed

+195
-91
lines changed

ext/standard/dl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#endif
3939
#endif /* defined(HAVE_LIBDL) */
4040

41-
/* {{{ proto int dl(string extension_filename)
41+
/* {{{ proto bool dl(string extension_filename)
4242
Load a PHP extension at runtime */
4343
PHPAPI PHP_FUNCTION(dl)
4444
{

ext/standard/dl.stub.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
function dl(string $extension_filename): bool {}

ext/standard/dl_arginfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* This is a generated file, edit the .stub.php file instead. */
2+
3+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_dl, 0, 1, _IS_BOOL, 0)
4+
ZEND_ARG_TYPE_INFO(0, extension_filename, IS_STRING, 0)
5+
ZEND_END_ARG_INFO()

sapi/apache2handler/php_functions.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -476,20 +476,6 @@ PHP_MINFO_FUNCTION(apache)
476476
}
477477
}
478478

479-
static const zend_function_entry apache_functions[] = {
480-
PHP_FE(apache_lookup_uri, arginfo_apache_lookup_uri)
481-
PHP_FE(virtual, arginfo_virtual)
482-
PHP_FE(apache_request_headers, arginfo_apache_request_headers)
483-
PHP_FE(apache_response_headers, arginfo_apache_response_headers)
484-
PHP_FE(apache_setenv, arginfo_apache_setenv)
485-
PHP_FE(apache_getenv, arginfo_apache_getenv)
486-
PHP_FE(apache_note, arginfo_apache_note)
487-
PHP_FE(apache_get_version, arginfo_apache_get_version)
488-
PHP_FE(apache_get_modules, arginfo_apache_get_modules)
489-
PHP_FALIAS(getallheaders, apache_request_headers, arginfo_getallheaders)
490-
{NULL, NULL, NULL}
491-
};
492-
493479
PHP_INI_BEGIN()
494480
STD_PHP_INI_ENTRY("xbithack", "0", PHP_INI_ALL, OnUpdateBool, xbithack, php_apache2_info_struct, php_apache2_info)
495481
STD_PHP_INI_ENTRY("engine", "1", PHP_INI_ALL, OnUpdateBool, engine, php_apache2_info_struct, php_apache2_info)
@@ -514,7 +500,7 @@ static PHP_MSHUTDOWN_FUNCTION(apache)
514500
zend_module_entry php_apache_module = {
515501
STANDARD_MODULE_HEADER,
516502
"apache2handler",
517-
apache_functions,
503+
ext_functions,
518504
PHP_MINIT(apache),
519505
PHP_MSHUTDOWN(apache),
520506
NULL,

sapi/apache2handler/php_functions.stub.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<?php
22

3+
/** @generate-function-entries */
4+
35
function apache_lookup_uri(string $filename): object|false {}
46

57
function virtual(string $uri): bool {}
68

79
function apache_request_headers(): array {}
810

11+
/** @alias apache_request_headers */
912
function getallheaders(): array {}
1013

1114
function apache_response_headers(): array {}

sapi/apache2handler/php_functions_arginfo.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,29 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_apache_get_version, 0, 0, MAY_BE
3535
ZEND_END_ARG_INFO()
3636

3737
#define arginfo_apache_get_modules arginfo_apache_request_headers
38+
39+
40+
ZEND_FUNCTION(apache_lookup_uri);
41+
ZEND_FUNCTION(virtual);
42+
ZEND_FUNCTION(apache_request_headers);
43+
ZEND_FUNCTION(apache_response_headers);
44+
ZEND_FUNCTION(apache_note);
45+
ZEND_FUNCTION(apache_setenv);
46+
ZEND_FUNCTION(apache_getenv);
47+
ZEND_FUNCTION(apache_get_version);
48+
ZEND_FUNCTION(apache_get_modules);
49+
50+
51+
static const zend_function_entry ext_functions[] = {
52+
ZEND_FE(apache_lookup_uri, arginfo_apache_lookup_uri)
53+
ZEND_FE(virtual, arginfo_virtual)
54+
ZEND_FE(apache_request_headers, arginfo_apache_request_headers)
55+
ZEND_FALIAS(getallheaders, apache_request_headers, arginfo_getallheaders)
56+
ZEND_FE(apache_response_headers, arginfo_apache_response_headers)
57+
ZEND_FE(apache_note, arginfo_apache_note)
58+
ZEND_FE(apache_setenv, arginfo_apache_setenv)
59+
ZEND_FE(apache_getenv, arginfo_apache_getenv)
60+
ZEND_FE(apache_get_version, arginfo_apache_get_version)
61+
ZEND_FE(apache_get_modules, arginfo_apache_get_modules)
62+
ZEND_FE_END
63+
};

sapi/fpm/fpm/fpm_main.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ int __riscosify_control = __RISCOSIFY_STRICT_UNIX_SPECS;
8282

8383
#include <php_config.h>
8484
#include "fpm.h"
85+
#include "fpm_main_arginfo.h"
8586
#include "fpm_request.h"
8687
#include "fpm_status.h"
8788
#include "fpm_signals.h"
@@ -1457,9 +1458,6 @@ static PHP_MINFO_FUNCTION(cgi)
14571458
}
14581459
/* }}} */
14591460

1460-
ZEND_BEGIN_ARG_INFO(cgi_fcgi_sapi_no_arginfo, 0)
1461-
ZEND_END_ARG_INFO()
1462-
14631461
PHP_FUNCTION(fastcgi_finish_request) /* {{{ */
14641462
{
14651463
fcgi_request *request = (fcgi_request*) SG(server_context);
@@ -1510,18 +1508,10 @@ PHP_FUNCTION(fpm_get_status) /* {{{ */
15101508
}
15111509
/* }}} */
15121510

1513-
static const zend_function_entry cgi_fcgi_sapi_functions[] = {
1514-
PHP_FE(fastcgi_finish_request, cgi_fcgi_sapi_no_arginfo)
1515-
PHP_FE(fpm_get_status, cgi_fcgi_sapi_no_arginfo)
1516-
PHP_FE(apache_request_headers, cgi_fcgi_sapi_no_arginfo)
1517-
PHP_FALIAS(getallheaders, apache_request_headers, cgi_fcgi_sapi_no_arginfo)
1518-
PHP_FE_END
1519-
};
1520-
15211511
static zend_module_entry cgi_module_entry = {
15221512
STANDARD_MODULE_HEADER,
15231513
"cgi-fcgi",
1524-
cgi_fcgi_sapi_functions,
1514+
ext_functions,
15251515
PHP_MINIT(cgi),
15261516
PHP_MSHUTDOWN(cgi),
15271517
NULL,

sapi/fpm/fpm/fpm_main.stub.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
/** @generate-function-entries */
4+
5+
function fastcgi_finish_request(): bool {}
6+
7+
function apache_request_headers(): array {}
8+
9+
/** @alias apache_request_headers */
10+
function getallheaders(): array {}
11+
12+
function fpm_get_status(): array|false {}

sapi/fpm/fpm/fpm_main_arginfo.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* This is a generated file, edit the .stub.php file instead. */
2+
3+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_fastcgi_finish_request, 0, 0, _IS_BOOL, 0)
4+
ZEND_END_ARG_INFO()
5+
6+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_apache_request_headers, 0, 0, IS_ARRAY, 0)
7+
ZEND_END_ARG_INFO()
8+
9+
#define arginfo_getallheaders arginfo_apache_request_headers
10+
11+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_fpm_get_status, 0, 0, MAY_BE_ARRAY|MAY_BE_FALSE)
12+
ZEND_END_ARG_INFO()
13+
14+
15+
ZEND_FUNCTION(fastcgi_finish_request);
16+
ZEND_FUNCTION(apache_request_headers);
17+
ZEND_FUNCTION(fpm_get_status);
18+
19+
20+
static const zend_function_entry ext_functions[] = {
21+
ZEND_FE(fastcgi_finish_request, arginfo_fastcgi_finish_request)
22+
ZEND_FE(apache_request_headers, arginfo_apache_request_headers)
23+
ZEND_FALIAS(getallheaders, apache_request_headers, arginfo_getallheaders)
24+
ZEND_FE(fpm_get_status, arginfo_fpm_get_status)
25+
ZEND_FE_END
26+
};

sapi/litespeed/lsapi_main.c

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "ext/standard/basic_functions.h"
2525
#include "ext/standard/info.h"
2626
#include "lsapilib.h"
27+
#include "lsapi_main_arginfo.h"
2728

2829
#include <stdio.h>
2930
#include <stdlib.h>
@@ -1615,29 +1616,13 @@ int main( int argc, char * argv[] )
16151616

16161617
/* LiteSpeed PHP module starts here */
16171618

1618-
/* {{{ arginfo */
1619-
ZEND_BEGIN_ARG_INFO(arginfo_litespeed__void, 0)
1620-
ZEND_END_ARG_INFO()
1621-
/* }}} */
1622-
16231619
PHP_FUNCTION(litespeed_request_headers);
16241620
PHP_FUNCTION(litespeed_response_headers);
16251621
PHP_FUNCTION(apache_get_modules);
16261622
PHP_FUNCTION(litespeed_finish_request);
16271623

16281624
PHP_MINFO_FUNCTION(litespeed);
16291625

1630-
static const zend_function_entry litespeed_functions[] = {
1631-
PHP_FE(litespeed_request_headers, arginfo_litespeed__void)
1632-
PHP_FE(litespeed_response_headers, arginfo_litespeed__void)
1633-
PHP_FE(apache_get_modules, arginfo_litespeed__void)
1634-
PHP_FE(litespeed_finish_request, arginfo_litespeed__void)
1635-
PHP_FALIAS(getallheaders, litespeed_request_headers, arginfo_litespeed__void)
1636-
PHP_FALIAS(apache_request_headers, litespeed_request_headers, arginfo_litespeed__void)
1637-
PHP_FALIAS(apache_response_headers, litespeed_response_headers, arginfo_litespeed__void)
1638-
{NULL, NULL, NULL}
1639-
};
1640-
16411626
static PHP_MINIT_FUNCTION(litespeed)
16421627
{
16431628
user_config_cache_init();
@@ -1675,7 +1660,7 @@ static PHP_MSHUTDOWN_FUNCTION(litespeed)
16751660
zend_module_entry litespeed_module_entry = {
16761661
STANDARD_MODULE_HEADER,
16771662
"litespeed",
1678-
litespeed_functions,
1663+
ext_functions,
16791664
PHP_MINIT(litespeed),
16801665
PHP_MSHUTDOWN(litespeed),
16811666
NULL,
@@ -1697,14 +1682,13 @@ static int add_associate_array( const char * pKey, int keyLen, const char * pVal
16971682
Fetch all HTTP request headers */
16981683
PHP_FUNCTION(litespeed_request_headers)
16991684
{
1700-
/* TODO: */
1701-
if (ZEND_NUM_ARGS() > 0) {
1702-
WRONG_PARAM_COUNT;
1685+
if (zend_parse_parameters_none() == FAILURE) {
1686+
RETURN_THROWS();
17031687
}
1688+
17041689
array_init(return_value);
17051690

17061691
LSAPI_ForeachOrgHeader( add_associate_array, return_value );
1707-
17081692
}
17091693
/* }}} */
17101694

@@ -1720,9 +1704,9 @@ PHP_FUNCTION(litespeed_response_headers)
17201704
int len;
17211705
char headerBuf[SAPI_LSAPI_MAX_HEADER_LENGTH];
17221706

1723-
if (ZEND_NUM_ARGS() > 0) {
1724-
WRONG_PARAM_COUNT;
1725-
}
1707+
if (zend_parse_parameters_none() == FAILURE) {
1708+
RETURN_THROWS();
1709+
}
17261710

17271711
if (!&SG(sapi_headers).headers) {
17281712
RETURN_FALSE;
@@ -1762,10 +1746,11 @@ PHP_FUNCTION(apache_get_modules)
17621746
"mod_rewrite", "mod_mime", "mod_headers", "mod_expires", "mod_auth_basic", NULL
17631747
};
17641748
const char **name = mod_names;
1765-
/* TODO: */
1766-
if (ZEND_NUM_ARGS() > 0) {
1767-
WRONG_PARAM_COUNT;
1768-
}
1749+
1750+
if (zend_parse_parameters_none() == FAILURE) {
1751+
RETURN_THROWS();
1752+
}
1753+
17691754
array_init(return_value);
17701755
while( *name )
17711756
{
@@ -1776,13 +1761,13 @@ PHP_FUNCTION(apache_get_modules)
17761761
/* }}} */
17771762

17781763

1779-
/* {{{ proto array litespeed_finish_request(void)
1764+
/* {{{ proto bool litespeed_finish_request(void)
17801765
Flushes all response data to the client */
17811766
PHP_FUNCTION(litespeed_finish_request)
17821767
{
1783-
if (ZEND_NUM_ARGS() > 0) {
1784-
WRONG_PARAM_COUNT;
1785-
}
1768+
if (zend_parse_parameters_none() == FAILURE) {
1769+
RETURN_THROWS();
1770+
}
17861771

17871772
php_output_end_all();
17881773
php_header();

sapi/litespeed/lsapi_main.stub.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/** @generate-function-entries */
4+
5+
function litespeed_request_headers(): array {}
6+
7+
/** @alias litespeed_request_headers */
8+
function getallheaders(): array {}
9+
10+
/** @alias litespeed_request_headers */
11+
function apache_request_headers(): array {}
12+
13+
function litespeed_response_headers(): array|false {}
14+
15+
/** @alias litespeed_response_headers */
16+
function apache_response_headers(): array|false {}
17+
18+
function apache_get_modules(): array {}
19+
20+
function litespeed_finish_request(): bool {}

sapi/litespeed/lsapi_main_arginfo.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* This is a generated file, edit the .stub.php file instead. */
2+
3+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_litespeed_request_headers, 0, 0, IS_ARRAY, 0)
4+
ZEND_END_ARG_INFO()
5+
6+
#define arginfo_getallheaders arginfo_litespeed_request_headers
7+
8+
#define arginfo_apache_request_headers arginfo_litespeed_request_headers
9+
10+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_litespeed_response_headers, 0, 0, MAY_BE_ARRAY|MAY_BE_FALSE)
11+
ZEND_END_ARG_INFO()
12+
13+
#define arginfo_apache_response_headers arginfo_litespeed_response_headers
14+
15+
#define arginfo_apache_get_modules arginfo_litespeed_request_headers
16+
17+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_litespeed_finish_request, 0, 0, _IS_BOOL, 0)
18+
ZEND_END_ARG_INFO()
19+
20+
21+
ZEND_FUNCTION(litespeed_request_headers);
22+
ZEND_FUNCTION(litespeed_response_headers);
23+
ZEND_FUNCTION(apache_get_modules);
24+
ZEND_FUNCTION(litespeed_finish_request);
25+
26+
27+
static const zend_function_entry ext_functions[] = {
28+
ZEND_FE(litespeed_request_headers, arginfo_litespeed_request_headers)
29+
ZEND_FALIAS(getallheaders, litespeed_request_headers, arginfo_getallheaders)
30+
ZEND_FALIAS(apache_request_headers, litespeed_request_headers, arginfo_apache_request_headers)
31+
ZEND_FE(litespeed_response_headers, arginfo_litespeed_response_headers)
32+
ZEND_FALIAS(apache_response_headers, litespeed_response_headers, arginfo_apache_response_headers)
33+
ZEND_FE(apache_get_modules, arginfo_apache_get_modules)
34+
ZEND_FE(litespeed_finish_request, arginfo_litespeed_finish_request)
35+
ZEND_FE_END
36+
};

0 commit comments

Comments
 (0)