Skip to content

Commit fff4d48

Browse files
committed
Merge pull request #14 from zelgerj/master
added new ini setting reset default sapi type
2 parents c569274 + 1ad5796 commit fff4d48

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

src/appserver.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ zend_module_entry appserver_module_entry = {
7171
};
7272

7373
PHP_INI_BEGIN()
74+
PHP_INI_ENTRY("appserver.php_sapi", "", PHP_INI_ALL, NULL)
7475
PHP_INI_ENTRY("appserver.remove_functions", "", PHP_INI_ALL, NULL)
7576
PHP_INI_ENTRY("appserver.remove_constants", "", PHP_INI_ALL, NULL)
7677
PHP_INI_END()
@@ -207,23 +208,25 @@ PHP_RINIT_FUNCTION(appserver)
207208
char *ptr, *str, *sapiconst = APPSERVER_CONSTANT_PHP_SAPI;
208209
zend_constant *defined;
209210
zval *new_phpsapi;
210-
char *new_phpsapi_name = APPSERVER_SAPI_NAME;
211-
212-
/* create zval for new sapi string */
213-
MAKE_STD_ZVAL(new_phpsapi);
214-
ZVAL_STRING(new_phpsapi, new_phpsapi_name, 1);
215-
216-
/* check if PHP_SAPI const can be found to overwrite cli sapi name to appserver */
217-
if (zend_hash_find(EG(zend_constants), sapiconst, strlen(sapiconst)+1, (void **) &defined) == SUCCESS) {
218-
/* create new constant with new php sapi name */
219-
zend_constant c;
220-
c.value = *new_phpsapi;
221-
c.flags = PHP_USER_CONSTANT;
222-
c.name = zend_strndup(&sapiconst, strlen(sapiconst));
223-
c.name_len = strlen(sapiconst) + 1;
224-
c.module_number = 0;
225-
/* update PHP_SAPI constant in hash table */
226-
zend_hash_update(EG(zend_constants), sapiconst, strlen(sapiconst)+1, (void*)&c, sizeof(zend_constant), (void **)&c);
211+
char *new_phpsapi_name;
212+
213+
if (INI_STR("appserver.php_sapi") != "") {
214+
new_phpsapi_name = INI_STR("appserver.php_sapi");
215+
/* check if PHP_SAPI const can be found to overwrite cli sapi name to appserver */
216+
if (zend_hash_find(EG(zend_constants), sapiconst, strlen(sapiconst)+1, (void **) &defined) == SUCCESS) {
217+
/* create zval for new sapi string */
218+
MAKE_STD_ZVAL(new_phpsapi);
219+
ZVAL_STRING(new_phpsapi, new_phpsapi_name, 1);
220+
/* create new constant with new php sapi name */
221+
zend_constant c;
222+
c.value = *new_phpsapi;
223+
c.flags = PHP_USER_CONSTANT;
224+
c.name = zend_strndup(&sapiconst, strlen(sapiconst));
225+
c.name_len = strlen(sapiconst) + 1;
226+
c.module_number = 0;
227+
/* update PHP_SAPI constant in hash table */
228+
zend_hash_update(EG(zend_constants), sapiconst, strlen(sapiconst)+1, (void*)&c, sizeof(zend_constant), (void **)&c);
229+
}
227230
}
228231

229232
/* remove functions given in ini setting */

src/tests/appserver_009.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
--TEST--
2-
appserver: check if PHP_SAPI is rewritten to appserver
2+
appserver: check if PHP_SAPI is rewritten to appserver by ini setting
33
--CREDITS--
44
Johann Zelger <jz [at] techdivision [dot] com>
5+
--INI--
6+
appserver.php_sapi=appserver
57
--FILE--
68
<?php
79

0 commit comments

Comments
 (0)