php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #76217
Patch yaf_dispatcher_setDefault.patch revision 2018-04-13 11:10 UTC by fanjiapeng at 126 dot com

Patch yaf_dispatcher_setDefault.patch for yaf Bug #76217

Patch version 2018-04-13 11:10 UTC

Return to Bug #76217 | Download this patch
Patch Revisions:

Developer: fanjiapeng@126.com

diff --git a/yaf_dispatcher.c b/yaf_dispatcher.c
index 83901d8..fe0ea2a 100644
--- a/yaf_dispatcher.c
+++ b/yaf_dispatcher.c
@@ -1231,71 +1231,63 @@ PHP_METHOD(yaf_dispatcher, setView) {
 /** {{{ proto public Yaf_Dispatcher::setDefaultModule(string $name)
 */
 PHP_METHOD(yaf_dispatcher, setDefaultModule) {
-	zval *module;
-	zval *self = getThis();
+    zend_string *module = NULL;
 
-	if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &module) == FAILURE) {
-		return;
-	}
+    if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &module) == FAILURE) {
+        return;
+    }
 
-	if (IS_STRING == Z_TYPE_P(module) && Z_STRLEN_P(module)
-			&& yaf_application_is_module_name(Z_STR_P(module))) {
-		zval module_std;
-		ZVAL_STRING(&module_std, zend_str_tolower_dup(Z_STRVAL_P(module), Z_STRLEN_P(module)));
-		*Z_STRVAL(module_std) = toupper(*Z_STRVAL(module_std));
-		zend_update_property(yaf_dispatcher_ce, self, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_MODULE), &module_std);
-		zval_ptr_dtor(&module_std);
+    if (yaf_application_is_module_name_str(ZSTR_VAL(module), ZSTR_LEN(module))) {
+        zval *self = getThis();
+        zend_string *lc_name = zend_string_tolower(module);
+        *ZSTR_VAL(lc_name) = toupper(*ZSTR_VAL(lc_name));
 
-		RETURN_ZVAL(self, 1, 0);
-	}
+        zend_update_property_str(yaf_dispatcher_ce, self, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_MODULE), lc_name);
+        zend_string_release(lc_name);
 
-	RETURN_FALSE;
+        RETURN_ZVAL(self, 1, 0);
+    }
+
+    RETURN_FALSE;
 }
 /* }}} */
 
 /** {{{ proto public Yaf_Dispatcher::setDefaultController(string $name)
 */
 PHP_METHOD(yaf_dispatcher, setDefaultController) {
-	zval *controller;
-	zval *self = getThis();
+    zend_string *controller = NULL;
 
-	if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &controller) == FAILURE) {
-		return;
-	}
+    if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &controller) == FAILURE) {
+        return;
+    }
 
-	if (IS_STRING == Z_TYPE_P(controller) && Z_STRLEN_P(controller)) {
-		zval controller_std;
-		ZVAL_STRING(&controller_std, zend_str_tolower_dup(Z_STRVAL_P(controller), Z_STRLEN_P(controller)));
-		*Z_STRVAL_P(&controller_std) = toupper(*Z_STRVAL(controller_std));
-		zend_update_property(yaf_dispatcher_ce, self, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_CONTROLLER), &controller_std);
+    zval *self = getThis();
+    zend_string *lc_name = zend_string_tolower(controller);
+    *ZSTR_VAL(lc_name) = toupper(*ZSTR_VAL(lc_name));
 
-		RETURN_ZVAL(self, 1, 0);
-	}
+    zend_update_property_str(yaf_dispatcher_ce, self, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_CONTROLLER), lc_name);
+    zend_string_release(lc_name);
 
-	RETURN_FALSE;
+    RETURN_ZVAL(self, 1, 0);
 }
 /* }}} */
 
 /** {{{ proto public Yaf_Dispatcher::setDefaultAction(string $name)
 */
 PHP_METHOD(yaf_dispatcher, setDefaultAction) {
-	zval *action;
-	zval *self = getThis();
+    zend_string *action = NULL;
 
-	if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &action) == FAILURE) {
-		return;
-	}
+    if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &action) == FAILURE) {
+        return;
+    }
 
-	if (IS_STRING == Z_TYPE_P(action) && Z_STRLEN_P(action)) {
-		zval action_lower;
-		ZVAL_STRING(&action_lower, zend_str_tolower_dup(Z_STRVAL_P(action), Z_STRLEN_P(action)));
-		zend_update_property(yaf_dispatcher_ce, self, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_ACTION), &action_lower);
-		zval_ptr_dtor(&action_lower);
+    zval *self = getThis();
+    zend_string *lc_name = zend_string_tolower(action);
 
-		RETURN_ZVAL(self, 1, 0);
-	}
+    zend_update_property_str(yaf_dispatcher_ce, self, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_ACTION), lc_name);
+    zend_string_release(lc_name);
 
-	RETURN_FALSE;
+    RETURN_ZVAL(self, 1, 0);
 }
 /* }}} */
 
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Dec 04 14:01:23 2020 UTC