diff --git a/configs/ini.c b/configs/ini.c index 9416ce34..de06bccf 100644 --- a/configs/ini.c +++ b/configs/ini.c @@ -14,12 +14,16 @@ +----------------------------------------------------------------------+ */ -/* $Id: ini.c 315757 2011-08-30 08:08:40Z laruence $ */ +/* $Id: ini.c 324896 2012-04-06 09:46:37Z laruence $ */ zend_class_entry *yaf_config_ini_ce; yaf_config_t * yaf_config_ini_instance(yaf_config_t *this_ptr, zval *filename, zval *section TSRMLS_DC); +#define YAF_CONFIG_INI_PARSING_START 0 +#define YAF_CONFIG_INI_PARSING_PROCESS 1 +#define YAF_CONFIG_INI_PARSING_END 2 + /** {{{ ARG_INFO */ ZEND_BEGIN_ARG_INFO_EX(yaf_config_ini_construct_arginfo, 0, 0, 1) @@ -49,41 +53,28 @@ ZEND_BEGIN_ARG_INFO_EX(yaf_config_ini_isset_arginfo, 0, 0, 1) ZEND_END_ARG_INFO() /* }}} */ -/** {{{ static unsigned int numerics[256] -*/ -static unsigned int numerics[256] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, - 4, 5, 6, 7, 8, 9, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; -/* }}} */ - -/** {{{ static int yaf_config_is_numeric(char *str TSRMLS_DC) -*/ -static inline int yaf_config_ini_is_numeric(char *str TSRMLS_DC) { - int i,j; - int ret = 0; - - for(i=0, j=strlen(str); i 2)) +/** {{{ static void yaf_config_ini_simple_parser_cb(zval *key, zval *value, zval *index, int callback_type, zval *arr TSRMLS_DC) +*/ +static void yaf_config_ini_simple_parser_cb(zval *key, zval *value, zval *index, int callback_type, zval *arr TSRMLS_DC) { + zval *element; + switch (callback_type) { + case ZEND_INI_PARSER_ENTRY: + { + char *skey, *seg, *ptr; + zval **ppzval, *dst; + + if (!value) { + break; + } - if (!found) { - char * record_name = emalloc(name_len + 1); + dst = arr; + skey = estrndup(Z_STRVAL_P(key), Z_STRLEN_P(key)); + if ((seg = php_strtok_r(skey, ".", &ptr))) { + do { + char *real_key = seg; + seg = php_strtok_r(NULL, ".", &ptr); + if (zend_symtable_find(Z_ARRVAL_P(dst), real_key, strlen(real_key) + 1, (void **) &ppzval) == FAILURE) { + if (seg) { + zval *tmp; + MAKE_STD_ZVAL(tmp); + array_init(tmp); + zend_symtable_update(Z_ARRVAL_P(dst), + real_key, strlen(real_key) + 1, (void **)&tmp, sizeof(zval *), (void **)&ppzval); + } else { + MAKE_STD_ZVAL(element); + ZVAL_ZVAL(element, value, 1, 0); + zend_symtable_update(Z_ARRVAL_P(dst), + real_key, strlen(real_key) + 1, (void **)&element, sizeof(zval *), NULL); + break; + } + } else { + if (IS_ARRAY != Z_TYPE_PP(ppzval)) { + if (seg) { + zval *tmp; + MAKE_STD_ZVAL(tmp); + array_init(tmp); + zend_symtable_update(Z_ARRVAL_P(dst), + real_key, strlen(real_key) + 1, (void **)&tmp, sizeof(zval *), (void **)&ppzval); + } else { + MAKE_STD_ZVAL(element); + ZVAL_ZVAL(element, value, 1, 0); + zend_symtable_update(Z_ARRVAL_P(dst), + real_key, strlen(real_key) + 1, (void **)&element, sizeof(zval *), NULL); + } + } + } + dst = *ppzval; + } while (seg); + } + efree(skey); + } + break; - memcpy(record_name, name, name_len - 1); - record_name[name_len - 1] = '.'; - record_name[name_len] = '\0'; + case ZEND_INI_PARSER_POP_ENTRY: + { + zval *hash, **find_hash, *dst; - MAKE_STD_ZVAL(ret); - array_init(ret); - for(zend_hash_internal_pointer_reset(ht); - zend_hash_has_more_elements(ht) == SUCCESS; - zend_hash_move_forward(ht)) { - if (zend_hash_get_current_key_ex(ht, &key, &keylen, &idx, 0, NULL) != HASH_KEY_IS_STRING) { - continue; + if (!value) { + break; } - if (strncasecmp(key, record_name, name_len)) { - continue; - } else { - zval *son = NULL; - int real_key_len, long_key; - char *real_key = strstr(key + name_len + 1, "."); - - zend_hash_get_pointer(ht, &position); - if (real_key == NULL) { - son = yaf_config_ini_parse_entry(ht, key, name_len - 1, keylen, 0 TSRMLS_CC); - real_key = estrdup(key + name_len); - real_key_len = strlen(real_key) + 1; - } else { - son = yaf_config_ini_parse_entry(ht, key, name_len - 1 , real_key - key + 1, 0 TSRMLS_CC); - real_key_len = real_key - (key + name_len) + 1; - real_key = estrdup(key + name_len); - *(real_key + real_key_len - 1) = '\0'; - } - if (!son) { - efree(real_key); - continue; + if (!(Z_STRLEN_P(key) > 1 && Z_STRVAL_P(key)[0] == '0') + && is_numeric_string(Z_STRVAL_P(key), Z_STRLEN_P(key), NULL, NULL, 0) == IS_LONG) { + ulong skey = (ulong)zend_atol(Z_STRVAL_P(key), Z_STRLEN_P(key)); + if (zend_hash_index_find(Z_ARRVAL_P(arr), skey, (void **) &find_hash) == FAILURE) { + MAKE_STD_ZVAL(hash); + array_init(hash); + zend_hash_index_update(Z_ARRVAL_P(arr), skey, &hash, sizeof(zval *), NULL); + } else { + hash = *find_hash; } - - zend_hash_set_pointer(ht, &position); - if((long_key = yaf_config_ini_is_numeric(real_key TSRMLS_CC)) >= 0) { - zend_hash_index_update(Z_ARRVAL_P(ret), long_key, (void **)&son, sizeof(zval *), NULL); + } else { + char *seg, *ptr; + char *skey = estrndup(Z_STRVAL_P(key), Z_STRLEN_P(key)); + + dst = arr; + if ((seg = php_strtok_r(skey, ".", &ptr))) { + while (seg) { + if (zend_symtable_find(Z_ARRVAL_P(dst), seg, strlen(seg) + 1, (void **) &find_hash) == FAILURE) { + MAKE_STD_ZVAL(hash); + array_init(hash); + zend_symtable_update(Z_ARRVAL_P(dst), + seg, strlen(seg) + 1, (void **)&hash, sizeof(zval *), (void **)&find_hash); + } + dst = *find_hash; + seg = php_strtok_r(NULL, ".", &ptr); + } + hash = dst; } else { - zend_hash_update(Z_ARRVAL_P(ret), real_key, real_key_len , (void **)&son, sizeof(zval *), NULL); + if (zend_symtable_find(Z_ARRVAL_P(dst), seg, strlen(seg) + 1, (void **)&find_hash) == FAILURE) { + MAKE_STD_ZVAL(hash); + array_init(hash); + zend_symtable_update(Z_ARRVAL_P(dst), seg, strlen(seg) + 1, (void **)&hash, sizeof(zval *), NULL); + } else { + hash = *find_hash; + } } - efree(real_key); + efree(skey); } - } - efree(record_name); - } - } - return ret; -} -/* }}} */ + if (Z_TYPE_P(hash) != IS_ARRAY) { + zval_dtor(hash); + INIT_PZVAL(hash); + array_init(hash); + } -/** {{{ static HashTable * yaf_config_ini_parse_record(HashTable * ht TSRMLS_DC) - * parse string to array - */ -static HashTable * yaf_config_ini_parse_record(HashTable *ht TSRMLS_DC) { - char *key, *real_key; - uint keylen; - long idx; - zval *tmp, *dummy; - HashTable *ret; - - ALLOC_HASHTABLE(ret); - zend_hash_init(ret, 64, NULL, ZVAL_PTR_DTOR, 0); - - MAKE_STD_ZVAL(dummy); - ZVAL_NULL(dummy); - for(zend_hash_internal_pointer_reset(ht); - zend_hash_has_more_elements(ht) == SUCCESS; - zend_hash_move_forward(ht)) { - switch (zend_hash_get_current_key_ex(ht, &key, &keylen, &idx, 0, NULL)) { - case HASH_KEY_IS_STRING: - if ((real_key = strstr(key, "."))) { - keylen = real_key - key; - real_key = estrndup(key, keylen); - if (zend_hash_exists(ret, real_key, keylen + 1)) { - efree(real_key); - continue; - } + MAKE_STD_ZVAL(element); + ZVAL_ZVAL(element, value, 1, 0); - Z_ADDREF_P(dummy); - zend_hash_update(ret, real_key, keylen + 1, (void **)&dummy, sizeof(zval *), NULL); - efree(real_key); + if (index && Z_STRLEN_P(index) > 0) { + add_assoc_zval_ex(hash, Z_STRVAL_P(index), Z_STRLEN_P(index) + 1, element); } else { - if (zend_hash_exists(ret, key, keylen)) { - continue; - } - Z_ADDREF_P(dummy); - zend_hash_update(ret, key, keylen, (void **)&dummy, sizeof(zval *), NULL); + add_next_index_zval(hash, element); } + } break; - case HASH_KEY_IS_LONG: - Z_ADDREF_P(dummy); - zend_hash_index_update(ret, idx, (void **)&dummy, sizeof(zval *), NULL); + + case ZEND_INI_PARSER_SECTION: break; - default: - continue; - } - } - zval_ptr_dtor(&dummy); - - for(zend_hash_internal_pointer_reset(ret); - zend_hash_has_more_elements(ret) == SUCCESS; - zend_hash_move_forward(ret)) { - switch (zend_hash_get_current_key_ex(ret, &key, &keylen, &idx, 0, NULL)) { - case HASH_KEY_IS_STRING: - if ((tmp = yaf_config_ini_parse_entry(ht, key, 0, keylen, 0 TSRMLS_CC))) { - zend_hash_update(ret, key, keylen , (void **)&tmp, sizeof(zval *), NULL); - } - break; - case HASH_KEY_IS_LONG: - if ((tmp = yaf_config_ini_parse_entry(ht, NULL, 0, 0, idx TSRMLS_CC))) { - zend_hash_index_update(ret, idx, (void **)&tmp, sizeof(zval *), NULL); - } - break; - default: - continue; - } } - - return ret; } /* }}} */ -/** {{{static zval * yaf_config_ini_parse_section(HashTable *ht, char *name, int len, long index TSRMLS_DC) +/** {{{ static void yaf_config_ini_parser_cb(zval *key, zval *value, zval *index, int callback_type, zval *arr TSRMLS_DC) */ -static zval * yaf_config_ini_parse_section(HashTable *ht, char *name, int len, long index TSRMLS_DC) { - zval *parent, **ppzval; - char *key, *buf; - long idx; - uint keylen; - HashPointer position; - zval *section; - - MAKE_STD_ZVAL(section); - array_init(section); - - if (name) { - for(zend_hash_internal_pointer_reset(ht); - zend_hash_has_more_elements(ht) == SUCCESS; - zend_hash_move_forward(ht)) { - - if (zend_hash_get_current_key_ex(ht, &key, &keylen, &idx, 0, NULL) != HASH_KEY_IS_STRING) { - continue; +static void yaf_config_ini_parser_cb(zval *key, zval *value, zval *index, int callback_type, zval *arr TSRMLS_DC) { + + if (YAF_G(parsing_flag) == YAF_CONFIG_INI_PARSING_END) { + return; + } + + if (callback_type == ZEND_INI_PARSER_SECTION) { + zval **parent; + char *seg, *skey; + uint skey_len; + + if (YAF_G(parsing_flag) == YAF_CONFIG_INI_PARSING_PROCESS) { + YAF_G(parsing_flag) = YAF_CONFIG_INI_PARSING_END; + return; + } + + skey = estrndup(Z_STRVAL_P(key), Z_STRLEN_P(key)); + + MAKE_STD_ZVAL(YAF_G(active_ini_file_section)); + array_init(YAF_G(active_ini_file_section)); + + if ((seg = strchr(skey, ':'))) { + char *section; + + while (*(seg) == ' ' || *(seg) == ':') { + *(seg++) = '\0'; } - if (strncasecmp(key, name, len)) { - continue; + if ((section = strrchr(seg, ':'))) { + /* muilt-inherit */ + do { + while (*(section) == ' ' || *(section) == ':') { + *(section++) = '\0'; + } + if (zend_symtable_find(Z_ARRVAL_P(arr), section, strlen(section) + 1, (void **)&parent) == SUCCESS) { + zend_hash_copy(Z_ARRVAL_P(YAF_G(active_ini_file_section)), Z_ARRVAL_PP(parent), + (copy_ctor_func_t)yaf_config_ini_zval_deep_copy, NULL, sizeof(zval *)); + } + } while ((section = strrchr(seg, ':'))); } - if (zend_hash_get_current_data(ht, (void**)&ppzval) == FAILURE) { - continue; + /* remove the tail space, thinking of 'foo : bar : test' */ + section = seg + strlen(seg) - 1; + while (*section == ' ' || *section == ':') { + *(section--) = '\0'; } - if (Z_TYPE_PP(ppzval) != IS_ARRAY) { - continue; + if (zend_symtable_find(Z_ARRVAL_P(arr), seg, strlen(seg) + 1, (void **)&parent) == SUCCESS) { + zend_hash_copy(Z_ARRVAL_P(YAF_G(active_ini_file_section)), Z_ARRVAL_PP(parent), + (copy_ctor_func_t)yaf_config_ini_zval_deep_copy, NULL, sizeof(zval *)); } + } + seg = skey + strlen(skey) - 1; + while (*seg == ' ' || *seg == ':') { + *(seg--) = '\0'; + } + skey_len = strlen(skey); + zend_symtable_update(Z_ARRVAL_P(arr), skey, skey_len + 1, &YAF_G(active_ini_file_section), sizeof(zval *), NULL); + if (YAF_G(ini_wanted_section) && Z_STRLEN_P(YAF_G(ini_wanted_section)) == skey_len + && !strncasecmp(Z_STRVAL_P(YAF_G(ini_wanted_section)), skey, skey_len)) { + YAF_G(parsing_flag) = YAF_CONFIG_INI_PARSING_PROCESS; + } + efree(skey); + } else if (value) { + zval *active_arr; + if (YAF_G(active_ini_file_section)) { + active_arr = YAF_G(active_ini_file_section); + } else { + active_arr = arr; + } + yaf_config_ini_simple_parser_cb(key, value, index, callback_type, active_arr TSRMLS_CC); + } +} +/* }}} */ +#else +/** {{{ static void yaf_config_ini_simple_parser_cb(zval *key, zval *value, int callback_type, zval *arr) +*/ +static void yaf_config_ini_simple_parser_cb(zval *key, zval *value, int callback_type, zval *arr) { + zval *element; + switch (callback_type) { + case ZEND_INI_PARSER_ENTRY: + { + char *skey, *seg, *ptr; + zval **ppzval, *dst; + + if (!value) { + break; + } - zend_hash_merge(Z_ARRVAL_P(section), Z_ARRVAL_PP(ppzval), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *), 0); + dst = arr; + skey = estrndup(Z_STRVAL_P(key), Z_STRLEN_P(key)); + if ((seg = php_strtok_r(skey, ".", &ptr))) { + do { + char *real_key = seg; + seg = php_strtok_r(NULL, ".", &ptr); + if (zend_symtable_find(Z_ARRVAL_P(dst), real_key, strlen(real_key) + 1, (void **) &ppzval) == FAILURE) { + if (seg) { + zval *tmp; + MAKE_STD_ZVAL(tmp); + array_init(tmp); + zend_symtable_update(Z_ARRVAL_P(dst), + real_key, strlen(real_key) + 1, (void **)&tmp, sizeof(zval *), (void **)&ppzval); + } else { + MAKE_STD_ZVAL(element); + ZVAL_ZVAL(element, value, 1, 0); + zend_symtable_update(Z_ARRVAL_P(dst), + real_key, strlen(real_key) + 1, (void **)&element, sizeof(zval *), NULL); + break; + } + } else { + if (IS_ARRAY != Z_TYPE_PP(ppzval)) { + if (seg) { + zval *tmp; + MAKE_STD_ZVAL(tmp); + array_init(tmp); + zend_symtable_update(Z_ARRVAL_P(dst), + real_key, strlen(real_key) + 1, (void **)&tmp, sizeof(zval *), (void **)&ppzval); + } else { + MAKE_STD_ZVAL(element); + ZVAL_ZVAL(element, value, 1, 0); + zend_symtable_update(Z_ARRVAL_P(dst), + real_key, strlen(real_key) + 1, (void **)&element, sizeof(zval *), NULL); + } + } + } + dst = *ppzval; + } while (seg); + } + efree(skey); + } + break; - if ((buf = strstr(key, ":"))) { - char *parent_section, *tmp; - uint parent_len; - while((++buf)[0] == ' '); + case ZEND_INI_PARSER_POP_ENTRY: + { + zval *hash, **find_hash, *dst; - parent_section = buf; + if (!value) { + break; + } - if ((tmp = strstr(parent_section, ":"))) { - parent_len = tmp - parent_section; + if (!(Z_STRLEN_P(key) > 1 && Z_STRVAL_P(key)[0] == '0') + && is_numeric_string(Z_STRVAL_P(key), Z_STRLEN_P(key), NULL, NULL, 0) == IS_LONG) { + ulong skey = (ulong)zend_atol(Z_STRVAL_P(key), Z_STRLEN_P(key)); + if (zend_hash_index_find(Z_ARRVAL_P(arr), skey, (void **) &find_hash) == FAILURE) { + MAKE_STD_ZVAL(hash); + array_init(hash); + zend_hash_index_update(Z_ARRVAL_P(arr), skey, &hash, sizeof(zval *), NULL); + } else { + hash = *find_hash; + } } else { - parent_len = strlen(parent_section); + char *seg, *ptr; + char *skey = estrndup(Z_STRVAL_P(key), Z_STRLEN_P(key)); + + dst = arr; + if ((seg = php_strtok_r(skey, ".", &ptr))) { + while (seg) { + if (zend_symtable_find(Z_ARRVAL_P(dst), seg, strlen(seg) + 1, (void **) &find_hash) == FAILURE) { + MAKE_STD_ZVAL(hash); + array_init(hash); + zend_symtable_update(Z_ARRVAL_P(dst), + seg, strlen(seg) + 1, (void **)&hash, sizeof(zval *), (void **)&find_hash); + } + dst = *find_hash; + seg = php_strtok_r(NULL, ".", &ptr); + } + hash = dst; + } else { + if (zend_symtable_find(Z_ARRVAL_P(dst), seg, strlen(seg) + 1, (void **)&find_hash) == FAILURE) { + MAKE_STD_ZVAL(hash); + array_init(hash); + zend_symtable_update(Z_ARRVAL_P(dst), seg, strlen(seg) + 1, (void **)&hash, sizeof(zval *), NULL); + } else { + hash = *find_hash; + } + } + efree(skey); } - /* in case of nesting like "section : section" */ - if (strncasecmp(buf, name, len)) { - zend_hash_get_pointer(ht, &position); - parent = yaf_config_ini_parse_section(ht, parent_section, parent_len, 0 TSRMLS_CC); - zend_hash_set_pointer(ht, &position); - zend_hash_merge(Z_ARRVAL_P(parent), Z_ARRVAL_P(section), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *), 1); - zval_ptr_dtor(§ion); - section = parent; - parent = NULL; + if (Z_TYPE_P(hash) != IS_ARRAY) { + zval_dtor(hash); + INIT_PZVAL(hash); + array_init(hash); } - } + MAKE_STD_ZVAL(element); + ZVAL_ZVAL(element, value, 1, 0); + add_next_index_zval(hash, element); + } + break; + + case ZEND_INI_PARSER_SECTION: break; + } +} +/* }}} */ + +/** {{{ static void yaf_config_ini_parser_cb(zval *key, zval *value, int callback_type, zval *arr) +*/ +static void yaf_config_ini_parser_cb(zval *key, zval *value, int callback_type, zval *arr) { + TSRMLS_FETCH(); + + if (YAF_G(parsing_flag) == YAF_CONFIG_INI_PARSING_END) { + return; + } + + if (callback_type == ZEND_INI_PARSER_SECTION) { + zval **parent; + char *seg, *skey; + uint skey_len; + + if (YAF_G(parsing_flag) == YAF_CONFIG_INI_PARSING_PROCESS) { + YAF_G(parsing_flag) = YAF_CONFIG_INI_PARSING_END; + return; } - } else { - /* HASH_KEY_IS_LONG */ - for(zend_hash_internal_pointer_reset(ht); - zend_hash_has_more_elements(ht) == SUCCESS; - zend_hash_move_forward(ht)) { - if (zend_hash_get_current_key_ex(ht, &key, &keylen, &idx, 0, NULL) != HASH_KEY_IS_LONG) { - continue; - } + skey = estrndup(Z_STRVAL_P(key), Z_STRLEN_P(key)); - if (idx != index) { - continue; + MAKE_STD_ZVAL(YAF_G(active_ini_file_section)); + array_init(YAF_G(active_ini_file_section)); + + if ((seg = strchr(skey, ':'))) { + char *section; + + while (*(seg) == ' ' || *(seg) == ':') { + *(seg++) = '\0'; } - if (zend_hash_get_current_data(ht, (void**)&ppzval) == FAILURE) { - continue; + if ((section = strrchr(seg, ':'))) { + /* muilt-inherit */ + do { + while (*(section) == ' ' || *(section) == ':') { + *(section++) = '\0'; + } + if (zend_symtable_find(Z_ARRVAL_P(arr), section, strlen(section) + 1, (void **)&parent) == SUCCESS) { + zend_hash_copy(Z_ARRVAL_P(YAF_G(active_ini_file_section)), Z_ARRVAL_PP(parent), + (copy_ctor_func_t)yaf_config_ini_zval_deep_copy, NULL, sizeof(zval *)); + } + } while ((section = strrchr(seg, ':'))); } - if (Z_TYPE_PP(ppzval) != IS_ARRAY) { - continue; + /* remove the tail space, thinking of 'foo : bar : test' */ + section = seg + strlen(seg) - 1; + while (*section == ' ' || *section == ':') { + *(section--) = '\0'; } - zend_hash_merge(Z_ARRVAL_P(section), Z_ARRVAL_PP(ppzval), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *), 0); + if (zend_symtable_find(Z_ARRVAL_P(arr), seg, strlen(seg) + 1, (void **)&parent) == SUCCESS) { + zend_hash_copy(Z_ARRVAL_P(YAF_G(active_ini_file_section)), Z_ARRVAL_PP(parent), + (copy_ctor_func_t)yaf_config_ini_zval_deep_copy, NULL, sizeof(zval *)); + } } + seg = skey + strlen(skey) - 1; + while (*seg == ' ' || *seg == ':') { + *(seg--) = '\0'; + } + skey_len = strlen(skey); + zend_symtable_update(Z_ARRVAL_P(arr), skey, skey_len + 1, &YAF_G(active_ini_file_section), sizeof(zval *), NULL); + if (YAF_G(ini_wanted_section) && Z_STRLEN_P(YAF_G(ini_wanted_section)) == skey_len + && !strncasecmp(Z_STRVAL_P(YAF_G(ini_wanted_section)), skey, Z_STRLEN_P(YAF_G(ini_wanted_section)))) { + YAF_G(parsing_flag) = YAF_CONFIG_INI_PARSING_PROCESS; + } + efree(skey); + } else if (value) { + zval *active_arr; + if (YAF_G(active_ini_file_section)) { + active_arr = YAF_G(active_ini_file_section); + } else { + active_arr = arr; + } + yaf_config_ini_simple_parser_cb(key, value, callback_type, active_arr); } - - return section; } /* }}} */ +#endif /** {{{ yaf_config_t * yaf_config_ini_instance(yaf_config_t *this_ptr, zval *filename, zval *section_name TSRMLS_DC) */ yaf_config_t * yaf_config_ini_instance(yaf_config_t *this_ptr, zval *filename, zval *section_name TSRMLS_DC) { yaf_config_t *instance; - zval *configs; + zval *configs = NULL; if (filename && Z_TYPE_P(filename) == IS_ARRAY) { if (this_ptr) { @@ -385,131 +512,67 @@ yaf_config_t * yaf_config_ini_instance(yaf_config_t *this_ptr, zval *filename, z return instance; } else if (filename && Z_TYPE_P(filename) == IS_STRING) { - zval *ini_entries, *process_section; - zval function = {{0}, 0}; /* missing braces around initializer */ - zval *params[2] = {0}; - - MAKE_STD_ZVAL(process_section); - ZVAL_TRUE(process_section); - - params[0] = filename; - params[1] = process_section; - - ZVAL_STRING(&function, "parse_ini_file", 0); - - MAKE_STD_ZVAL(ini_entries); - ZVAL_FALSE(ini_entries); - /* since config need section parsing - * so it's difficult to call zend_parse_ini_file directly - */ - if (call_user_function(EG(function_table), NULL, &function, ini_entries, 2, params TSRMLS_CC) == FAILURE) { - efree(process_section); - if (ini_entries) { - zval_ptr_dtor(&ini_entries); - } - yaf_trigger_error(E_ERROR TSRMLS_CC, "Call to parse_ini_file failed"); - return NULL; - } - efree(process_section); + struct stat sb; + zend_file_handle fh = {0}; + char *ini_file = Z_STRVAL_P(filename); + + MAKE_STD_ZVAL(configs); + ZVAL_NULL(configs); + + if (VCWD_STAT(ini_file, &sb) == 0) { + if (S_ISREG(sb.st_mode)) { + if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) { + fh.filename = ini_file; + fh.type = ZEND_HANDLE_FP; + YAF_G(active_ini_file_section) = NULL; + + YAF_G(parsing_flag) = YAF_CONFIG_INI_PARSING_START; + if (section_name && Z_STRLEN_P(section_name)) { + YAF_G(ini_wanted_section) = section_name; + } else { + YAF_G(ini_wanted_section) = NULL; + } - if (Z_TYPE_P(ini_entries) != IS_ARRAY) { - zval_ptr_dtor(&ini_entries); - yaf_trigger_error(E_ERROR TSRMLS_CC, "Unable to find config file %s or it is not in INI file format", Z_STRVAL_P(filename)); + array_init(configs); +#if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION > 2)) + if (zend_parse_ini_file(&fh, 0, 0 /* ZEND_INI_SCANNER_NORMAL */, + (zend_ini_parser_cb_t)yaf_config_ini_parser_cb, configs TSRMLS_CC) == FAILURE + || Z_TYPE_P(configs) != IS_ARRAY) +#else + if (zend_parse_ini_file(&fh, 0, (zend_ini_parser_cb_t)yaf_config_ini_parser_cb, configs) == FAILURE + || Z_TYPE_P(configs) != IS_ARRAY) +#endif + { + zval_dtor(configs); + efree(configs); + yaf_trigger_error(E_ERROR TSRMLS_CC, "Parsing ini file '%s' failed", ini_file); + return NULL; + } + } + } + } else { + efree(configs); + yaf_trigger_error(E_ERROR TSRMLS_CC, "Unable to find config file '%s'", ini_file); return NULL; } if (section_name && Z_STRLEN_P(section_name)) { - HashTable *garbage; - configs = yaf_config_ini_parse_section(Z_ARRVAL_P(ini_entries), Z_STRVAL_P(section_name), Z_STRLEN_P(section_name), 0 TSRMLS_CC); - if (!configs) { - zval_ptr_dtor(&ini_entries); - yaf_trigger_error(E_ERROR TSRMLS_CC, "There is no section %s in %s", Z_STRVAL_P(section_name), Z_STRVAL_P(filename)); + zval **section; + zval tmp; + if (zend_symtable_find(Z_ARRVAL_P(configs), + Z_STRVAL_P(section_name), Z_STRLEN_P(section_name) + 1, (void **)§ion) == FAILURE) { + zval_dtor(configs); + efree(configs); + yaf_trigger_error(E_ERROR TSRMLS_CC, "There is no section '%s' in '%s'", Z_STRVAL_P(section_name), ini_file); return NULL; } - garbage = Z_ARRVAL_P(configs); - Z_ARRVAL_P(configs) = yaf_config_ini_parse_record(Z_ARRVAL_P(configs) TSRMLS_CC); - zend_hash_destroy(garbage); - efree(garbage); - } else { - uint len, section = 0; - long idx; - char *key, *tmp, *ex; - zval *sec, **ppzv; - HashTable *ht; - HashPointer pot = {0}; - - ex = ":"; - MAKE_STD_ZVAL(configs); - array_init(configs); - - ht = Z_ARRVAL_P(ini_entries); - for(zend_hash_internal_pointer_reset(ht); - zend_hash_has_more_elements(ht) == SUCCESS; - zend_hash_move_forward(ht)) { - switch (zend_hash_get_current_key_ex(ht, &key, &len, &idx, 0, NULL)) { - case HASH_KEY_IS_STRING: - if ((tmp = strstr(key, ex))) { - while(strlen(tmp) && (*(tmp - 1) == ' ' || *(tmp - 1) == ' ')) tmp--; - len = tmp - key; - } else { - len -= 1; - } - - if (zend_hash_get_current_data(ht, (void **)&ppzv) == FAILURE) { - continue; - } - if (Z_TYPE_PP(ppzv) == IS_ARRAY) { - section = 1; - zend_hash_get_pointer(ht, &pot); - sec = yaf_config_ini_parse_section(ht, key, len, 0 TSRMLS_CC); - zend_hash_set_pointer(ht, &pot); - if (sec) { - HashTable *garbage = Z_ARRVAL_P(sec); - Z_ARRVAL_P(sec) = yaf_config_ini_parse_record(Z_ARRVAL_P(sec) TSRMLS_CC); - zend_hash_destroy(garbage); - efree(garbage); - - if (tmp) { - key = estrndup(key, len); - zend_hash_update(Z_ARRVAL_P(configs), key, len + 1, (void **)&sec, sizeof(zval *), NULL); - efree(key); - } else { - zend_hash_update(Z_ARRVAL_P(configs), key, len + 1, (void **)&sec, sizeof(zval *), NULL); - } - } - } - break; - case HASH_KEY_IS_LONG: - if (zend_hash_get_current_data(ht, (void **)&ppzv) == FAILURE) { - continue; - } - if (Z_TYPE_PP(ppzv) == IS_ARRAY) { - section = 1; - zend_hash_get_pointer(ht, &pot); - sec = yaf_config_ini_parse_section(ht, NULL, 0, idx TSRMLS_CC); - zend_hash_set_pointer(ht, &pot); - if (sec) { - HashTable *garbage = Z_ARRVAL_P(sec); - Z_ARRVAL_P(sec) = yaf_config_ini_parse_record(Z_ARRVAL_P(sec) TSRMLS_CC); - zend_hash_destroy(garbage); - efree(garbage); - zend_hash_index_update(Z_ARRVAL_P(configs), idx, (void **)&sec, sizeof(zval *), NULL); - } - } - break; - default: - continue; - } - - } - - if (!section) { - zend_hash_copy(Z_ARRVAL_P(configs), ht, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); - Z_ARRVAL_P(configs) = yaf_config_ini_parse_record(Z_ARRVAL_P(configs) TSRMLS_CC); - } - } + INIT_PZVAL(&tmp); + array_init(&tmp); + zend_hash_copy(Z_ARRVAL(tmp), Z_ARRVAL_PP(section), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); + zval_dtor(configs); - zval_ptr_dtor(&ini_entries); + *configs = tmp; + } if (this_ptr) { instance = this_ptr; @@ -518,24 +581,18 @@ yaf_config_t * yaf_config_ini_instance(yaf_config_t *this_ptr, zval *filename, z object_init_ex(instance, yaf_config_ini_ce); } - if (!configs) { - MAKE_STD_ZVAL(configs); - array_init(configs); - zend_update_property(yaf_config_ini_ce, instance, ZEND_STRL(YAF_CONFIG_PROPERT_NAME), configs TSRMLS_CC); - } else { - zend_update_property(yaf_config_ini_ce, instance, ZEND_STRL(YAF_CONFIG_PROPERT_NAME), configs TSRMLS_CC); - } + zend_update_property(yaf_config_ini_ce, instance, ZEND_STRL(YAF_CONFIG_PROPERT_NAME), configs TSRMLS_CC); zval_ptr_dtor(&configs); return instance; } else { yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Invalid parameters provided, must be path of ini file"); - return NULL; + return NULL; } } /* }}} */ -/** {{{ proto public Yaf_Config_Ini::__construct(mixed $config_path, string $section_name) +/** {{{ proto public Yaf_Config_Ini::__construct(mixed $config_path, string $section_name) */ PHP_METHOD(yaf_config_ini, __construct) { zval *filename, *section = NULL; @@ -593,7 +650,7 @@ PHP_METHOD(yaf_config_ini, get) { RETURN_NULL(); } } - + efree(entry); if (Z_TYPE_PP(ppzval) == IS_ARRAY) { @@ -635,7 +692,7 @@ PHP_METHOD(yaf_config_ini, __isset) { return; } else { zval *prop = zend_read_property(yaf_config_ini_ce, getThis(), ZEND_STRL(YAF_CONFIG_PROPERT_NAME), 1 TSRMLS_CC); - RETURN_BOOL(zend_hash_exists(Z_ARRVAL_P(prop), name, len + 1)); + RETURN_BOOL(zend_hash_exists(Z_ARRVAL_P(prop), name, len + 1)); } } /* }}} */ @@ -648,7 +705,7 @@ PHP_METHOD(yaf_config_ini, count) { } /* }}} */ -/** {{{ proto public Yaf_Config_Ini::offsetUnset($index) +/** {{{ proto public Yaf_Config_Ini::offsetUnset($index) */ PHP_METHOD(yaf_config_ini, offsetUnset) { RETURN_FALSE; diff --git a/configs/simple.c b/configs/simple.c index bb6f867f..a50aab57 100644 --- a/configs/simple.c +++ b/configs/simple.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: simple.c 315957 2011-09-01 09:03:32Z laruence $ */ + +/* $Id: simple.c 324504 2012-03-24 02:48:04Z laruence $ */ zend_class_entry *yaf_config_simple_ce; @@ -53,7 +53,7 @@ yaf_config_t * yaf_config_simple_instance(yaf_config_t *this_ptr, zval *values, yaf_config_t *instance; switch (Z_TYPE_P(values)) { - case IS_ARRAY: + case IS_ARRAY: if (this_ptr) { instance = this_ptr; } else { @@ -69,7 +69,7 @@ yaf_config_t * yaf_config_simple_instance(yaf_config_t *this_ptr, zval *values, break; default: yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Invalid parameters provided, must be an array"); - return NULL; + return NULL; } } /* }}} */ @@ -84,7 +84,7 @@ zval * yaf_config_simple_format(yaf_config_t *instance, zval **ppzval TSRMLS_DC) } /* }}} */ -/** {{{ proto public Yaf_Config_Simple::__construct(mixed $array, string $readonly) +/** {{{ proto public Yaf_Config_Simple::__construct(mixed $array, string $readonly) */ PHP_METHOD(yaf_config_simple, __construct) { zval *values, *readonly = NULL; @@ -127,7 +127,7 @@ PHP_METHOD(yaf_config_simple, get) { if (zend_hash_find(hash, name, len + 1, (void **) &ppzval) == FAILURE) { RETURN_FALSE; } - + if (Z_TYPE_PP(ppzval) == IS_ARRAY) { if ((ret = yaf_config_simple_format(getThis(), ppzval TSRMLS_CC))) { RETURN_ZVAL(ret, 1, 1); @@ -166,7 +166,7 @@ PHP_METHOD(yaf_config_simple, set) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expect a string key name"); RETURN_FALSE; } - + Z_ADDREF_P(value); props = zend_read_property(yaf_config_simple_ce, getThis(), ZEND_STRL(YAF_CONFIG_PROPERT_NAME), 1 TSRMLS_CC); if (zend_hash_update(Z_ARRVAL_P(props), Z_STRVAL_P(name), Z_STRLEN_P(name) + 1, (void **)&value, sizeof(zval*), NULL) == SUCCESS) { @@ -189,17 +189,17 @@ PHP_METHOD(yaf_config_simple, __isset) { return; } else { zval *prop = zend_read_property(yaf_config_simple_ce, getThis(), ZEND_STRL(YAF_CONFIG_PROPERT_NAME), 1 TSRMLS_CC); - RETURN_BOOL(zend_hash_exists(Z_ARRVAL_P(prop), name, len + 1)); + RETURN_BOOL(zend_hash_exists(Z_ARRVAL_P(prop), name, len + 1)); } } /* }}} */ -/** {{{ proto public Yaf_Config_Simple::offsetUnset($index) +/** {{{ proto public Yaf_Config_Simple::offsetUnset($index) */ PHP_METHOD(yaf_config_simple, offsetUnset) { zval *readonly = zend_read_property(yaf_config_simple_ce, getThis(), ZEND_STRL(YAF_CONFIG_PROPERT_NAME_READONLY), 1 TSRMLS_CC); - if (Z_BVAL_P(readonly)) { + if (!Z_BVAL_P(readonly)) { zval *name, *props; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &name) == FAILURE) { return; @@ -209,9 +209,9 @@ PHP_METHOD(yaf_config_simple, offsetUnset) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expect a string key name"); RETURN_FALSE; } - + props = zend_read_property(yaf_config_simple_ce, getThis(), ZEND_STRL(YAF_CONFIG_PROPERT_NAME), 1 TSRMLS_CC); - if (zend_hash_del(Z_ARRVAL_P(props), Z_STRVAL_P(name), Z_STRLEN_P(name)) == SUCCESS) { + if (zend_hash_del(Z_ARRVAL_P(props), Z_STRVAL_P(name), Z_STRLEN_P(name) + 1) == SUCCESS) { RETURN_TRUE; } } diff --git a/package2.xml b/package2.xml index a0ea3f7f..2ec8cfd7 100644 --- a/package2.xml +++ b/package2.xml @@ -10,11 +10,11 @@ laruence@php.net yes - 2011-10-08 - + 2012-04-01 + - 2.1.3 - 2.1.3 + 2.1.10 + 2.1.10 beta @@ -22,7 +22,13 @@ PHP --Fixed Bug that Yaf still call to Yaf_View_Simple although a custom view engine was setted + - Improved Yaf_Config_Ini::__Construct performance, and reduce memory consumption + - Fixed bug #61493 (Can't remove item when using unset() with a Yaf_Config_Simple instance) + - Support controller autoloading(Only default module) + - Fixed bug that the controller name could be lowercase in routeShutdown hook + - Fixed bug that segfault while attempt to free owrite_handler + - Added Yaf_Controller::$yafAutoRender to controller render + - Fixed some memory leaks @@ -108,6 +114,23 @@ + + + + + + + + + + + + + + + + + @@ -126,6 +149,119 @@ yaf + + 2012-04-01 + + 2.1.10 + 2.1.10 + + + beta + beta + + PHP License + + - Fixed bug #61493 (Can't remove item when using unset() with a Yaf_Config_Simple instance) + - Support controller autoloading(Only default module) + - Fixed bug that the controller name could be lowercase in routeShutdown hook + - Fixed bug that segfault while attempt to free owrite_handler + - Added Yaf_Controller::$yafAutoRender to controller render + - Fixed some memory leaks + + + + + 2012-03-20 + + 2.1.9 + 2.1.9 + + + stable + stable + + PHP License + + - Fixed Bug that Yaf_Response::setBody cause invalid read + + + + 2012-03-12 + + 2.1.8 + 2.1.8 + + + stable + stable + + PHP License + + - Fixed bug Yaf_Response::setBody act the same as Yaf_Response::prependBody + + + + 2012-02-05 + + 2.1.7 + 2.1.7 + + + stable + stable + + PHP License + + - Release 2.1.7 stable + + + + + 2012-01-06 + + 2.1.6 + 2.1.6 + + + beta + beta + + PHP License + + - Fix Bug that classname with namespace can not be auto loaded + + + + 2011-12-26 + + 2.1.5 + 2.1.5 + + + beta + beta + + PHP License + + - Fix Bug #60608 + + + + 2011-12-21 + + 2.1.4 + 2.1.4 + + + beta + beta + + PHP License + + - Improve the Yaf_Loader::getInstance, make the Yaf_Loader can be used independently + - Implemented Yaf_View::assignRef, which didn't work as expect before. + + 2011-10-08 @@ -138,10 +274,9 @@ PHP License --Fixed Bug that Yaf still call to Yaf_View_Simple although a custom view engine was setted + - Fixed Bug that Yaf still call to Yaf_View_Simple although a custom view engine was setted - 2011-09-01 @@ -154,13 +289,12 @@ PHP License --Added Yaf_Application::getLastErrorNo --Added Yaf_Application::getLastErrorMsg --Added Yaf_Application::clearLastError --Changed trigger ERROR to E_RECOVERABLE_ERROR, then people can use set_error_handler to catch it + - Added Yaf_Application::getLastErrorNo + - Added Yaf_Application::getLastErrorMsg + - Added Yaf_Application::clearLastError + - Changed trigger ERROR to E_RECOVERABLE_ERROR, then people can use set_error_handler to catch it - 2011-08-31 @@ -173,8 +307,8 @@ PHP License --Fixed Yaf_View_Simple::render flush output instantly in PHP5.4 --Fixed Yaf_Session crash in PHP5.4 + - Fixed Yaf_View_Simple::render flush output instantly in PHP5.4 + - Fixed Yaf_Session crash in PHP5.4 @@ -189,12 +323,12 @@ PHP License -- Avoided calling to get_class_entry for higher performance -- Added arginfo for all methods -- Remove unnecessary stack variable initialization -- Standardize error message -- Add Yaf_Request::setRequstUri -- Fixed build broken with PHP 5.4 + - Avoided calling to get_class_entry for higher performance + - Added arginfo for all methods + - Remove unnecessary stack variable initialization + - Standardize error message + - Add Yaf_Request::setRequstUri + - Fixed build broken with PHP 5.4 @@ -209,10 +343,10 @@ PHP License -- Fixed Bug that when call to Yaf_Config_Ini/Yaf_Config_Simple with freaky paramters then invoke its methods cause crash (thanks to Felipe Pena) -- Yaf_Application::execute call Zend_API call_user_func instead of call zif_call_user_func, since zif_call_user_func was not declared with dllexport -- Built on windows with PHP-5.3.6 and PHP-5.2.15 (you can download the dll on Yaf Google Code) -- Corrected some broken C89 statements + - Fixed Bug that when call to Yaf_Config_Ini/Yaf_Config_Simple with freaky paramters then invoke its methods cause crash (thanks to Felipe Pena) + - Yaf_Application::execute call Zend_API call_user_func instead of call zif_call_user_func, since zif_call_user_func was not declared with dllexport + - Built on windows with PHP-5.3.6 and PHP-5.2.15 (you can download the dll on Yaf Google Code) + - Corrected some broken C89 statements diff --git a/php_yaf.h b/php_yaf.h index 165be94b..11b25442 100644 --- a/php_yaf.h +++ b/php_yaf.h @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: php_yaf.h 317890 2011-10-08 13:31:56Z laruence $ */ + +/* $Id: php_yaf.h 324890 2012-04-06 05:46:43Z laruence $ */ #ifndef PHP_YAF_H #define PHP_YAF_H @@ -26,7 +26,7 @@ extern zend_module_entry yaf_module_entry; #define PHP_YAF_API __declspec(dllexport) #ifndef _MSC_VER #define _MSC_VER 1600 -#endif +#endif #else #define PHP_YAF_API #endif @@ -41,7 +41,7 @@ extern zend_module_entry yaf_module_entry; #define YAF_G(v) (yaf_globals.v) #endif -#define YAF_VERSION "2.1.3" +#define YAF_VERSION "2.1.11-dev" #define YAF_STARTUP_FUNCTION(module) ZEND_MINIT_FUNCTION(yaf_##module) #define YAF_RINIT_FUNCTION(modle) ZEND_RINIT_FUNCTION(yaf_##module) @@ -50,7 +50,7 @@ extern zend_module_entry yaf_module_entry; #define YAF_SHUTDOWN(module) ZEND_MODULE_SHUTDOWN_N(yaf_##module)(INIT_FUNC_ARGS_PASSTHRU) #if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION > 2)) || (PHP_MAJOR_VERSION > 5) -#define YAF_HAVE_NAMESPACE +#define YAF_HAVE_NAMESPACE #else #define Z_ADDREF_P ZVAL_ADDREF #define Z_REFCOUNT_P ZVAL_REFCOUNT @@ -82,7 +82,8 @@ ZEND_BEGIN_MODULE_GLOBALS(yaf) char *base_uri; char *environ; char *directory; - char *library_directory; + char *local_library; + char *local_namespace; char *global_library; char *view_ext; char *default_module; @@ -106,11 +107,15 @@ ZEND_BEGIN_MODULE_GLOBALS(yaf) long forward_limit; HashTable *configs; zval *modules; + zval *default_route; #if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4)) uint buf_nesting; void *buffer; void *owrite_handler; #endif + zval *active_ini_file_section; + zval *ini_wanted_section; + uint parsing_flag; #ifdef YAF_HAVE_NAMESPACE zend_bool use_namespace; #endif diff --git a/requests/http.c b/requests/http.c index bd508bb1..e6fb1935 100644 --- a/requests/http.c +++ b/requests/http.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: http.c 315715 2011-08-29 16:08:35Z laruence $ */ + +/* $Id: http.c 321289 2011-12-21 02:53:29Z laruence $ */ #include "ext/standard/url.h" @@ -56,7 +56,7 @@ yaf_request_t * yaf_request_http_instance(yaf_request_t *this_ptr, char *request if (Z_TYPE_P(uri) != IS_NULL) { settled_uri = uri; break; - } + } zval_ptr_dtor(&uri); /* IIS7 with URL Rewrite: make sure we get the unencoded url (double slash problem) */ @@ -64,7 +64,7 @@ yaf_request_t * yaf_request_http_instance(yaf_request_t *this_ptr, char *request if (Z_TYPE_P(uri) != IS_NULL) { zval *rewrited = yaf_request_query(YAF_GLOBAL_VARS_SERVER, ZEND_STRL("IIS_WasUrlRewritten") TSRMLS_CC); zval *unencode = yaf_request_query(YAF_GLOBAL_VARS_SERVER, ZEND_STRL("UNENCODED_URL") TSRMLS_CC); - if (Z_TYPE_P(rewrited) = IS_LONG + if (Z_TYPE_P(rewrited) = IS_LONG && Z_LVAL_P(rewrited) == 1 && Z_TYPE_P(unencode) == IS_STRING && Z_STRLEN_P(unencode) > 0) { @@ -73,7 +73,7 @@ yaf_request_t * yaf_request_http_instance(yaf_request_t *this_ptr, char *request break; } zval_ptr_dtor(&uri); -#endif +#endif uri = yaf_request_query(YAF_GLOBAL_VARS_SERVER, ZEND_STRL("PATH_INFO") TSRMLS_CC); if (Z_TYPE_P(uri) != IS_NULL) { settled_uri = uri; @@ -105,7 +105,7 @@ yaf_request_t * yaf_request_http_instance(yaf_request_t *this_ptr, char *request } } break; - } + } zval_ptr_dtor(&uri); uri = yaf_request_query(YAF_GLOBAL_VARS_SERVER, ZEND_STRL("ORIG_PATH_INFO") TSRMLS_CC); @@ -163,7 +163,7 @@ YAF_REQUEST_METHOD(yaf_request_http, Files, YAF_GLOBAL_VARS_FILES); YAF_REQUEST_METHOD(yaf_request_http, Cookie, YAF_GLOBAL_VARS_COOKIE); /* }}} */ -/** {{{ proto public Yaf_Request_Http::isXmlHttpRequest() +/** {{{ proto public Yaf_Request_Http::isXmlHttpRequest() */ PHP_METHOD(yaf_request_http, isXmlHttpRequest) { zval * header = yaf_request_query(YAF_GLOBAL_VARS_SERVER, ZEND_STRL("HTTP_X_REQUESTED_WITH") TSRMLS_CC); diff --git a/requests/simple.c b/requests/simple.c index cc029cc3..39021aae 100644 --- a/requests/simple.c +++ b/requests/simple.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: simple.c 315715 2011-08-29 16:08:35Z laruence $ */ + +/* $Id: simple.c 321289 2011-12-21 02:53:29Z laruence $ */ static zend_class_entry *yaf_request_simple_ce; @@ -57,7 +57,7 @@ yaf_request_t * yaf_request_simple_instance(yaf_request_t *this_ptr, zval *modul zend_update_property_string(yaf_request_simple_ce, instance, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_CONTROLLER), YAF_G(default_controller) TSRMLS_CC); } else { - zend_update_property(yaf_request_simple_ce, instance, + zend_update_property(yaf_request_simple_ce, instance, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_CONTROLLER), controller TSRMLS_CC); } @@ -129,7 +129,7 @@ PHP_METHOD(yaf_request_simple, __construct) { return; } else { if ((params && IS_ARRAY != Z_TYPE_P(params))) { - yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, + yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Expects the params is an array", yaf_request_simple_ce->name); RETURN_FALSE; } @@ -164,7 +164,7 @@ YAF_REQUEST_METHOD(yaf_request_simple, Files, YAF_GLOBAL_VARS_FILES); YAF_REQUEST_METHOD(yaf_request_simple, Cookie, YAF_GLOBAL_VARS_COOKIE); /* }}} */ -/** {{{ proto public Yaf_Request_Simple::isXmlHttpRequest() +/** {{{ proto public Yaf_Request_Simple::isXmlHttpRequest() */ PHP_METHOD(yaf_request_simple, isXmlHttpRequest) { zval * header = yaf_request_query(YAF_GLOBAL_VARS_SERVER, ZEND_STRL("X-Requested-With") TSRMLS_CC); diff --git a/response/cli.c b/response/cli.c index ae4aaf4b..849618b5 100644 --- a/response/cli.c +++ b/response/cli.c @@ -13,13 +13,13 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: cli.c 315615 2011-08-27 14:14:48Z laruence $ */ + +/* $Id: cli.c 321289 2011-12-21 02:53:29Z laruence $ */ zend_class_entry * yaf_response_cli_ce; -/** {{{ yaf_response_methods +/** {{{ yaf_response_methods */ zend_function_entry yaf_response_cli_methods[] = { {NULL, NULL, NULL} diff --git a/response/http.c b/response/http.c index 31c5f648..e63f15e9 100644 --- a/response/http.c +++ b/response/http.c @@ -14,11 +14,11 @@ +----------------------------------------------------------------------+ */ -/* $Id: http.c 315957 2011-09-01 09:03:32Z laruence $ */ +/* $Id: http.c 321289 2011-12-21 02:53:29Z laruence $ */ zend_class_entry *yaf_response_http_ce; -/** {{{ yaf_response_methods +/** {{{ yaf_response_methods */ zend_function_entry yaf_response_http_methods[] = { {NULL, NULL, NULL} diff --git a/routes/interface.c b/routes/interface.c index ad3491b5..3ec64a72 100644 --- a/routes/interface.c +++ b/routes/interface.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: interface.c 315759 2011-08-30 08:40:50Z laruence $ */ + +/* $Id: interface.c 324890 2012-04-06 05:46:43Z laruence $ */ #include "ext/standard/php_smart_str.h" @@ -41,8 +41,8 @@ zend_class_entry *yaf_route_ce; #include "rewrite.c" #include "regex.c" #include "map.c" - -/* {{{ yaf_route_t * yaf_route_instance(yaf_route_t *this_ptr, zval *config TSRMLS_DC) + +/* {{{ yaf_route_t * yaf_route_instance(yaf_route_t *this_ptr, zval *config TSRMLS_DC) */ yaf_route_t * yaf_route_instance(yaf_route_t *this_ptr, zval *config TSRMLS_DC) { zval **match, **def, **map, **ppzval; @@ -57,54 +57,79 @@ yaf_route_t * yaf_route_instance(yaf_route_t *this_ptr, zval *config TSRMLS_DC) return NULL; } - if (strncasecmp(Z_STRVAL_PP(ppzval), "rewrite", sizeof("rewrite") - 1) == 0) { + if (Z_STRLEN_PP(ppzval) == (sizeof("rewrite") - 1) + && strncasecmp(Z_STRVAL_PP(ppzval), "rewrite", sizeof("rewrite") - 1) == 0) { if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("match"), (void **)&match) == FAILURE || Z_TYPE_PP(match) != IS_STRING) { return NULL; - } + } if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("route"), (void **)&def) == FAILURE || Z_TYPE_PP(def) != IS_ARRAY) { return NULL; - } + } - instance = yaf_route_rewrite_instance(NULL, *match, *def, NULL TSRMLS_CC); - } else if (strncasecmp(Z_STRVAL_PP(ppzval), "regex", sizeof("regex") - 1) == 0) { + instance = yaf_route_rewrite_instance(NULL, *match, *def, NULL TSRMLS_CC); + } else if (Z_STRLEN_PP(ppzval) == ("regex", sizeof("regex") - 1) + && strncasecmp(Z_STRVAL_PP(ppzval), "regex", sizeof("regex") - 1) == 0) { if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("match"), (void **)&match) == FAILURE || Z_TYPE_PP(match) != IS_STRING) { return NULL; - } + } if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("route"), (void **)&def) == FAILURE || Z_TYPE_PP(def) != IS_ARRAY) { return NULL; - } + } if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("map"), (void **)&map) == FAILURE || Z_TYPE_PP(map) != IS_ARRAY) { return NULL; } - instance = yaf_route_regex_instance(NULL, *match, *def, *map, NULL TSRMLS_CC); - } else if (strncasecmp(Z_STRVAL_PP(ppzval), "simple", sizeof("simple") - 1) == 0) { + instance = yaf_route_regex_instance(NULL, *match, *def, *map, NULL TSRMLS_CC); + } else if (Z_STRLEN_PP(ppzval) == (sizeof("map") - 1) + && strncasecmp(Z_STRVAL_PP(ppzval), "map", sizeof("map") - 1) == 0) { + char *delimiter = NULL; + uint delim_len = 0; + zend_bool controller_prefer = 0; + + if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("controllerPrefer"), (void **)&ppzval) == SUCCESS) { + zval *tmp = *ppzval; + Z_ADDREF_P(tmp); + convert_to_boolean_ex(&tmp); + controller_prefer = Z_BVAL_P(tmp); + zval_ptr_dtor(&tmp); + } + + if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("delimiter"), (void **)&ppzval) == SUCCESS + && Z_TYPE_PP(ppzval) == IS_STRING) { + delimiter = Z_STRVAL_PP(ppzval); + delim_len = Z_STRLEN_PP(ppzval); + } + + instance = yaf_route_map_instance(NULL, controller_prefer, delimiter, delim_len TSRMLS_CC); + } else if (Z_STRLEN_PP(ppzval) == (sizeof("simple") - 1) + && strncasecmp(Z_STRVAL_PP(ppzval), "simple", sizeof("simple") - 1) == 0) { if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("module"), (void **)&match) == FAILURE || Z_TYPE_PP(match) != IS_STRING) { return NULL; - } + } if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("controller"), (void **)&def) == FAILURE || Z_TYPE_PP(def) != IS_STRING) { return NULL; - } + } if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("action"), (void **)&map) == FAILURE || Z_TYPE_PP(map) != IS_STRING) { return NULL; - } + } - instance = yaf_route_simple_instance(NULL, *match, *def, *map TSRMLS_CC); - } else if (strncasecmp(Z_STRVAL_PP(ppzval), "supervar", sizeof("supervar") - 1) == 0) { + instance = yaf_route_simple_instance(NULL, *match, *def, *map TSRMLS_CC); + } else if (Z_STRLEN_PP(ppzval) == (sizeof("supervar") - 1) + && strncasecmp(Z_STRVAL_PP(ppzval), "supervar", sizeof("supervar") - 1) == 0) { if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("varname"), (void **)&match) == FAILURE || Z_TYPE_PP(match) != IS_STRING) { return NULL; - } + } + + instance = yaf_route_supervar_instance(NULL, *match TSRMLS_CC); + } - instance = yaf_route_supervar_instance(NULL, *match TSRMLS_CC); - } - return instance; } /* }}} */ diff --git a/routes/map.c b/routes/map.c index c888d72b..aaf54301 100644 --- a/routes/map.c +++ b/routes/map.c @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: map.c 315957 2011-09-01 09:03:32Z laruence $*/ +/* $Id: map.c 324890 2012-04-06 05:46:43Z laruence $*/ zend_class_entry *yaf_route_map_ce; @@ -29,6 +29,32 @@ ZEND_BEGIN_ARG_INFO_EX(yaf_route_map_construct_arginfo, 0, 0, 0) ZEND_END_ARG_INFO() /* }}} */ +/* {{{ yaf_route_t * yaf_route_map_instance(yaf_route_t *this_ptr, zend_bool controller_prefer, char *delim, uint len TSRMLS_DC) + */ +yaf_route_t * yaf_route_map_instance(yaf_route_t *this_ptr, zend_bool controller_prefer, char *delim, uint len TSRMLS_DC) { + yaf_route_t *instance; + + if (this_ptr) { + instance = this_ptr; + } else { + MAKE_STD_ZVAL(instance); + object_init_ex(instance, yaf_route_map_ce); + } + + if (controller_prefer) { + zend_update_property_bool(yaf_route_map_ce, instance, + ZEND_STRL(YAF_ROUTE_MAP_VAR_NAME_CTL_PREFER), 1 TSRMLS_CC); + } + + if (delim && len) { + zend_update_property_stringl(yaf_route_map_ce, instance, + ZEND_STRL(YAF_ROUTE_MAP_VAR_NAME_DELIMETER), delim, len TSRMLS_CC); + } + + return instance; +} +/* }}} */ + /** {{{ int yaf_route_map_route(yaf_route_t *route, yaf_request_t *request TSRMLS_DC) */ int yaf_route_map_route(yaf_route_t *route, yaf_request_t *request TSRMLS_DC) { @@ -52,9 +78,9 @@ int yaf_route_map_route(yaf_route_t *route, yaf_request_t *request TSRMLS_DC) { req_uri = estrdup(Z_STRVAL_P(zuri)); } - if (Z_TYPE_P(delimer) == IS_STRING - && Z_STRLEN_P(delimer)) { - if ((query_str = strstr(req_uri, Z_STRVAL_P(delimer))) != NULL + if (Z_TYPE_P(delimer) == IS_STRING + && Z_STRLEN_P(delimer)) { + if ((query_str = strstr(req_uri, Z_STRVAL_P(delimer))) != NULL && *(query_str - 1) == '/') { tmp = req_uri; rest = query_str + Z_STRLEN_P(delimer); @@ -117,27 +143,19 @@ PHP_METHOD(yaf_route_map, route) { } /* }}} */ -/** {{{ proto public Yaf_Route_Simple::__construct(int $controller_prefer=0, string $delimer = '#!') +/** {{{ proto public Yaf_Route_Simple::__construct(bool $controller_prefer=FALSE, string $delimer = '#!') */ PHP_METHOD(yaf_route_map, __construct) { - long controller_prefer = 0; - char *delim = NULL; - uint delim_len = 0; + char *delim = NULL; + uint delim_len = 0; + zend_bool controller_prefer = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ls", + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bs", &controller_prefer, &delim, &delim_len) == FAILURE) { return; } - if (controller_prefer) { - zend_update_property_bool(yaf_route_map_ce, getThis(), - ZEND_STRL(YAF_ROUTE_MAP_VAR_NAME_CTL_PREFER), 1 TSRMLS_CC); - } - - if (delim && delim_len) { - zend_update_property_stringl(yaf_route_map_ce, getThis(), - ZEND_STRL(YAF_ROUTE_MAP_VAR_NAME_DELIMETER), delim, delim_len TSRMLS_CC); - } + (void)yaf_route_map_instance(getThis(), controller_prefer, delim, delim_len TSRMLS_CC); } /* }}} */ @@ -174,5 +192,5 @@ YAF_STARTUP_FUNCTION(route_map) { * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 + * vim<600: noet sw=4 ts=4 */ diff --git a/routes/regex.c b/routes/regex.c index 293576a9..83604845 100644 --- a/routes/regex.c +++ b/routes/regex.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: regex.c 315715 2011-08-29 16:08:35Z laruence $ */ + +/* $Id: regex.c 321289 2011-12-21 02:53:29Z laruence $ */ zend_class_entry *yaf_route_regex_ce; @@ -63,7 +63,7 @@ static zval * yaf_route_regex_match(yaf_route_t *route, char *uir, int len TSRML if (!len) { return NULL; } - + match = zend_read_property(yaf_route_regex_ce, route, ZEND_STRL(YAF_ROUTE_PROPETY_NAME_MATCH), 1 TSRMLS_CC); if ((pce_regexp = pcre_get_compiled_regex_cache(Z_STRVAL_P(match), Z_STRLEN_P(match) TSRMLS_CC)) == NULL) { @@ -74,7 +74,7 @@ static zval * yaf_route_regex_match(yaf_route_t *route, char *uir, int len TSRML MAKE_STD_ZVAL(matches); MAKE_STD_ZVAL(subparts); ZVAL_NULL(subparts); - + map = zend_read_property(yaf_route_regex_ce, route, ZEND_STRL(YAF_ROUTE_PROPETY_NAME_MAP), 1 TSRMLS_CC); php_pcre_match_impl(pce_regexp, uir, len, matches, subparts /* subpats */, @@ -172,7 +172,7 @@ int yaf_route_regex_route(yaf_route_t *router, yaf_request_t *request TSRMLS_DC) */ PHP_METHOD(yaf_route_regex, route) { yaf_route_t *route; - yaf_request_t *request; + yaf_request_t *request; route = getThis(); @@ -201,7 +201,7 @@ PHP_METHOD(yaf_route_regex, __construct) { yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Expects an array as third paramter", yaf_route_regex_ce->name); WRONG_PARAM_COUNT; } - + if (IS_STRING != Z_TYPE_P(match) || !Z_STRLEN_P(match)) { yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Expects a string as the first parameter", yaf_route_regex_ce->name); RETURN_FALSE; @@ -231,7 +231,7 @@ PHP_METHOD(yaf_route_regex, __construct) { RETURN_FALSE; } /** }}} */ - + /** {{{ yaf_route_regex_methods */ zend_function_entry yaf_route_regex_methods[] = { diff --git a/routes/rewrite.c b/routes/rewrite.c index d0d88691..1ac000c2 100644 --- a/routes/rewrite.c +++ b/routes/rewrite.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: rewrite.c 315715 2011-08-29 16:08:35Z laruence $ */ + +/* $Id: rewrite.c 321289 2011-12-21 02:53:29Z laruence $ */ zend_class_entry *yaf_route_rewrite_ce; @@ -64,10 +64,10 @@ static zval * yaf_route_rewrite_match(yaf_route_t *router, char *uir, int len TS if (!len) { return NULL; } - + match = zend_read_property(yaf_route_rewrite_ce, router, ZEND_STRL(YAF_ROUTE_PROPETY_NAME_MATCH), 1 TSRMLS_CC); pmatch = estrndup(Z_STRVAL_P(match), Z_STRLEN_P(match)); - + smart_str_appendc(&pattern, YAF_ROUTE_REGEX_DILIMITER); smart_str_appendc(&pattern, '^'); @@ -80,7 +80,7 @@ static zval * yaf_route_rewrite_match(yaf_route_t *router, char *uir, int len TS if(*(seg) == '*') { smart_str_appendl(&pattern, "(?P<__yaf_route_rest>.*)", sizeof("(?P<__yaf_route_rest>.*)") -1); break; - } + } if(*(seg) == ':') { smart_str_appendl(&pattern, "(?P<", sizeof("(?P<") -1 ); @@ -98,7 +98,7 @@ static zval * yaf_route_rewrite_match(yaf_route_t *router, char *uir, int len TS smart_str_appendc(&pattern, YAF_ROUTE_REGEX_DILIMITER); smart_str_appendc(&pattern, 'i'); smart_str_0(&pattern); - + if ((pce_regexp = pcre_get_compiled_regex_cache(pattern.c, pattern.len TSRMLS_CC)) == NULL) { smart_str_free(&pattern); return NULL; @@ -142,7 +142,7 @@ static zval * yaf_route_rewrite_match(yaf_route_t *router, char *uir, int len TS if (zend_hash_get_current_data(ht, (void**)&ppzval) == FAILURE) { continue; } - + if (!strncmp(key, "__yaf_route_rest", len)) { zval *args = yaf_router_parse_parameters(Z_STRVAL_PP(ppzval) TSRMLS_CC); if (args) { @@ -261,7 +261,7 @@ PHP_METHOD(yaf_route_rewrite, __construct) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "za|a", &match, &route, &verify) == FAILURE) { return; } - + if (IS_STRING != Z_TYPE_P(match) || !Z_STRLEN_P(match)) { yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Expects a string as the first parameter", yaf_route_rewrite_ce->name); RETURN_FALSE; @@ -286,7 +286,7 @@ PHP_METHOD(yaf_route_rewrite, __construct) { RETURN_FALSE; } /** }}} */ - + /** {{{ yaf_route_rewrite_methods */ zend_function_entry yaf_route_rewrite_methods[] = { diff --git a/routes/simple.c b/routes/simple.c index 21451a8f..584d8ee1 100644 --- a/routes/simple.c +++ b/routes/simple.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: simple.c 315957 2011-09-01 09:03:32Z laruence $ */ + +/* $Id: simple.c 321289 2011-12-21 02:53:29Z laruence $ */ zend_class_entry *yaf_route_simple_ce; @@ -145,5 +145,5 @@ YAF_STARTUP_FUNCTION(route_simple) { * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 + * vim<600: noet sw=4 ts=4 */ diff --git a/routes/static.c b/routes/static.c index c51ba7f0..8a4950dc 100644 --- a/routes/static.c +++ b/routes/static.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: static.c 315957 2011-09-01 09:03:32Z laruence $ */ + +/* $Id: static.c 321289 2011-12-21 02:53:29Z laruence $ */ zend_class_entry * yaf_route_static_ce; @@ -62,7 +62,7 @@ int yaf_route_static_route(yaf_route_t *route, yaf_request_t *request TSRMLS_DC) if (yaf_application_is_module_name(p, s-p TSRMLS_CC)) { module = estrndup(p, s - p); p = s + 1; - } + } } if ((s = strstr(p, "/")) != NULL) { @@ -78,7 +78,7 @@ int yaf_route_static_route(yaf_route_t *route, yaf_request_t *request TSRMLS_DC) if (*p != '\0') { rest = estrdup(p); } - + if (module == NULL && controller == NULL && action == NULL ) { @@ -96,7 +96,7 @@ int yaf_route_static_route(yaf_route_t *route, yaf_request_t *request TSRMLS_DC) if (YAF_G(action_prefer)) { action = controller; controller = NULL; - } + } } else if (controller == NULL && action == NULL && rest != NULL) { @@ -122,8 +122,8 @@ int yaf_route_static_route(yaf_route_t *route, yaf_request_t *request TSRMLS_DC) /* /module/controller/action */ action = rest; rest = NULL; - } - + } + } while (0); efree(req_uri); @@ -131,16 +131,16 @@ int yaf_route_static_route(yaf_route_t *route, yaf_request_t *request TSRMLS_DC) if (module != NULL) { zend_update_property_string(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_MODULE), module TSRMLS_CC); efree(module); - } + } if (controller != NULL) { zend_update_property_string(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_CONTROLLER), controller TSRMLS_CC); efree(controller); - } + } if (action != NULL) { zend_update_property_string(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_ACTION), action TSRMLS_CC); efree(action); - } + } if (rest) { params = yaf_router_parse_parameters(rest TSRMLS_CC); @@ -201,6 +201,6 @@ YAF_STARTUP_FUNCTION(route_static) { * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 + * vim<600: noet sw=4 ts=4 */ diff --git a/routes/supervar.c b/routes/supervar.c index 0786f5c8..428e049c 100644 --- a/routes/supervar.c +++ b/routes/supervar.c @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: supervar.c 315957 2011-09-01 09:03:32Z laruence $ */ +/* $Id: supervar.c 321289 2011-12-21 02:53:29Z laruence $ */ #define YAF_ROUTE_SUPERVAR_PROPETY_NAME_VAR "_var_name" @@ -34,7 +34,7 @@ int yaf_route_supervar_route(yaf_route_t *route, yaf_request_t *request TSRMLS_D char *req_uri, *module = NULL, *controller = NULL, *action = NULL, *rest = NULL; varname = zend_read_property(yaf_route_supervar_ce, route, ZEND_STRL(YAF_ROUTE_SUPERVAR_PROPETY_NAME_VAR), 1 TSRMLS_CC); - + zuir = yaf_request_query(YAF_GLOBAL_VARS_GET, Z_STRVAL_P(varname), Z_STRLEN_P(varname) TSRMLS_CC); if (!zuir || ZVAL_IS_NULL(zuir)) { @@ -63,7 +63,7 @@ int yaf_route_supervar_route(yaf_route_t *route, yaf_request_t *request TSRMLS_D if (yaf_application_is_module_name(p, s-p TSRMLS_CC)) { module = estrndup(p, s - p); p = s + 1; - } + } } if ((s = strstr(p, "/")) != NULL) { @@ -97,7 +97,7 @@ int yaf_route_supervar_route(yaf_route_t *route, yaf_request_t *request TSRMLS_D if (YAF_G(action_prefer)) { action = controller; controller = NULL; - } + } } else if (controller == NULL && action == NULL && rest != NULL) { @@ -123,7 +123,7 @@ int yaf_route_supervar_route(yaf_route_t *route, yaf_request_t *request TSRMLS_D /* /module/controller/action */ action = rest; rest = NULL; - } + } } while (0); @@ -132,15 +132,15 @@ int yaf_route_supervar_route(yaf_route_t *route, yaf_request_t *request TSRMLS_D if (module != NULL) { zend_update_property_string(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_MODULE), module TSRMLS_CC); efree(module); - } + } if (controller != NULL) { zend_update_property_string(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_CONTROLLER), controller TSRMLS_CC); efree(controller); - } + } if (action != NULL) { zend_update_property_string(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_ACTION), action TSRMLS_CC); efree(action); - } + } if (rest) { params = yaf_router_parse_parameters(rest TSRMLS_CC); @@ -184,7 +184,7 @@ PHP_METHOD(yaf_route_supervar, route) { return; } else { RETURN_BOOL(yaf_route_supervar_route(getThis(), request TSRMLS_CC)); - } + } } /** }}} */ @@ -196,7 +196,7 @@ PHP_METHOD(yaf_route_supervar, __construct) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &var) == FAILURE) { return; } - + if (Z_TYPE_P(var) != IS_STRING || !Z_STRLEN_P(var)) { yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Expects a string super var name", yaf_route_supervar_ce->name); RETURN_FALSE; @@ -205,7 +205,7 @@ PHP_METHOD(yaf_route_supervar, __construct) { zend_update_property(yaf_route_supervar_ce, getThis(), ZEND_STRL(YAF_ROUTE_SUPERVAR_PROPETY_NAME_VAR), var TSRMLS_CC); } /** }}} */ - + /** {{{ yaf_route_supervar_methods */ zend_function_entry yaf_route_supervar_methods[] = { diff --git a/tests/003.phpt b/tests/003.phpt index 02b53a6c..8b7262aa 100644 --- a/tests/003.phpt +++ b/tests/003.phpt @@ -2,6 +2,8 @@ Check for Yaf_Loader --SKIPIF-- +--INI-- +yaf.use_spl_autoload=0 --FILE-- Array ( - [directory] => APPLICATION_PATCH/applcation + [directory] => APPLICATION_PATH/applcation ) [name] => base @@ -84,7 +84,7 @@ Yaf_Config_Ini Object [rewrite] => Array ( [type] => rewrite - [match] => /ap/:name/:value + [match] => /yaf/:name/:value [route] => Array ( [controller] => Index @@ -101,7 +101,7 @@ Yaf_Config_Ini Object ( [application] => Array ( - [directory] => APPLICATION_PATCH/applcation + [directory] => APPLICATION_PATH/applcation ) [name] => extra @@ -151,7 +151,7 @@ Yaf_Config_Ini Object [rewrite] => Array ( [type] => rewrite - [match] => /ap/:name/:value + [match] => /yaf/:name/:value [route] => Array ( [controller] => Index @@ -169,7 +169,7 @@ Yaf_Config_Ini Object ( [application] => Array ( - [directory] => APPLICATION_PATCH/applcation + [directory] => APPLICATION_PATH/applcation ) [name] => extra @@ -219,7 +219,7 @@ Yaf_Config_Ini Object [rewrite] => Array ( [type] => rewrite - [match] => /ap/:name/:value + [match] => /yaf/:name/:value [route] => Array ( [controller] => Index @@ -237,7 +237,7 @@ Yaf_Config_Ini Object ( [application] => Array ( - [directory] => APPLICATION_PATCH/applcation + [directory] => APPLICATION_PATH/applcation [dispatcher] => Array ( [throwException] => @@ -293,7 +293,7 @@ Yaf_Config_Ini Object [rewrite] => Array ( [type] => rewrite - [match] => /ap/:name/:value + [match] => /yaf/:name/:age [route] => Array ( [controller] => Index @@ -307,6 +307,13 @@ Yaf_Config_Ini Object [value] => 2 ) + [envtest] => Array + ( + [env] => + [ini] => + [const] => FOO + ) + ) [_readonly:protected] => 1 @@ -317,7 +324,7 @@ Yaf_Config_Ini Object ( [application] => Array ( - [directory] => APPLICATION_PATCH/applcation + [directory] => APPLICATION_PATH/applcation ) [name] => extra @@ -367,7 +374,7 @@ Yaf_Config_Ini Object [rewrite] => Array ( [type] => rewrite - [match] => /ap/:name/:value + [match] => /yaf/:name/:value [route] => Array ( [controller] => Index @@ -384,6 +391,6 @@ Yaf_Config_Ini Object [_readonly:protected] => 1 ) bool(true) -baseextraproductnocatchbool(false) +baseextraproductnocatchenvtestbool(false) NULL int(0) diff --git a/tests/013.phpt b/tests/013.phpt index a34f9e4d..f8492094 100644 --- a/tests/013.phpt +++ b/tests/013.phpt @@ -57,7 +57,7 @@ Yaf_Config_Ini Object [rewrite] => Array ( [type] => rewrite - [match] => /ap/:name/:value + [match] => /yaf/:name/:value [route] => Array ( [controller] => Index @@ -109,7 +109,7 @@ Array [rewrite] => Yaf_Route_Rewrite Object ( - [_route:protected] => /ap/:name/:value + [_route:protected] => /yaf/:name/:value [_default:protected] => Array ( [controller] => Index diff --git a/tests/014.phpt b/tests/014.phpt index 3e24b9dc..a6cff2ba 100644 --- a/tests/014.phpt +++ b/tests/014.phpt @@ -19,7 +19,7 @@ Yaf_Application Object ( [application] => Array ( - [directory] => APPLICATION_PATCH/applcation + [directory] => %stests/applcation ) [name] => extra @@ -69,7 +69,7 @@ Yaf_Application Object [rewrite] => Array ( [type] => rewrite - [match] => /ap/:name/:value + [match] => /yaf/:name/:value [route] => Array ( [controller] => Index diff --git a/tests/018.phpt b/tests/018.phpt index 2895bc3e..4911e55b 100644 --- a/tests/018.phpt +++ b/tests/018.phpt @@ -15,7 +15,7 @@ Yaf_Config_Ini Object ( [application] => Array ( - [directory] => APPLICATION_PATCH/applcation + [directory] => APPLICATION_PATH/applcation ) [name] => base @@ -64,7 +64,7 @@ Yaf_Config_Ini Object [rewrite] => Array ( [type] => rewrite - [match] => /ap/:name/:value + [match] => /yaf/:name/:value [route] => Array ( [controller] => Index diff --git a/tests/022.phpt b/tests/022.phpt new file mode 100644 index 00000000..24239812 --- /dev/null +++ b/tests/022.phpt @@ -0,0 +1,28 @@ +--TEST-- +Check for Yaf_Application +--SKIPIF-- + +--INI-- +--FILE-- + array( + "directory" => realpath(dirname(__FILE__)), + "dispatcher" => array( + "catchException" => 0, + "throwException" => 0, + ), + ), +); + +$app = new Yaf_Application($config); +var_dump($app->getAppDirectory()); +$app->setAppDirectory('/tmp'); +var_dump($app->getAppDirectory()); +$app->run(); +?> +--EXPECTF-- +string(%d) "%stests" +string(4) "/tmp" + +Catchable fatal error: Yaf_Application::run(): Could not find controller script /tmp/controllers/Index.php in %s022.php on line %d diff --git a/tests/023.phpt b/tests/023.phpt new file mode 100644 index 00000000..612527fe --- /dev/null +++ b/tests/023.phpt @@ -0,0 +1,38 @@ +--TEST-- +Check for Yaf_Loader::set/get(library_path) +--SKIPIF-- + +--INI-- +yaf.use_spl_autoload=0 +--FILE-- +registerLocalNamespace(array("Foo")); + +$loader->autoload("Foo_Bar"); +$loader->autoload("Bar_Foo"); + +$loader->setLibraryPath("/foobar", FALSE); +$loader->autoload("Foo_Bar"); +$loader->autoload("Bar_Foo"); + +$loader->setLibraryPath("/foobar", TRUE); +$loader->autoload("Foo_Bar"); +$loader->autoload("Bar_Foo"); + +$loader->autoload("Bar_Model"); +?> +--EXPECTF-- +Warning: Yaf_Loader::autoload(): Could not find script /foo/Foo/Bar.php in %s023.php on line %d + +Warning: Yaf_Loader::autoload(): Could not find script /bar/Bar/Foo.php in %s023.php on line %d + +Warning: Yaf_Loader::autoload(): Could not find script /foobar/Foo/Bar.php in %s023.php on line %d + +Warning: Yaf_Loader::autoload(): Could not find script /bar/Bar/Foo.php in %s023.php on line %d + +Warning: Yaf_Loader::autoload(): Could not find script /foobar/Foo/Bar.php in %s023.php on line %d + +Warning: Yaf_Loader::autoload(): Could not find script /foobar/Bar/Foo.php in %s023.php on line %d + +Warning: Yaf_Loader::autoload(): Couldn't load a framework MVC class without an Yaf_Application initializing in %s023.php on line %d diff --git a/tests/024.phpt b/tests/024.phpt new file mode 100644 index 00000000..3510f064 --- /dev/null +++ b/tests/024.phpt @@ -0,0 +1,27 @@ +--TEST-- +Check for Yaf_Loader::getInstace() paramters +--SKIPIF-- + +--INI-- +yaf.library="/php/global/dir" +--FILE-- +getLibraryPath()); +var_dump($loader->getLibraryPath(TRUE)); +$config = array( + "application" => array( + "directory" => realpath(dirname(__FILE__)), + ), +); + +$app = new Yaf_Application($config); +var_dump($loader->getLibraryPath()); +var_dump($loader->getLibraryPath(TRUE)); +?> +--EXPECTF-- +string(4) "/foo" +string(4) "/bar" +string(%d) "%s/library" +string(15) "/php/global/dir" diff --git a/tests/025.phpt b/tests/025.phpt new file mode 100644 index 00000000..568c8a38 --- /dev/null +++ b/tests/025.phpt @@ -0,0 +1,32 @@ +--TEST-- +Check for Yaf_Loader with namespace configuration +--SKIPIF-- + +--INI-- +yaf.library="/php/global/dir" +--FILE-- + array( + "directory" => realpath(dirname(__FILE__)), + "library" => array( + "directory" => "/tmp", + "namespace" => "Foo, Bar", + ), + ), +); + +$app = new Yaf_Application($config); +Yaf_Loader::getInstance()->registerLocalNamespace("Dummy"); +print_r(Yaf_Loader::getInstance()); +var_dump(Yaf_Loader::getInstance()->isLocalName("Bar_Name")); + +?> +--EXPECTF-- +Yaf_Loader Object +( + [_local_ns:protected] => :Foo::Bar:Dummy: + [_library:protected] => /tmp + [_global_library:protected] => /php/global/dir +) +bool(true) diff --git a/tests/026.phpt b/tests/026.phpt new file mode 100644 index 00000000..cf410d12 --- /dev/null +++ b/tests/026.phpt @@ -0,0 +1,14 @@ +--TEST-- +Check for Yaf_Response::setBody/prependBody/appendBody +--SKIPIF-- + +--INI-- +yaf.library="/php/global/dir" +--FILE-- +setBody("ell")->appendBody("o")->prependBody("H"); +echo $response; +?> +--EXPECTF-- +Hello diff --git a/tests/027.phpt b/tests/027.phpt new file mode 100644 index 00000000..3efa1a9e --- /dev/null +++ b/tests/027.phpt @@ -0,0 +1,30 @@ +--TEST-- +Check for Yaf autoload controller +--SKIPIF-- + +--INI-- +yaf.use_spl_autoload=0 +yaf.library="/php/global/dir" +--FILE-- + array( + "directory" => realpath(dirname(__FILE__)), + "dispatcher" => array( + "catchException" => 0, + "throwException" => 0, + ), + ), + ); + +function main() { + $dummy = new NoExistsController(); +} + +$app = new Yaf_Application($config); +$app->execute("main"); +?> +--EXPECTF-- +Warning: Yaf_Loader::autoload(): Could not find script %s/controllers/NoExists.php in %s027.php on line %d + +Fatal error: Class 'NoExistsController' not found in %s027.php on line %d diff --git a/tests/028.phpt b/tests/028.phpt new file mode 100644 index 00000000..bb93a980 --- /dev/null +++ b/tests/028.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug segfault while call exit in a view template +--DESCRIPTION-- +Since PHP 5.4 change the output handler mechanism, this test will fail in 5.4 +--SKIPIF-- + +--INI-- +yaf.library="/php/global/dir" +--FILE-- +assign("name", "laruence"); +$tpl = dirname(__FILE__) . '/foo.phtml'; +function cleartpl() { + global $tpl; + @unlink($tpl); +} +register_shutdown_function("cleartpl"); + +file_put_contents($tpl, << +HTML +); +echo $view->render($tpl); +?> +--EXPECTF-- diff --git a/tests/029.phpt b/tests/029.phpt new file mode 100644 index 00000000..d996e377 --- /dev/null +++ b/tests/029.phpt @@ -0,0 +1,30 @@ +--TEST-- +Check for Yaf_View_Simple::get and clear +--SKIPIF-- + +--INI-- +yaf.library="/php/global/dir" +--FILE-- +assign("a", "b"); +$view->assign("b", "a"); +print_r($view->get("a")); +print_r($view->get()); +$view->clear("b"); +print_r($view->get()); +$view->clear(); +print_r($view->get()); +--EXPECTF-- +bArray +( + [a] => b + [b] => a +) +Array +( + [a] => b +) +Array +( +) diff --git a/tests/030.phpt b/tests/030.phpt new file mode 100644 index 00000000..dd56c9f0 --- /dev/null +++ b/tests/030.phpt @@ -0,0 +1,18 @@ +--TEST-- +Check for Yaf_Config_Ini::__construct with section +--SKIPIF-- + +--INI-- +yaf.library="/php/global/dir" +--FILE-- +getMessage()); +} + +--EXPECTF-- +There is no section 'ex' in '%ssimple.ini' diff --git a/tests/031.phpt b/tests/031.phpt new file mode 100644 index 00000000..1d1b4fb4 --- /dev/null +++ b/tests/031.phpt @@ -0,0 +1,34 @@ +--TEST-- +Check for application.dispatcher.defaultRoute +--SKIPIF-- + +--INI-- +yaf.library="/php/global/dir" +--FILE-- + array( + "directory" => realpath(dirname(__FILE__)), + "dispatcher" => array( + "defaultRoute" => array( + "type" => "map", + "delimiter" => '##', + "controllerPrefer" => 1, + ), + ), + ), +); + +$app = new Yaf_Application($config); +print_r($app->getDispatcher()->getRouter()->getRoutes()); +?> +--EXPECTF-- +Array +( + [_default] => Yaf_Route_Map Object + ( + [_ctl_router:protected] => 1 + [_delimeter:protected] => ## + ) + +) diff --git a/tests/032.phpt b/tests/032.phpt new file mode 100644 index 00000000..d25fa03f --- /dev/null +++ b/tests/032.phpt @@ -0,0 +1,25 @@ +--TEST-- +Check for Yaf_Config_Ini with env +--SKIPIF-- + +--INI-- +yaf.directory=/foo/bar +--FILE-- + +--EXPECTF-- +Yaf_Config_Ini Object +( + [_config:protected] => Array + ( + [env] => bar + [ini] => /foo/bar + [const] => Dummy + ) + + [_readonly:protected] => 1 +) diff --git a/tests/bug61493.phpt b/tests/bug61493.phpt new file mode 100644 index 00000000..ced9a028 --- /dev/null +++ b/tests/bug61493.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug #61493 (Can't remove item when using unset() with a Yaf_Config_Simple instance) +--CREDITS-- +littlemiaor at gmail dot com +--SKIPIF-- + +--FILE-- + 'bar', +), false); + +unset($config['foo']); +print_r($config); +?> +--EXPECTF-- +Yaf_Config_Simple Object +( + [_config:protected] => Array + ( + ) + + [_readonly:protected] => +) diff --git a/tests/simple.ini b/tests/simple.ini index 70f6701f..76590826 100644 --- a/tests/simple.ini +++ b/tests/simple.ini @@ -1,35 +1,42 @@ [base] -application.directory=APPLICATION_PATCH "/applcation" -name = base +application.directory=APPLICATION_PATH "/applcation" +name = "base" array.1 = 1 5=5 -array.name = name +array.name="name" routes.regex.type="regex" routes.regex.match="^/ap/(.*)" -routes.regex.route.controller=Index -routes.regex.route.action=action -routes.regex.map.0=name -routes.regex.map.1=name -routes.regex.map.2=value +routes.regex.route.controller="Index" +routes.regex.route.action="action" +routes.regex.map.0="name" +routes.regex.map.1="name" +routes.regex.map.2="value" routes.simple.type="simple" -routes.simple.controller=c -routes.simple.module=m -routes.simple.action=a +routes.simple.controller="c" +routes.simple.module="m" +routes.simple.action="a" routes.supervar.type="supervar" -routes.supervar.varname=c +routes.supervar.varname="c" routes.rewrite.type="rewrite" -routes.rewrite.match="/ap/:name/:value" -routes.rewrite.route.controller=Index -routes.rewrite.route.action=action +routes.rewrite.match="/yaf/:name/:value" +routes.rewrite.route.controller="Index" +routes.rewrite.route.action="action" -[extra : base] -value = 2 -name = extra -array.name = new_name -array.2 = test +[extra : base ] +value = "2" +name = "extra" +array.name = "new_name" +array.2 = "test" [product : extra] [nocatch : extra] application.dispatcher.throwException=Off application.dispatcher.catchException=yes +routes.rewrite.match="/yaf/:name/:age" + +[envtest] +env=${FOO} +ini=${yaf.directory} +const=FOO + diff --git a/views/interface.c b/views/interface.c index a79305e5..e4efa3ce 100644 --- a/views/interface.c +++ b/views/interface.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: interface.c 315638 2011-08-28 13:11:43Z laruence $ */ + +/* $Id: interface.c 321289 2011-12-21 02:53:29Z laruence $ */ zend_class_entry *yaf_view_interface_ce; @@ -43,7 +43,7 @@ ZEND_BEGIN_ARG_INFO_EX(yaf_view_getpath_arginfo, 0, 0, 0) ZEND_END_ARG_INFO() /* }}} */ -/** {{{ yaf_view_interface_methods +/** {{{ yaf_view_interface_methods */ zend_function_entry yaf_view_interface_methods[] = { ZEND_ABSTRACT_ME(yaf_view, assign, yaf_view_assign_arginfo) @@ -55,7 +55,7 @@ zend_function_entry yaf_view_interface_methods[] = { }; /* }}} */ -/** {{{ YAF_STARTUP_FUNCTION +/** {{{ YAF_STARTUP_FUNCTION */ YAF_STARTUP_FUNCTION(view_interface) { zend_class_entry ce; diff --git a/views/simple.c b/views/simple.c index 02d3e49b..54071795 100644 --- a/views/simple.c +++ b/views/simple.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: simple.c 315957 2011-09-01 09:03:32Z laruence $ */ + +/* $Id: simple.c 324844 2012-04-05 09:16:32Z laruence $ */ #include "main/php_output.h" @@ -78,7 +78,7 @@ ZEND_BEGIN_ARG_INFO_EX(yaf_view_simple_construct_arginfo, 0, 0, 1) ZEND_ARG_ARRAY_INFO(0, options, 1) ZEND_END_ARG_INFO(); -ZEND_BEGIN_ARG_INFO_EX(yaf_view_simple_get_arginfo, 0, 0, 1) +ZEND_BEGIN_ARG_INFO_EX(yaf_view_simple_get_arginfo, 0, 0, 0) ZEND_ARG_INFO(0, name) ZEND_END_ARG_INFO(); @@ -90,6 +90,10 @@ ZEND_BEGIN_ARG_INFO_EX(yaf_view_simple_assign_by_ref_arginfo, 0, 0, 2) ZEND_ARG_INFO(0, name) ZEND_ARG_INFO(1, value) ZEND_END_ARG_INFO(); + +ZEND_BEGIN_ARG_INFO_EX(yaf_view_simple_clear_arginfo, 0, 0, 0) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO(); /* }}} */ #if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4)) @@ -114,7 +118,7 @@ static int yaf_view_simple_render_write(const char *str, uint str_length TSRMLS_ php_error_docref(NULL TSRMLS_CC, E_ERROR, "Yaf output buffer collapsed"); } } - + target = buffer->buffer + buffer->len; buffer->len = len; } @@ -153,7 +157,7 @@ static int yaf_view_simple_valid_var_name(char *var_name, int len) /* {{{ */ (ch < 65 /* A */ || /* Z */ ch > 90) && (ch < 97 /* a */ || /* z */ ch > 122) && (ch < 127 /* 0x7f */ || /* 0xff */ ch > 255) - ) { + ) { return 0; } } @@ -162,7 +166,7 @@ static int yaf_view_simple_valid_var_name(char *var_name, int len) /* {{{ */ } /* }}} */ -/** {{{ static int yaf_view_simple_extract(zval *tpl_vars, zval *vars TSRMLS_DC) +/** {{{ static int yaf_view_simple_extract(zval *tpl_vars, zval *vars TSRMLS_DC) */ static int yaf_view_simple_extract(zval *tpl_vars, zval *vars TSRMLS_DC) { zval **entry; @@ -180,7 +184,7 @@ static int yaf_view_simple_extract(zval *tpl_vars, zval *vars TSRMLS_DC) { if (tpl_vars && Z_TYPE_P(tpl_vars) == IS_ARRAY) { for(zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(tpl_vars), &pos); - zend_hash_get_current_data_ex(Z_ARRVAL_P(tpl_vars), (void **)&entry, &pos) == SUCCESS; + zend_hash_get_current_data_ex(Z_ARRVAL_P(tpl_vars), (void **)&entry, &pos) == SUCCESS; zend_hash_move_forward_ex(Z_ARRVAL_P(tpl_vars), &pos)) { if (zend_hash_get_current_key_ex(Z_ARRVAL_P(tpl_vars), &var_name, &var_name_len, &num_key, 0, &pos) != HASH_KEY_IS_STRING) { continue; @@ -197,15 +201,15 @@ static int yaf_view_simple_extract(zval *tpl_vars, zval *vars TSRMLS_DC) { if (yaf_view_simple_valid_var_name(var_name, var_name_len - 1)) { - ZEND_SET_SYMBOL_WITH_LENGTH(EG(active_symbol_table), var_name, var_name_len, - *entry, Z_REFCOUNT_P(*entry) + 1, 0 /**PZVAL_IS_REF(*entry)*/); + ZEND_SET_SYMBOL_WITH_LENGTH(EG(active_symbol_table), var_name, var_name_len, + *entry, Z_REFCOUNT_P(*entry) + 1, PZVAL_IS_REF(*entry)); } } } if (vars && Z_TYPE_P(vars) == IS_ARRAY) { for(zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(vars), &pos); - zend_hash_get_current_data_ex(Z_ARRVAL_P(vars), (void **)&entry, &pos) == SUCCESS; + zend_hash_get_current_data_ex(Z_ARRVAL_P(vars), (void **)&entry, &pos) == SUCCESS; zend_hash_move_forward_ex(Z_ARRVAL_P(vars), &pos)) { if (zend_hash_get_current_key_ex(Z_ARRVAL_P(vars), &var_name, &var_name_len, &num_key, 0, &pos) != HASH_KEY_IS_STRING) { continue; @@ -221,7 +225,7 @@ static int yaf_view_simple_extract(zval *tpl_vars, zval *vars TSRMLS_DC) { } if (yaf_view_simple_valid_var_name(var_name, var_name_len - 1)) { - ZEND_SET_SYMBOL_WITH_LENGTH(EG(active_symbol_table), var_name, var_name_len, + ZEND_SET_SYMBOL_WITH_LENGTH(EG(active_symbol_table), var_name, var_name_len, *entry, Z_REFCOUNT_P(*entry) + 1, 0 /**PZVAL_IS_REF(*entry)*/); } } @@ -259,8 +263,8 @@ yaf_view_t * yaf_view_simple_instance(yaf_view_t *view, zval *tpl_dir, zval *opt */ int yaf_view_simple_render(yaf_view_t *view, zval *tpl, zval * vars, zval *ret TSRMLS_DC) { zval *tpl_vars; - char *script; - uint len; + char *script; + uint len; HashTable *calling_symbol_table; #if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4)) @@ -284,7 +288,7 @@ int yaf_view_simple_render(yaf_view_t *view, zval *tpl, zval * vars, zval *ret T #if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4)) YAF_REDIRECT_OUTPUT_BUFFER(buffer); -#else +#else if (php_output_start_user(NULL, 0, PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC) == FAILURE) { php_error_docref("ref.outcontrol" TSRMLS_CC, E_WARNING, "failed to create buffer"); return 0; @@ -326,7 +330,7 @@ int yaf_view_simple_render(yaf_view_t *view, zval *tpl, zval * vars, zval *ret T } yaf_trigger_error(YAF_ERR_NOTFOUND_VIEW TSRMLS_CC, - "Could not determine the view script path, you should call %s::setScriptPath to specific it", + "Could not determine the view script path, you should call %s::setScriptPath to specific it", yaf_view_simple_ce->name); return 0; } @@ -425,7 +429,7 @@ int yaf_view_simple_display(yaf_view_t *view, zval *tpl, zval *vars, zval *ret T zval *tpl_dir = zend_read_property(yaf_view_simple_ce, view, ZEND_STRL(YAF_VIEW_PROPERTY_NAME_TPLDIR), 1 TSRMLS_CC); if (ZVAL_IS_NULL(tpl_dir)) { - yaf_trigger_error(YAF_ERR_NOTFOUND_VIEW TSRMLS_CC, + yaf_trigger_error(YAF_ERR_NOTFOUND_VIEW TSRMLS_CC, "Could not determine the view script path, you should call %s::setScriptPath to specific it", yaf_view_simple_ce->name); EG(scope) = old_scope; if (calling_symbol_table) { @@ -462,7 +466,7 @@ int yaf_view_simple_display(yaf_view_t *view, zval *tpl, zval *vars, zval *ret T } /* }}} */ -/** {{{ proto public Yaf_View_Simple::__construct(string $tpl_dir, array $options = NULL) +/** {{{ proto public Yaf_View_Simple::__construct(string $tpl_dir, array $options = NULL) */ PHP_METHOD(yaf_view_simple, __construct) { zval *tpl_dir, *options = NULL; @@ -484,7 +488,7 @@ PHP_METHOD(yaf_view_simple, __isset) { return; } else { zval *tpl_vars = zend_read_property(yaf_view_simple_ce, getThis(), ZEND_STRL(YAF_VIEW_PROPERTY_NAME_TPLVARS), 1 TSRMLS_CC); - RETURN_BOOL(zend_hash_exists(Z_ARRVAL_P(tpl_vars), name, len + 1)); + RETURN_BOOL(zend_hash_exists(Z_ARRVAL_P(tpl_vars), name, len + 1)); } } /* }}} */ @@ -541,12 +545,12 @@ PHP_METHOD(yaf_view_simple, assign) { zval *value; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) == FAILURE) { return; - } + } if (Z_TYPE_P(value) == IS_ARRAY) { zend_hash_copy(Z_ARRVAL_P(tpl_vars), Z_ARRVAL_P(value), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); RETURN_TRUE; - } + } RETURN_FALSE; } else if (argc == 2) { zval *value; @@ -554,7 +558,7 @@ PHP_METHOD(yaf_view_simple, assign) { uint len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len, &value) == FAILURE) { return; - } + } Z_ADDREF_P(value); if (zend_hash_update(Z_ARRVAL_P(tpl_vars), name, len + 1, &value, sizeof(zval *), NULL) == SUCCESS) { @@ -575,14 +579,14 @@ PHP_METHOD(yaf_view_simple, assignRef) { zval * value, * tpl_vars; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len, &value) == FAILURE) { WRONG_PARAM_COUNT; - } + } tpl_vars = zend_read_property(yaf_view_simple_ce, getThis(), ZEND_STRL(YAF_VIEW_PROPERTY_NAME_TPLVARS), 1 TSRMLS_CC); Z_ADDREF_P(value); if (zend_hash_update(Z_ARRVAL_P(tpl_vars), name, len + 1, &value, sizeof(zval *), NULL) == SUCCESS) { RETURN_TRUE; - } + } RETURN_FALSE; } /* }}} */ @@ -591,20 +595,24 @@ PHP_METHOD(yaf_view_simple, assignRef) { */ PHP_METHOD(yaf_view_simple, get) { char *name; - uint len; + uint len = 0; zval *tpl_vars, **ret; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &len) == FAILURE) { return; - } + } tpl_vars = zend_read_property(yaf_view_simple_ce, getThis(), ZEND_STRL(YAF_VIEW_PROPERTY_NAME_TPLVARS), 1 TSRMLS_CC); if (tpl_vars && Z_TYPE_P(tpl_vars) == IS_ARRAY) { - if (zend_hash_find(Z_ARRVAL_P(tpl_vars), name, len + 1, (void **) &ret) == SUCCESS) { - RETURN_ZVAL(*ret, 1, 0); + if (len) { + if (zend_hash_find(Z_ARRVAL_P(tpl_vars), name, len + 1, (void **) &ret) == SUCCESS) { + RETURN_ZVAL(*ret, 1, 0); + } + } else { + RETURN_ZVAL(tpl_vars, 1, 0); } - } + } RETURN_NULL(); } @@ -644,7 +652,30 @@ PHP_METHOD(yaf_view_simple, display) { } /* }}} */ -/** {{{ yaf_view_simple_methods +/** {{{ proto public Yaf_View_Simple::clear(string $name) +*/ +PHP_METHOD(yaf_view_simple, clear) { + char *name; + zval *tpl_vars; + uint len = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &len) == FAILURE) { + return; + } + + tpl_vars = zend_read_property(yaf_view_simple_ce, getThis(), ZEND_STRL(YAF_VIEW_PROPERTY_NAME_TPLVARS), 1 TSRMLS_CC); + if (tpl_vars && Z_TYPE_P(tpl_vars) == IS_ARRAY) { + if (len) { + zend_symtable_del(Z_ARRVAL_P(tpl_vars), name, len + 1); + } else { + zend_hash_clean(Z_ARRVAL_P(tpl_vars)); + } + } + RETURN_ZVAL(getThis(), 1, 0); +} +/* }}} */ + +/** {{{ yaf_view_simple_methods */ zend_function_entry yaf_view_simple_methods[] = { PHP_ME(yaf_view_simple, __construct, yaf_view_simple_construct_arginfo, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC) @@ -654,6 +685,7 @@ zend_function_entry yaf_view_simple_methods[] = { PHP_ME(yaf_view_simple, render, yaf_view_render_arginfo, ZEND_ACC_PUBLIC) PHP_ME(yaf_view_simple, display, yaf_view_display_arginfo, ZEND_ACC_PUBLIC) PHP_ME(yaf_view_simple, assignRef, yaf_view_simple_assign_by_ref_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(yaf_view_simple, clear, yaf_view_simple_clear_arginfo, ZEND_ACC_PUBLIC) PHP_ME(yaf_view_simple, setScriptPath, yaf_view_setpath_arginfo, ZEND_ACC_PUBLIC) PHP_ME(yaf_view_simple, getScriptPath, yaf_view_getpath_arginfo, ZEND_ACC_PUBLIC) PHP_MALIAS(yaf_view_simple, __get, get, yaf_view_simple_get_arginfo, ZEND_ACC_PUBLIC) @@ -662,7 +694,7 @@ zend_function_entry yaf_view_simple_methods[] = { }; /* }}} */ -/** {{{ YAF_STARTUP_FUNCTION +/** {{{ YAF_STARTUP_FUNCTION */ YAF_STARTUP_FUNCTION(view_simple) { zend_class_entry ce; diff --git a/yaf.c b/yaf.c index 66a5d653..3df2ecfd 100644 --- a/yaf.c +++ b/yaf.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf.c 316485 2011-09-11 02:41:00Z laruence $ */ + +/* $Id: yaf.c 324897 2012-04-06 09:55:01Z laruence $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -50,7 +50,7 @@ ZEND_DECLARE_MODULE_GLOBALS(yaf); /* {{{ yaf_functions[] */ zend_function_entry yaf_functions[] = { - {NULL, NULL, NULL} + {NULL, NULL, NULL} }; /* }}} */ @@ -79,17 +79,18 @@ PHP_INI_END(); */ PHP_GINIT_FUNCTION(yaf) { - yaf_globals->autoload_started = 0; - yaf_globals->configs = NULL; + yaf_globals->autoload_started = 0; + yaf_globals->configs = NULL; yaf_globals->directory = NULL; - yaf_globals->library_directory = NULL; - yaf_globals->ext = YAF_DEFAULT_EXT; + yaf_globals->local_library = NULL; + yaf_globals->ext = YAF_DEFAULT_EXT; yaf_globals->view_ext = YAF_DEFAULT_VIEW_EXT; yaf_globals->default_module = YAF_ROUTER_DEFAULT_MODULE; - yaf_globals->default_controller = YAF_ROUTER_DEFAULT_CONTROLLER; + yaf_globals->default_controller = YAF_ROUTER_DEFAULT_CONTROLLER; yaf_globals->default_action = YAF_ROUTER_DEFAULT_ACTION; yaf_globals->bootstrap = YAF_DEFAULT_BOOTSTRAP; - yaf_globals->modules = NULL; + yaf_globals->modules = NULL; + yaf_globals->default_route = NULL; } /* }}} */ @@ -183,7 +184,8 @@ PHP_RINIT_FUNCTION(yaf) YAF_G(catch_exception) = 0; YAF_G(directory) = NULL; YAF_G(bootstrap) = NULL; - YAF_G(library_directory) = NULL; + YAF_G(local_library) = NULL; + YAF_G(local_namespace) = NULL; YAF_G(modules) = NULL; YAF_G(base_uri) = NULL; #if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4)) @@ -202,8 +204,28 @@ PHP_RSHUTDOWN_FUNCTION(yaf) { if (YAF_G(directory)) { efree(YAF_G(directory)); - YAF_G(directory) = NULL; } + if (YAF_G(local_library)) { + efree(YAF_G(local_library)); + } + if (YAF_G(local_namespace)) { + efree(YAF_G(local_namespace)); + } + if (YAF_G(bootstrap)) { + efree(YAF_G(bootstrap)); + } + if (YAF_G(modules)) { + zval_dtor(YAF_G(modules)); + efree(YAF_G(modules)); + } + if (YAF_G(base_uri)) { + efree(YAF_G(base_uri)); + } +#if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4)) + if (YAF_G(buffer)) { + efree(YAF_G(buffer)); + } +#endif return SUCCESS; } @@ -228,35 +250,40 @@ PHP_MINFO_FUNCTION(yaf) } /* }}} */ -/** {{{ DL support +/** {{{ DL support */ #ifdef COMPILE_DL_YAF ZEND_GET_MODULE(yaf) #endif /* }}} */ -/** {{{ module depends +/** {{{ module depends */ +#if ZEND_MODULE_API_NO >= 20050922 zend_module_dep yaf_deps[] = { ZEND_MOD_REQUIRED("spl") ZEND_MOD_REQUIRED("pcre") ZEND_MOD_OPTIONAL("session") {NULL, NULL, NULL} }; +#endif /* }}} */ /** {{{ yaf_module_entry */ zend_module_entry yaf_module_entry = { - STANDARD_MODULE_HEADER_EX, - NULL, +#if ZEND_MODULE_API_NO >= 20050922 + STANDARD_MODULE_HEADER_EX, NULL, yaf_deps, +#else + STANDARD_MODULE_HEADER, +#endif "yaf", yaf_functions, PHP_MINIT(yaf), PHP_MSHUTDOWN(yaf), - PHP_RINIT(yaf), - PHP_RSHUTDOWN(yaf), + PHP_RINIT(yaf), + PHP_RSHUTDOWN(yaf), PHP_MINFO(yaf), YAF_VERSION, PHP_MODULE_GLOBALS(yaf), diff --git a/yaf_action.c b/yaf_action.c index d8f50b42..68d0461a 100644 --- a/yaf_action.c +++ b/yaf_action.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_action.c 315957 2011-09-01 09:03:32Z laruence $ */ + +/* $Id: yaf_action.c 321289 2011-12-21 02:53:29Z laruence $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -35,7 +35,7 @@ zend_class_entry *yaf_action_ce; -/** {{{ ARG_INFO +/** {{{ ARG_INFO */ /* }}} */ @@ -48,7 +48,7 @@ PHP_METHOD(yaf_action, getController) { } /* }}} */ -/** {{{ yaf_controller_methods +/** {{{ yaf_controller_methods */ zend_function_entry yaf_action_methods[] = { PHP_ABSTRACT_ME(yaf_action_controller, execute, NULL) diff --git a/yaf_action.h b/yaf_action.h index c436b1eb..08623d8b 100644 --- a/yaf_action.h +++ b/yaf_action.h @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_action.h 315615 2011-08-27 14:14:48Z laruence $ */ + +/* $Id: yaf_action.h 321289 2011-12-21 02:53:29Z laruence $ */ #ifndef YAF_ACTION_H #define YAF_ACTION_H diff --git a/yaf_application.c b/yaf_application.c index b951d8fa..e09aceba 100644 --- a/yaf_application.c +++ b/yaf_application.c @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: yaf_application.c 315959 2011-09-01 09:46:43Z laruence $ */ +/* $Id: yaf_application.c 324897 2012-04-06 09:55:01Z laruence $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -42,6 +42,9 @@ zend_class_entry * yaf_application_ce; /** {{{ ARG_INFO * */ +ZEND_BEGIN_ARG_INFO_EX(yaf_application_void_arginfo, 0, 0, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(yaf_application_construct_arginfo, 0, 0, 1) ZEND_ARG_INFO(0, config) ZEND_ARG_INFO(0, envrion) @@ -74,6 +77,9 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(yaf_application_run_arginfo, 0, 0, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(yaf_application_setappdir_arginfo, 0, 0, 1) + ZEND_ARG_INFO(0, directory) +ZEND_END_ARG_INFO() /* }}} */ /** {{{ int yaf_application_is_module_name(char *name, int len TSRMLS_DC) @@ -106,7 +112,7 @@ int yaf_application_is_module_name(char *name, int len TSRMLS_DC) { } /* }}} */ -/** {{{ static int yaf_application_parse_option(zval *options TSRMLS_DC) +/** {{{ static int yaf_application_parse_option(zval *options TSRMLS_DC) */ static int yaf_application_parse_option(zval *options TSRMLS_DC) { HashTable *conf; @@ -151,12 +157,22 @@ static int yaf_application_parse_option(zval *options TSRMLS_DC) { YAF_G(bootstrap) = estrndup(Z_STRVAL_PP(ppzval), Z_STRLEN_PP(ppzval)); } - if (zend_hash_find(Z_ARRVAL_P(app), ZEND_STRS("library"), (void **)&ppzval) == SUCCESS - && Z_TYPE_PP(ppzval) == IS_STRING) { - YAF_G(library_directory) = estrndup(Z_STRVAL_PP(ppzval), Z_STRLEN_PP(ppzval)); - } + if (zend_hash_find(Z_ARRVAL_P(app), ZEND_STRS("library"), (void **)&ppzval) == SUCCESS) { + if (IS_STRING == Z_TYPE_PP(ppzval)) { + YAF_G(local_library) = estrndup(Z_STRVAL_PP(ppzval), Z_STRLEN_PP(ppzval)); + } else if (IS_ARRAY == Z_TYPE_PP(ppzval)) { + if (zend_hash_find(Z_ARRVAL_PP(ppzval), ZEND_STRS("directory"), (void **)&ppsval) == SUCCESS + && Z_TYPE_PP(ppsval) == IS_STRING) { + YAF_G(local_library) = estrndup(Z_STRVAL_PP(ppsval), Z_STRLEN_PP(ppsval)); + } + if (zend_hash_find(Z_ARRVAL_PP(ppzval), ZEND_STRS("namespace"), (void **)&ppsval) == SUCCESS + && Z_TYPE_PP(ppsval) == IS_STRING) { + YAF_G(local_namespace) = estrndup(Z_STRVAL_PP(ppsval), Z_STRLEN_PP(ppsval)); + } + } + } - if (zend_hash_find(Z_ARRVAL_P(app), ZEND_STRS("view"), (void **)&ppzval) == FAILURE + if (zend_hash_find(Z_ARRVAL_P(app), ZEND_STRS("view"), (void **)&ppzval) == FAILURE || Z_TYPE_PP(ppzval) != IS_ARRAY) { YAF_G(view_ext) = YAF_DEFAULT_VIEW_EXT; } else { @@ -217,6 +233,11 @@ static int yaf_application_parse_option(zval *options TSRMLS_DC) { YAF_G(catch_exception) = Z_BVAL_P(tmp); zval_ptr_dtor(&tmp); } + + if (zend_hash_find(Z_ARRVAL_PP(ppzval), ZEND_STRS("defaultRoute"), (void **)&ppsval) == SUCCESS + && Z_TYPE_PP(ppsval) == IS_ARRAY) { + YAF_G(default_route) = *ppsval; + } } do { @@ -234,7 +255,7 @@ static int yaf_application_parse_option(zval *options TSRMLS_DC) { if (seg && strlen(seg)) { MAKE_STD_ZVAL(module); ZVAL_STRINGL(module, seg, strlen(seg), 1); - zend_hash_next_index_insert(Z_ARRVAL_P(zmodules), + zend_hash_next_index_insert(Z_ARRVAL_P(zmodules), (void **)&module, sizeof(zval *), NULL); } seg = php_strtok_r(NULL, ",", &ptrptr); @@ -252,7 +273,7 @@ static int yaf_application_parse_option(zval *options TSRMLS_DC) { } /* }}} */ -/** {{{ proto Yaf_Application::__construct(mixed $config, string $environ = YAF_G(environ)) +/** {{{ proto Yaf_Application::__construct(mixed $config, string $environ = YAF_G(environ)) */ PHP_METHOD(yaf_application, __construct) { yaf_config_t *zconfig; @@ -279,7 +300,7 @@ PHP_METHOD(yaf_application, __construct) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|z", &config, §ion) == FAILURE) { yaf_trigger_error(YAF_ERR_STARTUP_FAILED TSRMLS_CC, "%s::__construct expects at least 1 parameter, 0 give", yaf_application_ce->name); return; - } + } if (!section || Z_TYPE_P(section) != IS_STRING || !Z_STRLEN_P(section)) { MAKE_STD_ZVAL(section); @@ -326,17 +347,17 @@ PHP_METHOD(yaf_application, __construct) { zval_ptr_dtor(&zdispatcher); zval_ptr_dtor(&zconfig); - if (YAF_G(library_directory)) { - loader = yaf_loader_instance(NULL, YAF_G(library_directory), + if (YAF_G(local_library)) { + loader = yaf_loader_instance(NULL, YAF_G(local_library), strlen(YAF_G(global_library))? YAF_G(global_library) : NULL TSRMLS_CC); - efree(YAF_G(library_directory)); - YAF_G(library_directory) = NULL; + efree(YAF_G(local_library)); + YAF_G(local_library) = NULL; } else { - char *library_directory; - spprintf(&library_directory, 0, "%s%c%s", YAF_G(directory), DEFAULT_SLASH, YAF_LIBRARY_DIRECTORY_NAME); - loader = yaf_loader_instance(NULL, library_directory, + char *local_library; + spprintf(&local_library, 0, "%s%c%s", YAF_G(directory), DEFAULT_SLASH, YAF_LIBRARY_DIRECTORY_NAME); + loader = yaf_loader_instance(NULL, local_library, strlen(YAF_G(global_library))? YAF_G(global_library) : NULL TSRMLS_CC); - efree(library_directory); + efree(local_library); } if (!loader) { @@ -344,6 +365,22 @@ PHP_METHOD(yaf_application, __construct) { RETURN_FALSE; } + if (YAF_G(local_namespace)) { + uint i, len; + char *tmp = YAF_G(local_namespace); + len = strlen(tmp); + if (len) { + for(i=0; iname, (*ce)->name); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expect a %s instance, %s give", yaf_bootstrap_ce->name, (*ce)->name); retval = 0; } - + efree(bootstrap_path); } @@ -597,13 +634,13 @@ PHP_METHOD(yaf_application, bootstrap) { zval_dtor(bootstrap); efree(bootstrap); - } + } RETVAL_ZVAL(self, 1, 0); } /* }}} */ -/** {{{ proto public Yaf_Application::getLastErrorNo(void) +/** {{{ proto public Yaf_Application::getLastErrorNo(void) */ PHP_METHOD(yaf_application, getLastErrorNo) { zval *errcode = zend_read_property(yaf_application_ce, getThis(), ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_ERRNO), 1 TSRMLS_CC); @@ -611,7 +648,7 @@ PHP_METHOD(yaf_application, getLastErrorNo) { } /* }}} */ -/** {{{ proto public Yaf_Application::getLastErrorMsg(void) +/** {{{ proto public Yaf_Application::getLastErrorMsg(void) */ PHP_METHOD(yaf_application, getLastErrorMsg) { zval *errmsg = zend_read_property(yaf_application_ce, getThis(), ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_ERRMSG), 1 TSRMLS_CC); @@ -619,7 +656,7 @@ PHP_METHOD(yaf_application, getLastErrorMsg) { } /* }}} */ -/** {{{ proto public Yaf_Application::clearLastError(void) +/** {{{ proto public Yaf_Application::clearLastError(void) */ PHP_METHOD(yaf_application, clearLastError) { zend_update_property_long(yaf_application_ce, getThis(), ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_ERRNO), 0 TSRMLS_CC); @@ -629,25 +666,57 @@ PHP_METHOD(yaf_application, clearLastError) { } /* }}} */ -/** {{{ yaf_application_methods +/** {{{ proto public Yaf_Application::setAppDirectory(string $directory) +*/ +PHP_METHOD(yaf_application, setAppDirectory) { + int len; + char *directory; + yaf_dispatcher_t *self = getThis(); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &directory, &len) == FAILURE) { + return; + } + + if (!len || !IS_ABSOLUTE_PATH(directory, len)) { + RETURN_FALSE; + } + + efree(YAF_G(directory)); + + YAF_G(directory) = estrndup(directory, len); + + RETURN_ZVAL(self, 1, 0); +} +/* }}} */ + +/** {{{ proto public Yaf_Application::getAppDirectory(void) +*/ +PHP_METHOD(yaf_application, getAppDirectory) { + RETURN_STRING(YAF_G(directory), 1); +} +/* }}} */ + +/** {{{ yaf_application_methods */ zend_function_entry yaf_application_methods[] = { - PHP_ME(yaf_application, __construct, yaf_application_construct_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) - PHP_ME(yaf_application, run, yaf_application_run_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(yaf_application, execute, yaf_application_execute_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(yaf_application, app, yaf_application_app_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(yaf_application, __construct, yaf_application_construct_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(yaf_application, run, yaf_application_run_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(yaf_application, execute, yaf_application_execute_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(yaf_application, app, yaf_application_app_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) PHP_ME(yaf_application, environ, yaf_application_environ_arginfo, ZEND_ACC_PUBLIC) PHP_ME(yaf_application, bootstrap, yaf_application_bootstrap_arginfo, ZEND_ACC_PUBLIC) PHP_ME(yaf_application, getConfig, yaf_application_getconfig_arginfo, ZEND_ACC_PUBLIC) PHP_ME(yaf_application, getModules, yaf_application_getmodule_arginfo, ZEND_ACC_PUBLIC) PHP_ME(yaf_application, getDispatcher, yaf_application_getdispatch_arginfo,ZEND_ACC_PUBLIC) - PHP_ME(yaf_application, getLastErrorNo, NULL, ZEND_ACC_PUBLIC) - PHP_ME(yaf_application, getLastErrorMsg,NULL, ZEND_ACC_PUBLIC) - PHP_ME(yaf_application, clearLastError, NULL, ZEND_ACC_PUBLIC) - PHP_ME(yaf_application, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR) - PHP_ME(yaf_application, __clone, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_CLONE) - PHP_ME(yaf_application, __sleep, NULL, ZEND_ACC_PRIVATE) - PHP_ME(yaf_application, __wakeup, NULL, ZEND_ACC_PRIVATE) + PHP_ME(yaf_application, setAppDirectory,yaf_application_setappdir_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(yaf_application, getAppDirectory,yaf_application_void_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(yaf_application, getLastErrorNo, yaf_application_void_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(yaf_application, getLastErrorMsg,yaf_application_void_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(yaf_application, clearLastError, yaf_application_void_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(yaf_application, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR) + PHP_ME(yaf_application, __clone, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_CLONE) + PHP_ME(yaf_application, __sleep, NULL, ZEND_ACC_PRIVATE) + PHP_ME(yaf_application, __wakeup, NULL, ZEND_ACC_PRIVATE) {NULL, NULL, NULL} }; /* }}} */ diff --git a/yaf_application.h b/yaf_application.h index 90379a70..87bde4f2 100644 --- a/yaf_application.h +++ b/yaf_application.h @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_application.h 315957 2011-09-01 09:03:32Z laruence $ */ + +/* $Id: yaf_application.h 321289 2011-12-21 02:53:29Z laruence $ */ #ifndef PHP_YAF_APPLICATION_H #define PHP_YAF_APPLICATION_H diff --git a/yaf_bootstrap.c b/yaf_bootstrap.c index bde5c574..35ea86de 100644 --- a/yaf_bootstrap.c +++ b/yaf_bootstrap.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_bootstrap.c 318209 2011-10-19 07:04:34Z laruence $ */ + +/* $Id: yaf_bootstrap.c 321289 2011-12-21 02:53:29Z laruence $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -29,7 +29,7 @@ zend_class_entry *yaf_bootstrap_ce; -/** {{{ yaf_bootstrap_methods +/** {{{ yaf_bootstrap_methods */ zend_function_entry yaf_bootstrap_methods[] = { {NULL, NULL, NULL} diff --git a/yaf_bootstrap.h b/yaf_bootstrap.h index 87f2df01..afa8921d 100644 --- a/yaf_bootstrap.h +++ b/yaf_bootstrap.h @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_bootstrap.h 315615 2011-08-27 14:14:48Z laruence $ */ + +/* $Id: yaf_bootstrap.h 321289 2011-12-21 02:53:29Z laruence $ */ #ifndef YAF_BOOTSTRAP_H #define YAF_BOOTSTRAP_H diff --git a/yaf_config.c b/yaf_config.c index b6983235..0adbab92 100644 --- a/yaf_config.c +++ b/yaf_config.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_config.c 315957 2011-09-01 09:03:32Z laruence $ */ + +/* $Id: yaf_config.c 321289 2011-12-21 02:53:29Z laruence $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -58,7 +58,7 @@ static int yaf_config_ini_modified(zval * file, long ctime TSRMLS_DC) { php_stat(Z_STRVAL_P(file), Z_STRLEN_P(file) + 1, 7 /*YAF_FS_CTIME*/ , &n_ctime TSRMLS_CC); if (Z_TYPE(n_ctime) != IS_BOOL && ctime != Z_LVAL(n_ctime)) { return Z_LVAL(n_ctime); - } + } return 0; } /* }}} */ @@ -114,11 +114,11 @@ static void yaf_config_copy_persistent(HashTable *pdst, HashTable *src TSRMLS_DC if (zend_hash_get_current_data(src, (void**)&ppzval) == FAILURE) { continue; } - + tmp = yaf_config_ini_zval_persistent(*ppzval TSRMLS_CC); if (tmp) zend_hash_index_update(pdst, idx, (void **)&tmp, sizeof(zval *), NULL); - + } else { zval *tmp; if (zend_hash_get_current_data(src, (void**)&ppzval) == FAILURE) { @@ -137,8 +137,8 @@ static void yaf_config_copy_persistent(HashTable *pdst, HashTable *src TSRMLS_DC */ static void yaf_config_copy_losable(HashTable *ldst, HashTable *src TSRMLS_DC) { zval **ppzval, *tmp; - char *key; - long idx; + char *key; + long idx; uint keylen; for(zend_hash_internal_pointer_reset(src); @@ -149,10 +149,10 @@ static void yaf_config_copy_losable(HashTable *ldst, HashTable *src TSRMLS_DC) { if (zend_hash_get_current_data(src, (void**)&ppzval) == FAILURE) { continue; } - + tmp = yaf_config_ini_zval_losable(*ppzval TSRMLS_CC); zend_hash_index_update(ldst, idx, (void **)&tmp, sizeof(zval *), NULL); - + } else { if (zend_hash_get_current_data(src, (void**)&ppzval) == FAILURE) { continue; @@ -288,7 +288,7 @@ static void yaf_config_ini_serialize(yaf_config_t *this_ptr, zval *filename, zva } cache = (yaf_config_cache *)pemalloc(sizeof(yaf_config_cache), 1); - + if (!cache) { return; } @@ -308,7 +308,7 @@ static void yaf_config_ini_serialize(yaf_config_t *this_ptr, zval *filename, zva cache->ctime = ctime; cache->data = persistent; len = spprintf(&key, 0, "%s#%s", Z_STRVAL_P(filename), Z_STRVAL_P(section)); - + zend_hash_update(YAF_G(configs), key, len + 1, (void **)&cache, sizeof(yaf_config_cache *), NULL); efree(key); diff --git a/yaf_config.h b/yaf_config.h index a3d42c05..d9d09cf1 100644 --- a/yaf_config.h +++ b/yaf_config.h @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_config.h 315615 2011-08-27 14:14:48Z laruence $ */ + +/* $Id: yaf_config.h 321289 2011-12-21 02:53:29Z laruence $ */ #ifndef YAF_CONFIG_H #define YAF_CONFIG_H diff --git a/yaf_controller.c b/yaf_controller.c index e2f4d18b..bb2985f1 100644 --- a/yaf_controller.c +++ b/yaf_controller.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_controller.c 317890 2011-10-08 13:31:56Z laruence $ */ + +/* $Id: yaf_controller.c 321289 2011-12-21 02:53:29Z laruence $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -134,7 +134,7 @@ static zval * yaf_controller_render(yaf_controller_t *instance, char *action_nam } /* }}} */ -/** {{{ static int yaf_controller_display(zend_class_entry *ce, yaf_controller_t *instance, char *action_name, int len, zval *var_array TSRMLS_DC) +/** {{{ static int yaf_controller_display(zend_class_entry *ce, yaf_controller_t *instance, char *action_name, int len, zval *var_array TSRMLS_DC) */ static int yaf_controller_display(zend_class_entry *ce, yaf_controller_t *instance, char *action_name, int len, zval *var_array TSRMLS_DC) { char *path, *view_ext, *self_name; @@ -146,7 +146,7 @@ static int yaf_controller_display(zend_class_entry *ce, yaf_controller_t *instan view = zend_read_property(ce, instance, ZEND_STRL(YAF_CONTROLLER_PROPERTY_NAME_VIEW), 1 TSRMLS_CC); name = zend_read_property(ce, instance, ZEND_STRL(YAF_CONTROLLER_PROPERTY_NAME_NAME), 1 TSRMLS_CC); view_ext = YAF_G(view_ext); - + self_name = zend_str_tolower_dup(Z_STRVAL_P(name), Z_STRLEN_P(name)); path_len = spprintf(&path, 0, "%s%c%s.%s", self_name, DEFAULT_SLASH, action_name, view_ext); @@ -167,7 +167,7 @@ static int yaf_controller_display(zend_class_entry *ce, yaf_controller_t *instan return 0; } - if ((Z_TYPE_P(ret) == IS_BOOL && !Z_BVAL_P(ret))) { + if ((Z_TYPE_P(ret) == IS_BOOL && !Z_BVAL_P(ret))) { zval_ptr_dtor(&ret); return 0; } @@ -192,7 +192,7 @@ int yaf_controller_construct(zend_class_entry *ce, yaf_controller_t *self, yaf_r zend_update_property(ce, self, ZEND_STRL(YAF_CONTROLLER_PROPERTY_NAME_MODULE), module TSRMLS_CC); zend_update_property(ce, self, ZEND_STRL(YAF_CONTROLLER_PROPERTY_NAME_VIEW), view TSRMLS_CC); - if (!instanceof_function(ce, yaf_action_ce TSRMLS_CC) + if (!instanceof_function(ce, yaf_action_ce TSRMLS_CC) && zend_hash_exists(&(ce->function_table), ZEND_STRS("init"))) { zend_call_method_with_0_params(&self, ce, NULL, "init", NULL); } @@ -217,7 +217,7 @@ PHP_METHOD(yaf_controller, __construct) { zval *invoke_arg = NULL; yaf_controller_t *self = getThis(); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ooo|z", + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ooo|z", &request, yaf_request_ce, &response, yaf_response_ce, &view, yaf_view_interface_ce, &invoke_arg) == FAILURE) { return; } else { @@ -354,7 +354,7 @@ PHP_METHOD(yaf_controller, forward) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|zzz", &module, &controller, &action, &args) == FAILURE) { return; - } + } request = zend_read_property(yaf_controller_ce, self, ZEND_STRL(YAF_CONTROLLER_PROPERTY_NAME_REQUEST), 1 TSRMLS_CC); parameters = zend_read_property(yaf_controller_ce, self, ZEND_STRL(YAF_CONTROLLER_PROPERTY_NAME_ARGS), 1 TSRMLS_CC); @@ -432,14 +432,14 @@ PHP_METHOD(yaf_controller, forward) { /** {{{ proto public Yaf_Controller_Abstract::redirect(string $url) */ PHP_METHOD(yaf_controller, redirect) { - char *location; + char *location; uint location_len; yaf_response_t *response; yaf_controller_t *self = getThis(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &location, &location_len) == FAILURE) { return; - } + } response = zend_read_property(yaf_controller_ce, self, ZEND_STRL(YAF_CONTROLLER_PROPERTY_NAME_RESPONSE), 1 TSRMLS_CC); @@ -490,7 +490,7 @@ PHP_METHOD(yaf_controller, __clone) { } /* }}} */ -/** {{{ yaf_controller_methods +/** {{{ yaf_controller_methods */ zend_function_entry yaf_controller_methods[] = { PHP_ME(yaf_controller, render, yaf_controller_render_arginfo, ZEND_ACC_PROTECTED|ZEND_ACC_FINAL) diff --git a/yaf_controller.h b/yaf_controller.h index 18c25b8c..854dd253 100644 --- a/yaf_controller.h +++ b/yaf_controller.h @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_controller.h 315615 2011-08-27 14:14:48Z laruence $ */ + +/* $Id: yaf_controller.h 324667 2012-03-31 13:55:08Z laruence $ */ #ifndef YAF_CONTROLLER_H #define YAF_CONTROLLER_H @@ -25,11 +25,13 @@ #define YAF_CONTROLLER_PROPERTY_NAME_RESPONSE "_response" #define YAF_CONTROLLER_PROPERTY_NAME_REQUEST "_request" #define YAF_CONTROLLER_PROPERTY_NAME_ARGS "_invoke_args" -#define YAF_CONTROLLER_PROPERTY_NAME_ACTIONS "actions" +#define YAF_CONTROLLER_PROPERTY_NAME_ACTIONS "actions" #define YAF_CONTROLLER_PROPERTY_NAME_VIEW "_view" +#define YAF_CONTROLLER_PROPERTY_NAME_RENDER "yafAutoRender" + extern zend_class_entry *yaf_controller_ce; -int yaf_controller_construct(zend_class_entry *ce, yaf_controller_t *self, +int yaf_controller_construct(zend_class_entry *ce, yaf_controller_t *self, yaf_request_t *request, yaf_response_t *response, yaf_view_t *view, zval *args TSRMLS_DC); YAF_STARTUP_FUNCTION(controller); #endif diff --git a/yaf_dispatcher.c b/yaf_dispatcher.c index 7d0514cb..8c774ee4 100644 --- a/yaf_dispatcher.c +++ b/yaf_dispatcher.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_dispatcher.c 315962 2011-09-01 10:00:15Z laruence $ */ + +/* $Id: yaf_dispatcher.c 324955 2012-04-08 09:24:06Z laruence $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -94,10 +94,6 @@ ZEND_BEGIN_ARG_INFO_EX(yaf_dispatcher_setview_arginfo, 0, 0, 1) ZEND_ARG_INFO(0, view) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(yaf_dispatcher_setappdir_arginfo, 0, 0, 1) - ZEND_ARG_INFO(0, directory) -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_INFO_EX(yaf_dispatcher_setctrl_arginfo, 0, 0, 1) ZEND_ARG_INFO(0, controller) ZEND_END_ARG_INFO() @@ -112,7 +108,7 @@ ZEND_END_ARG_INFO() /* }}} */ -/** {{{ yaf_dispatcher_t * yaf_dispatcher_instance(zval *this_ptr TSRMLS_DC) +/** {{{ yaf_dispatcher_t * yaf_dispatcher_instance(zval *this_ptr TSRMLS_DC) */ yaf_dispatcher_t * yaf_dispatcher_instance(yaf_dispatcher_t *this_ptr TSRMLS_DC) { zval *plugins; @@ -121,7 +117,7 @@ yaf_dispatcher_t * yaf_dispatcher_instance(yaf_dispatcher_t *this_ptr TSRMLS_DC) instance = zend_read_static_property(yaf_dispatcher_ce, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_INSTANCE), 1 TSRMLS_CC); - if (IS_OBJECT == Z_TYPE_P(instance) + if (IS_OBJECT == Z_TYPE_P(instance) && instanceof_function(Z_OBJCE_P(instance), yaf_dispatcher_ce TSRMLS_CC)) { Z_ADDREF_P(instance); return instance; @@ -136,7 +132,7 @@ yaf_dispatcher_t * yaf_dispatcher_instance(yaf_dispatcher_t *this_ptr TSRMLS_DC) object_init_ex(instance, yaf_dispatcher_ce); } - /** unecessary yet + /** unecessary yet MAKE_STD_ZVAL(args); array_init(args); yaf_update_property(instance, YAF_DISPATCHER_PROPERTY_NAME_ARGS, args); @@ -194,7 +190,7 @@ static void yaf_dispatcher_get_call_parmaters(zend_class_entry *request_ce, yaf_ if (zend_hash_get_current_key_ex(params_ht, &key, &keylen, &idx, 0, NULL) == HASH_KEY_IS_STRING) { if (keylen == llen && !strncasecmp(key, arg_info->name, keylen)) { if (zend_hash_get_current_data(params_ht, (void**)&arg) == SUCCESS) { - /* return when we find first match, there is a trap + /* return when we find first match, there is a trap * when multi different parameters in different case presenting in params_ht * only the first take affect */ @@ -209,7 +205,7 @@ static void yaf_dispatcher_get_call_parmaters(zend_class_entry *request_ce, yaf_ if (NULL == arg) { break; } - } + } } } /* }}} */ @@ -265,7 +261,7 @@ static inline void yaf_dispatcher_fix_default(yaf_dispatcher_t *dispatcher, yaf_ while (*p != '\0') { if (*p == '_' #ifdef YAF_HAVE_NAMESPACE - || *p == '\\' + || *p == '\\' #endif ) { if (*(p+1) != '\0') { @@ -308,10 +304,10 @@ zend_class_entry * yaf_dispatcher_get_controller(char *app_dir, char *module, ch int directory_len = 0; if (def_module) { - directory_len = spprintf(&directory, 0, "%s%c%s", app_dir, DEFAULT_SLASH, "controllers"); + directory_len = spprintf(&directory, 0, "%s%c%s", app_dir, DEFAULT_SLASH, YAF_CONTROLLER_DIRECTORY_NAME); } else { directory_len = spprintf(&directory, 0, "%s%c%s%c%s%c%s", app_dir, DEFAULT_SLASH, - "modules", DEFAULT_SLASH, module, DEFAULT_SLASH, "controllers"); + YAF_MODULE_DIRECTORY_NAME, DEFAULT_SLASH, module, DEFAULT_SLASH, YAF_CONTROLLER_DIRECTORY_NAME); } if (directory_len) { @@ -417,7 +413,7 @@ zend_class_entry * yaf_dispatcher_get_action(char *app_dir, yaf_controller_t *co efree(action_path); } } else { - yaf_trigger_error(YAF_ERR_NOTFOUND_ACTION TSRMLS_CC, "There is no method %s%s in %s::$%s", + yaf_trigger_error(YAF_ERR_NOTFOUND_ACTION TSRMLS_CC, "There is no method %s%s in %s::$%s", action, "Action", Z_OBJCE_P(controller)->name, YAF_CONTROLLER_PROPERTY_NAME_ACTIONS); } } else @@ -437,7 +433,7 @@ zend_class_entry * yaf_dispatcher_get_action(char *app_dir, yaf_controller_t *co while (*p != '\0') { if (*p == '_' #ifdef YAF_HAVE_NAMESPACE - || *p == '\\' + || *p == '\\' #endif ) { if (*(p+1) != '\0') { @@ -497,12 +493,12 @@ zend_class_entry * yaf_dispatcher_get_action(char *app_dir, yaf_controller_t *co efree(directory); return *ce; - } else + } else /* }}} */ { yaf_trigger_error(YAF_ERR_NOTFOUND_ACTION TSRMLS_CC, "There is no method %s%s in %s", action, "Action", Z_OBJCE_P(controller)->name); } - + return NULL; } /* }}} */ @@ -517,13 +513,13 @@ int yaf_dispatcher_handle(yaf_dispatcher_t *dispatcher, yaf_request_t *request, yaf_request_set_dispatched(request, 1 TSRMLS_CC); if (!app_dir) { - yaf_trigger_error(YAF_ERR_STARTUP_FAILED TSRMLS_CC, "%s requires %s(which set the application.directory) to be initialized first", + yaf_trigger_error(YAF_ERR_STARTUP_FAILED TSRMLS_CC, "%s requires %s(which set the application.directory) to be initialized first", yaf_dispatcher_ce->name, yaf_application_ce->name); return 0; } else { int is_def_module = 0; int is_def_ctr = 0; - zval *module, *controller, *dmodule, *dcontroller, *return_response, *instantly_flush; + zval *module, *controller, *dmodule, *dcontroller, *instantly_flush; zend_class_entry *ce; yaf_controller_t *executor; zend_function *fptr; @@ -551,11 +547,11 @@ int yaf_dispatcher_handle(yaf_dispatcher_t *dispatcher, yaf_request_t *request, if(strncasecmp(Z_STRVAL_P(dmodule), Z_STRVAL_P(module), Z_STRLEN_P(module)) == 0) { is_def_module = 1; - } + } if (strncasecmp(Z_STRVAL_P(dcontroller), Z_STRVAL_P(controller), Z_STRLEN_P(controller)) == 0) { is_def_ctr = 1; - } + } ce = yaf_dispatcher_get_controller(app_dir, Z_STRVAL_P(module), Z_STRVAL_P(controller), Z_STRLEN_P(controller), is_def_module TSRMLS_CC); if (!ce) { @@ -571,8 +567,8 @@ int yaf_dispatcher_handle(yaf_dispatcher_t *dispatcher, yaf_request_t *request, MAKE_STD_ZVAL(icontroller); object_init_ex(icontroller, ce); - /* cause controller's constructor is a final method, so it must be a internal function - do { + /* cause controller's constructor is a final method, so it must be a internal function + do { zend_function *constructor = NULL; constructor = Z_OBJ_HT_P(exec_ctr)->get_constructor(exec_ctr TSRMLS_CC); if (constructor != NULL) { @@ -583,7 +579,7 @@ int yaf_dispatcher_handle(yaf_dispatcher_t *dispatcher, yaf_request_t *request, } } } while(0); - */ + */ yaf_controller_construct(ce, icontroller, request, response, view, NULL TSRMLS_CC); MAKE_STD_ZVAL(view_dir); @@ -623,7 +619,7 @@ int yaf_dispatcher_handle(yaf_dispatcher_t *dispatcher, yaf_request_t *request, ret = NULL; executor = icontroller; - if (fptr->common.num_args) { + if (fptr->common.num_args) { zval *method_name; yaf_dispatcher_get_call_parmaters(request_ce, request, fptr, &call_args, &count TSRMLS_CC); @@ -655,13 +651,13 @@ int yaf_dispatcher_handle(yaf_dispatcher_t *dispatcher, yaf_request_t *request, efree(icontroller); return 0; } - } else if ((ce = yaf_dispatcher_get_action(app_dir, icontroller, - Z_STRVAL_P(module), is_def_module, Z_STRVAL_P(action), Z_STRLEN_P(action) TSRMLS_CC)) - && (zend_hash_find(&(ce)->function_table, YAF_ACTION_EXECUTOR_NAME, + } else if ((ce = yaf_dispatcher_get_action(app_dir, icontroller, + Z_STRVAL_P(module), is_def_module, Z_STRVAL_P(action), Z_STRLEN_P(action) TSRMLS_CC)) + && (zend_hash_find(&(ce)->function_table, YAF_ACTION_EXECUTOR_NAME, sizeof(YAF_ACTION_EXECUTOR_NAME), (void **)&fptr) == SUCCESS)) { zval ***call_args; yaf_action_t *iaction; - uint count = 0; + uint count = 0; MAKE_STD_ZVAL(iaction); object_init_ex(iaction, ce); @@ -705,57 +701,63 @@ int yaf_dispatcher_handle(yaf_dispatcher_t *dispatcher, yaf_request_t *request, zval_dtor(icontroller); efree(icontroller); return 0; - } + } } else { Z_DELREF_P(action); zval_dtor(icontroller); efree(icontroller); return 0; - } + } - render = zend_read_property(yaf_dispatcher_ce, dispatcher, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_RENDER), 1 TSRMLS_CC); - return_response = zend_read_property(yaf_dispatcher_ce, dispatcher, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_RETURN), 1 TSRMLS_CC); - instantly_flush = zend_read_property(yaf_dispatcher_ce, dispatcher, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_FLUSH), 1 TSRMLS_CC); + if (executor) { + /* controller's property can override the Dispatcher's */ + int auto_render = 1; + render = zend_read_property(ce, executor, ZEND_STRL(YAF_CONTROLLER_PROPERTY_NAME_RENDER), 1 TSRMLS_CC); + instantly_flush = zend_read_property(yaf_dispatcher_ce, dispatcher, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_FLUSH), 1 TSRMLS_CC); + if (render == EG(uninitialized_zval_ptr)) { + render = zend_read_property(yaf_dispatcher_ce, dispatcher, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_RENDER), 1 TSRMLS_CC); + auto_render = Z_BVAL_P(render); + } else if (Z_TYPE_P(render) <= IS_BOOL && !Z_BVAL_P(render)) { + auto_render = 0; + } - if (executor && Z_BVAL_P(render)) { - ret = NULL; - if (!Z_BVAL_P(instantly_flush)) { - zend_call_method_with_1_params(&executor, ce, NULL, "render", &ret, action); - zval_dtor(executor); - efree(executor); - - if (ret && Z_TYPE_P(ret) == IS_STRING && Z_STRLEN_P(ret)) { - yaf_response_alter_body(response, NULL, 0, Z_STRVAL_P(ret), Z_STRLEN_P(ret), 0 TSRMLS_CC); - zval_ptr_dtor(&ret); - } else if (ret) { - zval_ptr_dtor(&ret); - Z_DELREF_P(action); - return 0; - } - } else { - zend_call_method_with_1_params(&executor, ce, NULL, "display", &ret, action); - zval_dtor(executor); - efree(executor); + if (auto_render) { + ret = NULL; + if (!Z_BVAL_P(instantly_flush)) { + zend_call_method_with_1_params(&executor, ce, NULL, "render", &ret, action); + zval_dtor(executor); + efree(executor); + + if (ret && Z_TYPE_P(ret) == IS_STRING && Z_STRLEN_P(ret)) { + yaf_response_alter_body(response, NULL, 0, Z_STRVAL_P(ret), Z_STRLEN_P(ret), YAF_RESPONSE_APPEND TSRMLS_CC); + zval_ptr_dtor(&ret); + } else if (ret) { + zval_ptr_dtor(&ret); + Z_DELREF_P(action); + return 0; + } + } else { + zend_call_method_with_1_params(&executor, ce, NULL, "display", &ret, action); + zval_dtor(executor); + efree(executor); - if (!ret) { - Z_DELREF_P(action); - return 0; - } + if (!ret) { + Z_DELREF_P(action); + return 0; + } - if ((Z_TYPE_P(ret) == IS_BOOL && !Z_BVAL_P(ret))) { - zval_ptr_dtor(&ret); - Z_DELREF_P(action); - return 0; + if ((Z_TYPE_P(ret) == IS_BOOL && !Z_BVAL_P(ret))) { + zval_ptr_dtor(&ret); + Z_DELREF_P(action); + return 0; + } } } - } Z_DELREF_P(action); - - return 1; } - } - + return 1; + } return 0; } /* }}} */ @@ -865,13 +867,14 @@ yaf_response_t * yaf_dispatcher_dispatch(yaf_dispatcher_t *dispatcher TSRMLS_DC) zval_ptr_dtor(&response); return NULL; } + yaf_dispatcher_fix_default(dispatcher, request TSRMLS_CC); YAF_PLUGIN_HANDLE(plugins, YAF_PLUGIN_HOOK_ROUTESHUTDOWN, request, response); YAF_EXCEPTION_HANDLE(dispatcher, request, response); (void)yaf_request_set_routed(request, 1 TSRMLS_CC); + } else { + yaf_dispatcher_fix_default(dispatcher, request TSRMLS_CC); } - yaf_dispatcher_fix_default(dispatcher, request TSRMLS_CC); - YAF_PLUGIN_HANDLE(plugins, YAF_PLUGIN_HOOK_LOOPSTARTUP, request, response); YAF_EXCEPTION_HANDLE(dispatcher, request, response); @@ -910,7 +913,7 @@ yaf_response_t * yaf_dispatcher_dispatch(yaf_dispatcher_t *dispatcher TSRMLS_DC) } /* }}} */ -/** {{{ proto private Yaf_Dispatcher::__construct(void) +/** {{{ proto private Yaf_Dispatcher::__construct(void) */ PHP_METHOD(yaf_dispatcher, __construct) { } @@ -961,7 +964,7 @@ PHP_METHOD(yaf_dispatcher, setErrorHandler) { } /* }}} */ -/** {{{ proto public Yaf_Dispatcher::disableView() +/** {{{ proto public Yaf_Dispatcher::disableView() */ PHP_METHOD(yaf_dispatcher, disableView) { yaf_dispatcher_t *self = getThis(); @@ -970,7 +973,7 @@ PHP_METHOD(yaf_dispatcher, disableView) { } /* }}} */ -/** {{{ proto public Yaf_Dispatcher::enableView() +/** {{{ proto public Yaf_Dispatcher::enableView() */ PHP_METHOD(yaf_dispatcher, enableView) { yaf_dispatcher_t *self = getThis(); @@ -979,7 +982,7 @@ PHP_METHOD(yaf_dispatcher, enableView) { } /* }}} */ -/** {{{ proto public Yaf_Dispatcher::returnResponse() +/** {{{ proto public Yaf_Dispatcher::returnResponse() */ PHP_METHOD(yaf_dispatcher, returnResponse) { long auto_response; @@ -995,7 +998,7 @@ PHP_METHOD(yaf_dispatcher, returnResponse) { } /* }}} */ -/** {{{ proto public Yaf_Dispatcher::flushInstantly(bool $flag) +/** {{{ proto public Yaf_Dispatcher::flushInstantly(bool $flag) */ PHP_METHOD(yaf_dispatcher, flushInstantly) { long instantly_flush; @@ -1035,7 +1038,7 @@ PHP_METHOD(yaf_dispatcher, registerPlugin) { } /* }}} */ -/** {{{ proto public Yaf_Dispatcher::setRequest(Yaf_Request_Abstract $request) +/** {{{ proto public Yaf_Dispatcher::setRequest(Yaf_Request_Abstract $request) */ PHP_METHOD(yaf_dispatcher, setRequest) { yaf_request_t *request; @@ -1045,12 +1048,12 @@ PHP_METHOD(yaf_dispatcher, setRequest) { return; } - if (IS_OBJECT != Z_TYPE_P(request) + if (IS_OBJECT != Z_TYPE_P(request) || !instanceof_function(Z_OBJCE_P(request), yaf_request_ce TSRMLS_CC)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expects a %s instance", yaf_request_ce->name); RETURN_FALSE; - } - + } + self = getThis(); if (yaf_dispatcher_set_request(self, request TSRMLS_CC)) { RETURN_ZVAL(self, 1, 0); @@ -1060,7 +1063,7 @@ PHP_METHOD(yaf_dispatcher, setRequest) { } /* }}} */ -/** {{{ proto public Yaf_Dispatcher::getInstance(void) +/** {{{ proto public Yaf_Dispatcher::getInstance(void) */ PHP_METHOD(yaf_dispatcher, getInstance) { yaf_dispatcher_t *dispatcher = yaf_dispatcher_instance(NULL TSRMLS_CC); @@ -1068,7 +1071,7 @@ PHP_METHOD(yaf_dispatcher, getInstance) { } /* }}} */ -/** {{{ proto public Yaf_Dispatcher::getRouter(void) +/** {{{ proto public Yaf_Dispatcher::getRouter(void) */ PHP_METHOD(yaf_dispatcher, getRouter) { yaf_router_t *router = zend_read_property(yaf_dispatcher_ce, getThis(), ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_ROUTER), 1 TSRMLS_CC); @@ -1076,7 +1079,7 @@ PHP_METHOD(yaf_dispatcher, getRouter) { } /* }}} */ -/** {{{ proto public Yaf_Dispatcher::getRequest(void) +/** {{{ proto public Yaf_Dispatcher::getRequest(void) */ PHP_METHOD(yaf_dispatcher, getRequest) { yaf_request_t *request = zend_read_property(yaf_dispatcher_ce, getThis(), ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_REQUEST), 1 TSRMLS_CC); @@ -1084,7 +1087,7 @@ PHP_METHOD(yaf_dispatcher, getRequest) { } /* }}} */ -/** {{{ proto public Yaf_Dispatcher::getApplication(void) +/** {{{ proto public Yaf_Dispatcher::getApplication(void) */ PHP_METHOD(yaf_dispatcher, getApplication) { PHP_MN(yaf_application_app)(INTERNAL_FUNCTION_PARAM_PASSTHRU); @@ -1112,47 +1115,47 @@ PHP_METHOD(yaf_dispatcher, dispatch) { } /* }}} */ -/** {{{ proto public Yaf_Dispatcher::throwException(bool $flag=0) +/** {{{ proto public Yaf_Dispatcher::throwException(bool $flag=0) */ PHP_METHOD(yaf_dispatcher, throwException) { int flag; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &flag) == FAILURE) { return; - } + } YAF_G(throw_exception) = flag? 1: 0; RETURN_ZVAL(getThis(), 1, 0); } /* }}} */ -/** {{{ proto public Yaf_Dispatcher::catchException(bool $flag=0) +/** {{{ proto public Yaf_Dispatcher::catchException(bool $flag=0) */ PHP_METHOD(yaf_dispatcher, catchException) { int flag; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &flag) == FAILURE) { return; - } + } YAF_G(catch_exception) = flag? 1: 0; RETURN_ZVAL(getThis(), 1, 0); } /* }}} */ -/** {{{ proto public Yaf_Dispatcher::autoRender(int $flag) - */ -PHP_METHOD(yaf_dispatcher, autoRender) { +/** {{{ proto public Yaf_Dispatcher::autoRender(int $flag) + */ +PHP_METHOD(yaf_dispatcher, autoRender) { long flag; - yaf_dispatcher_t *self = getThis(); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &flag) == FAILURE) { + yaf_dispatcher_t *self = getThis(); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &flag) == FAILURE) { return; - } - + } + zend_update_property_bool(yaf_dispatcher_ce, self, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_RENDER), flag? 1 : 0 TSRMLS_CC); - - RETURN_ZVAL(self, 1, 0); -} -/* }}} */ + + RETURN_ZVAL(self, 1, 0); +} +/* }}} */ /** {{{ proto public Yaf_Dispatcher::initView(string $tpl_dir, array $options = NULL) */ @@ -1194,29 +1197,6 @@ PHP_METHOD(yaf_dispatcher, setView) { } /* }}} */ -/** {{{ proto public Yaf_Dispatcher::setAppDirectory(string $directory) -*/ -PHP_METHOD(yaf_dispatcher, setAppDirectory) { - int len; - char *directory; - yaf_dispatcher_t *self = getThis(); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &directory, &len) == FAILURE) { - return; - } - - if (!len || !IS_ABSOLUTE_PATH(directory, len)) { - RETURN_FALSE; - } - - efree(YAF_G(directory)); - - YAF_G(directory) = estrndup(directory, len); - - RETURN_ZVAL(self, 1, 0); -} -/* }}} */ - /** {{{ proto public Yaf_Dispatcher::setDefaultModule(string $name) */ PHP_METHOD(yaf_dispatcher, setDefaultModule) { @@ -1227,14 +1207,15 @@ PHP_METHOD(yaf_dispatcher, setDefaultModule) { return; } - if (IS_STRING == Z_TYPE_P(module) && Z_STRLEN_P(module) + if (IS_STRING == Z_TYPE_P(module) && Z_STRLEN_P(module) && yaf_application_is_module_name(Z_STRVAL_P(module), Z_STRLEN_P(module) TSRMLS_CC)) { zval *module_std; MAKE_STD_ZVAL(module_std); ZVAL_STRING(module_std, zend_str_tolower_dup(Z_STRVAL_P(module), Z_STRLEN_P(module)), 0); *Z_STRVAL_P(module_std) = toupper(*Z_STRVAL_P(module_std)); zend_update_property(yaf_dispatcher_ce, self, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_MODULE), module_std TSRMLS_CC); - + zval_ptr_dtor(&module_std); + RETURN_ZVAL(self, 1, 0); } @@ -1258,7 +1239,7 @@ PHP_METHOD(yaf_dispatcher, setDefaultController) { ZVAL_STRING(controller_std, zend_str_tolower_dup(Z_STRVAL_P(controller), Z_STRLEN_P(controller)), 0); *Z_STRVAL_P(controller_std) = toupper(*Z_STRVAL_P(controller_std)); zend_update_property(yaf_dispatcher_ce, self, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_CONTROLLER), controller_std TSRMLS_CC); - + RETURN_ZVAL(self, 1, 0); } @@ -1281,7 +1262,8 @@ PHP_METHOD(yaf_dispatcher, setDefaultAction) { MAKE_STD_ZVAL(action_lower); ZVAL_STRING(action_lower, zend_str_tolower_dup(Z_STRVAL_P(action), Z_STRLEN_P(action)), 0); zend_update_property(yaf_dispatcher_ce, self, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_ACTION), action_lower TSRMLS_CC); - + zval_ptr_dtor(&action_lower); + RETURN_ZVAL(self, 1, 0); } @@ -1301,10 +1283,10 @@ PHP_METHOD(yaf_dispatcher, __clone) { } /* }}} */ -/** {{{ yaf_dispatcher_methods +/** {{{ yaf_dispatcher_methods */ zend_function_entry yaf_dispatcher_methods[] = { - PHP_ME(yaf_dispatcher, __construct, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR) + PHP_ME(yaf_dispatcher, __construct, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR) PHP_ME(yaf_dispatcher, __clone, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_CLONE) PHP_ME(yaf_dispatcher, __sleep, NULL, ZEND_ACC_PRIVATE) PHP_ME(yaf_dispatcher, __wakeup, NULL, ZEND_ACC_PRIVATE) @@ -1317,7 +1299,6 @@ zend_function_entry yaf_dispatcher_methods[] = { PHP_ME(yaf_dispatcher, getRouter, yaf_dispatcher_void_arginfo, ZEND_ACC_PUBLIC) PHP_ME(yaf_dispatcher, getRequest, yaf_dispatcher_void_arginfo, ZEND_ACC_PUBLIC) PHP_ME(yaf_dispatcher, setErrorHandler, yaf_dispatcher_seterrhdler_arginfo, ZEND_ACC_PUBLIC) - PHP_ME(yaf_dispatcher, setAppDirectory, yaf_dispatcher_setappdir_arginfo, ZEND_ACC_PUBLIC) PHP_ME(yaf_dispatcher, setDefaultModule, yaf_dispatcher_setmodule_arginfo, ZEND_ACC_PUBLIC) PHP_ME(yaf_dispatcher, setDefaultController,yaf_dispatcher_setctrl_arginfo, ZEND_ACC_PUBLIC) PHP_ME(yaf_dispatcher, setDefaultAction, yaf_dispatcher_setaction_arginfo, ZEND_ACC_PUBLIC) diff --git a/yaf_exception.c b/yaf_exception.c index 785425a5..c6cfbafe 100644 --- a/yaf_exception.c +++ b/yaf_exception.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_exception.c 315957 2011-09-01 09:03:32Z laruence $ */ + +/* $Id: yaf_exception.c 324666 2012-03-31 13:30:18Z laruence $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -48,22 +48,22 @@ void yaf_trigger_error(int type TSRMLS_DC, char *format, ...) { uint msg_len; va_start(args, format); - msg_len = vspprintf(&message, 0, format, args); - va_end(args); + msg_len = vspprintf(&message, 0, format, args); + va_end(args); if (YAF_G(throw_exception)) { yaf_throw_exception(type, message TSRMLS_CC); - } else { + } else { yaf_application_t *app = zend_read_static_property(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_APP), 1 TSRMLS_CC); zend_update_property_long(yaf_application_ce, app, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_ERRNO), type TSRMLS_CC); zend_update_property_stringl(yaf_application_ce, app, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_ERRMSG), message, msg_len TSRMLS_CC); - php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, message); - } - efree(message); + php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "%s", message); + } + efree(message); } /* }}} */ -/** {{{ zend_class_entry * yaf_get_exception_base(int root TSRMLS_DC) +/** {{{ zend_class_entry * yaf_get_exception_base(int root TSRMLS_DC) */ zend_class_entry * yaf_get_exception_base(int root TSRMLS_DC) { #if can_handle_soft_dependency_on_SPL && defined(HAVE_SPL) && ((PHP_MAJOR_VERSION > 5) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1)) @@ -104,7 +104,7 @@ void yaf_throw_exception(long code, char *message TSRMLS_DC) { /* }}} */ #if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 3)) || (PHP_MAJOR_VERSION < 5) -/** {{{ proto Yaf_Exception::__construct($mesg = 0, $code = 0, Exception $previous = NULL) +/** {{{ proto Yaf_Exception::__construct($mesg = 0, $code = 0, Exception $previous = NULL) */ PHP_METHOD(yaf_exception, __construct) { char *message = NULL; @@ -145,8 +145,8 @@ PHP_METHOD(yaf_exception, getPrevious) { */ zend_function_entry yaf_exception_methods[] = { #if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 3)) || (PHP_MAJOR_VERSION < 5) - PHP_ME(yaf_exception, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) - PHP_ME(yaf_exception, getPrevious, NULL, ZEND_ACC_PUBLIC) + PHP_ME(yaf_exception, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(yaf_exception, getPrevious, NULL, ZEND_ACC_PUBLIC) #endif {NULL, NULL, NULL} }; diff --git a/yaf_exception.h b/yaf_exception.h index 7e1391e7..3e33bc1d 100644 --- a/yaf_exception.h +++ b/yaf_exception.h @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_exception.h 315615 2011-08-27 14:14:48Z laruence $ */ + +/* $Id: yaf_exception.h 321289 2011-12-21 02:53:29Z laruence $ */ #ifndef YAF_EXCEPTION_H #define YAF_EXCEPTION_H @@ -28,8 +28,8 @@ #define YAF_ERR_STARTUP_FAILED 512 #define YAF_ERR_ROUTE_FAILED 513 #define YAF_ERR_DISPATCH_FAILED 514 -#define YAF_ERR_NOTFOUND_MODULE 515 -#define YAF_ERR_NOTFOUND_CONTROLLER 516 +#define YAF_ERR_NOTFOUND_MODULE 515 +#define YAF_ERR_NOTFOUND_CONTROLLER 516 #define YAF_ERR_NOTFOUND_ACTION 517 #define YAF_ERR_NOTFOUND_VIEW 518 #define YAF_ERR_CALL_FAILED 519 diff --git a/yaf_loader.c b/yaf_loader.c index cd2f7d94..9ee9ca55 100644 --- a/yaf_loader.c +++ b/yaf_loader.c @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: yaf_loader.c 315715 2011-08-29 16:08:35Z laruence $ */ +/* $Id: yaf_loader.c 324792 2012-04-04 07:45:20Z laruence $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -36,6 +36,42 @@ zend_class_entry *yaf_loader_ce; +/** {{{ ARG_INFO + */ +ZEND_BEGIN_ARG_INFO_EX(yaf_loader_void_arginfo, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(yaf_loader_getinstance_arginfo, 0, 0, 0) + ZEND_ARG_INFO(0, local_library_path) + ZEND_ARG_INFO(0, global_library_path) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(yaf_loader_autoloader_arginfo, 0, 0, 1) + ZEND_ARG_INFO(0, class_name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(yaf_loader_regnamespace_arginfo, 0, 0, 1) + ZEND_ARG_INFO(0, name_prefix) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(yaf_loader_islocalname_arginfo, 0, 0, 1) + ZEND_ARG_INFO(0, class_name) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(yaf_loader_import_arginfo, 0, 0, 1) + ZEND_ARG_INFO(0, file) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(yaf_loader_setlib_arginfo, 0, 0, 1) + ZEND_ARG_INFO(0, library_path) + ZEND_ARG_INFO(0, is_global) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(yaf_loader_getlib_arginfo, 0, 0, 0) + ZEND_ARG_INFO(0, is_global) +ZEND_END_ARG_INFO() +/* }}} */ + /** {{{ int yaf_loader_register(TSRMLS_D) */ int yaf_loader_register(yaf_loader_t *loader TSRMLS_DC) { @@ -92,7 +128,7 @@ int yaf_loader_register(yaf_loader_t *loader TSRMLS_DC) { 0, 0, ZEND_FN(yaf_override_spl_autoload), - NULL + NULL }; zend_internal_function *internal_function = (zend_internal_function *)&override_function; internal_function->type = ZEND_INTERNAL_FUNCTION; @@ -108,11 +144,11 @@ int yaf_loader_register(yaf_loader_t *loader TSRMLS_DC) { internal_function->return_reference = 0; internal_function->fn_flags = ZEND_ACC_PUBLIC; function_add_ref((zend_function*)&override_function); - //zend_register_functions - if (zend_hash_update(EG(function_table), YAF_SPL_AUTOLOAD_REGISTER_NAME, + //zend_register_functions + if (zend_hash_update(EG(function_table), YAF_SPL_AUTOLOAD_REGISTER_NAME, sizeof(YAF_SPL_AUTOLOAD_REGISTER_NAME), &override_function, sizeof(zend_function), (void **)®_function) == FAILURE) { YAF_DEBUG("register autoload failed"); - //no big deal + //no big deal } } }}} */ @@ -133,7 +169,7 @@ inline int yaf_loader_is_category(char *class, uint class_len, char *category, u uint separator_len = strlen(YAF_G(name_separator)); if (YAF_G(name_suffix)) { - if (strncmp(class + class_len - category_len, category, category_len) == 0) { + if (class_len > category_len && strncmp(class + class_len - category_len, category, category_len) == 0) { if (!separator_len || strncmp(class + class_len - category_len - separator_len, YAF_G(name_separator), separator_len) == 0) { return 1; } @@ -168,13 +204,13 @@ int yaf_loader_is_local_namespace(yaf_loader_t *loader, char *class_name, int le if (pos) { prefix_len = pos - class_name; prefix = estrndup(class_name, prefix_len); - } + } #ifdef YAF_HAVE_NAMESPACE else if ((pos = strstr(class_name, "\\"))) { prefix_len = pos - class_name; prefix = estrndup(class_name, prefix_len); } -#endif +#endif if (!prefix_len) { efree(prefix); @@ -204,15 +240,30 @@ yaf_loader_t * yaf_loader_instance(yaf_loader_t *this_ptr, char *library_path, c instance = zend_read_static_property(yaf_loader_ce, ZEND_STRL(YAF_LOADER_PROPERTY_NAME_INSTANCE), 1 TSRMLS_CC); - if (IS_OBJECT == Z_TYPE_P(instance) - && instanceof_function(Z_OBJCE_P(instance), yaf_loader_ce TSRMLS_CC)) { + if (IS_OBJECT == Z_TYPE_P(instance)) { + /* unecessary since there is no set_router things + && instanceof_function(Z_OBJCE_P(instance), yaf_loader_ce TSRMLS_CC)) { + */ + if (library_path) { + MAKE_STD_ZVAL(library); + ZVAL_STRING(library, library_path, 1); + zend_update_property(yaf_loader_ce, instance, ZEND_STRL(YAF_LOADER_PROPERTY_NAME_LIBRARY), library TSRMLS_CC); + zval_ptr_dtor(&library); + } + + if (global_path) { + MAKE_STD_ZVAL(glibrary); + ZVAL_STRING(glibrary, global_path, 1); + zend_update_property(yaf_loader_ce, instance, ZEND_STRL(YAF_LOADER_PROPERTY_NAME_GLOBAL_LIB), glibrary TSRMLS_CC); + zval_ptr_dtor(&glibrary); + } return instance; } if (!global_path && !library_path) { return NULL; } - + if (this_ptr) { instance = this_ptr; } else { @@ -408,7 +459,7 @@ int yaf_internal_autoload(char *file_name, uint name_len, char **directory TSRML if (NULL == library_path) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s requires %s(which set the library_directory) to be initialized first", yaf_loader_ce->name, yaf_application_ce->name); - return 0; + return 0; } smart_str_appendl(&buf, library_path, library_path_len); @@ -438,12 +489,12 @@ int yaf_internal_autoload(char *file_name, uint name_len, char **directory TSRML } else { break; } - } + } if (YAF_G(lowcase_path)) { /* all path of library is lowercase */ zend_str_tolower(buf.c + directory_len, buf.len - directory_len); - } + } smart_str_appendl(&buf, p, strlen(p)); smart_str_appendc(&buf, '.'); @@ -458,16 +509,16 @@ int yaf_internal_autoload(char *file_name, uint name_len, char **directory TSRML status = yaf_loader_import(buf.c, buf.len, 0 TSRMLS_CC); smart_str_free(&buf); - if (!status) + if (!status) return 0; - + return 1; } /* }}} */ -/** {{{ int yaf_loader_register_namespace_single(yaf_loader_t *loader, zval *prefix TSRMLS_DC) +/** {{{ int yaf_loader_register_namespace_single(yaf_loader_t *loader, char *prefix, uint len TSRMLS_DC) */ -int yaf_loader_register_namespace_single(yaf_loader_t *loader, zval *prefix TSRMLS_DC) { +int yaf_loader_register_namespace_single(yaf_loader_t *loader, char *prefix, uint len TSRMLS_DC) { zval *namespaces; smart_str buf = {NULL, 0, 0}; @@ -477,15 +528,16 @@ int yaf_loader_register_namespace_single(yaf_loader_t *loader, zval *prefix TSRM smart_str_appendc(&buf, DEFAULT_DIR_SEPARATOR); } else { smart_str_appendl(&buf, Z_STRVAL_P(namespaces), Z_STRLEN_P(namespaces)); + efree(Z_STRVAL_P(namespaces)); } - smart_str_appendl(&buf, Z_STRVAL_P(prefix), Z_STRLEN_P(prefix)); + smart_str_appendl(&buf, prefix, len); smart_str_appendc(&buf, DEFAULT_DIR_SEPARATOR); ZVAL_STRINGL(namespaces, buf.c, buf.len, 1); smart_str_free(&buf); - + return 1; } /* }}} */ @@ -515,7 +567,7 @@ int yaf_loader_register_namespace_multi(yaf_loader_t *loader, zval *prefixes TSR } else { smart_str_appendl(&buf, Z_STRVAL_PP(ppzval), Z_STRLEN_PP(ppzval)); smart_str_appendc(&buf, DEFAULT_DIR_SEPARATOR); - } + } } ZVAL_STRINGL(namespaces, buf.c, buf.len, 1); @@ -526,7 +578,7 @@ int yaf_loader_register_namespace_multi(yaf_loader_t *loader, zval *prefixes TSR } /* }}} */ -/** {{{ proto private Yaf_Loader::__construct(void) +/** {{{ proto private Yaf_Loader::__construct(void) */ PHP_METHOD(yaf_loader, __construct) { } @@ -560,7 +612,7 @@ PHP_METHOD(yaf_loader, registerLocalNamespace) { } if (IS_STRING == Z_TYPE_P(namespaces)) { - if (yaf_loader_register_namespace_single(getThis(), namespaces TSRMLS_CC)) { + if (yaf_loader_register_namespace_single(getThis(), Z_STRVAL_P(namespaces), Z_STRLEN_P(namespaces) TSRMLS_CC)) { RETURN_ZVAL(getThis(), 1, 0); } } else if (IS_ARRAY == Z_TYPE_P(namespaces)) { @@ -609,15 +661,56 @@ PHP_METHOD(yaf_loader, isLocalName) { } /* }}} */ +/** {{{ proto public Yaf_Loader::setLibraryPath(string $path, $global = FALSE) +*/ +PHP_METHOD(yaf_loader, setLibraryPath) { + char *library; + uint len; + zend_bool global = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &library, &len, &global) == FAILURE) { + return; + } + + if (!global) { + zend_update_property_stringl(yaf_loader_ce, getThis(), ZEND_STRL(YAF_LOADER_PROPERTY_NAME_LIBRARY), library, len TSRMLS_CC); + } else { + zend_update_property_stringl(yaf_loader_ce, getThis(), ZEND_STRL(YAF_LOADER_PROPERTY_NAME_GLOBAL_LIB), library, len TSRMLS_CC); + } + + RETURN_ZVAL(getThis(), 1, 0); +} +/* }}} */ + +/** {{{ proto public Yaf_Loader::getLibraryPath($global = FALSE) +*/ +PHP_METHOD(yaf_loader, getLibraryPath) { + zval *library; + zend_bool global = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &global) == FAILURE) { + return; + } + + if (!global) { + library = zend_read_property(yaf_loader_ce, getThis(), ZEND_STRL(YAF_LOADER_PROPERTY_NAME_LIBRARY), 1 TSRMLS_CC); + } else { + library = zend_read_property(yaf_loader_ce, getThis(), ZEND_STRL(YAF_LOADER_PROPERTY_NAME_GLOBAL_LIB), 1 TSRMLS_CC); + } + + RETURN_ZVAL(library, 1, 0); +} +/* }}} */ + /** {{{ proto public static Yaf_Loader::import($file) */ PHP_METHOD(yaf_loader, import) { char *file; - uint len; + uint len, need_free = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s" ,&file, &len) == FAILURE) { return; - } + } if (!len) { RETURN_FALSE; @@ -632,16 +725,24 @@ PHP_METHOD(yaf_loader, import) { } else { zval *library = zend_read_property(yaf_loader_ce, loader, ZEND_STRL(YAF_LOADER_PROPERTY_NAME_LIBRARY), 1 TSRMLS_CC); len = spprintf(&file, 0, "%s%c%s", Z_STRVAL_P(library), DEFAULT_SLASH, file); + need_free = 1; } } retval = (zend_hash_exists(&EG(included_files), file, len + 1)); - if (retval) { + if (need_free) { + efree(file); + } RETURN_TRUE; } - RETURN_BOOL(yaf_loader_import(file, len, 0 TSRMLS_CC)); + retval = yaf_loader_import(file, len, 0 TSRMLS_CC); + if (need_free) { + efree(file); + } + + RETURN_BOOL(retval); } } /* }}} */ @@ -649,7 +750,7 @@ PHP_METHOD(yaf_loader, import) { /** {{{ proto public Yaf_Loader::autoload($class_name) */ PHP_METHOD(yaf_loader, autoload) { - char *class_name, *app_directory, *directory = NULL, *file_name = NULL; + char *class_name, *origin_classname, *app_directory, *directory = NULL, *file_name = NULL; #ifdef YAF_HAVE_NAMESPACE char *origin_lcname = NULL; #endif @@ -657,12 +758,13 @@ PHP_METHOD(yaf_loader, autoload) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &class_name, &class_name_len) == FAILURE) { return; - } + } separator_len = strlen(YAF_G(name_separator)); app_directory = YAF_G(directory); + origin_classname = class_name; - do { + do { if (!class_name_len) { break; } @@ -710,7 +812,22 @@ PHP_METHOD(yaf_loader, autoload) { } break; - } + } + + if (yaf_loader_is_category(class_name, class_name_len, YAF_LOADER_CONTROLLER, YAF_LOADER_LEN_CONTROLLER TSRMLS_CC)) { + /* this is a controller class */ + spprintf(&directory, 0, "%s/%s", app_directory, YAF_CONTROLLER_DIRECTORY_NAME); + file_name_len = class_name_len - separator_len - YAF_LOADER_LEN_CONTROLLER; + + if (YAF_G(name_suffix)) { + file_name = estrndup(class_name, file_name_len); + } else { + file_name = estrdup(class_name + YAF_LOADER_LEN_CONTROLLER + separator_len); + } + + break; + } + /* {{{ This only effects internally */ if (YAF_G(st_compatible) && (strncmp(class_name, YAF_LOADER_DAO, YAF_LOADER_LEN_DAO) == 0 @@ -726,7 +843,17 @@ PHP_METHOD(yaf_loader, autoload) { } while(0); if (!app_directory && directory) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, + efree(directory); +#ifdef YAF_HAVE_NAMESPACE + if (origin_lcname) { + efree(origin_lcname); + } +#endif + if (file_name != class_name) { + efree(file_name); + } + + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't load a framework MVC class without an %s initializing", yaf_application_ce->name); RETURN_FALSE; } @@ -734,7 +861,7 @@ PHP_METHOD(yaf_loader, autoload) { if (!YAF_G(use_spl_autoload)) { /** directory might be NULL since we passed a NULL */ if (yaf_internal_autoload(file_name, file_name_len, &directory TSRMLS_CC)) { - if (zend_hash_exists(EG(class_table), zend_str_tolower_dup(class_name, class_name_len), class_name_len + 1)) { + if (zend_hash_exists(EG(class_table), zend_str_tolower_dup(origin_classname, class_name_len), class_name_len + 1)) { #ifdef YAF_HAVE_NAMESPACE if (origin_lcname) { efree(origin_lcname); @@ -769,8 +896,9 @@ PHP_METHOD(yaf_loader, autoload) { } RETURN_TRUE; } else { + char *lower_case_name = zend_str_tolower_dup(origin_classname, class_name_len); if (yaf_internal_autoload(file_name, file_name_len, &directory TSRMLS_CC) && - zend_hash_exists(EG(class_table), zend_str_tolower_dup(class_name, class_name_len), class_name_len + 1)) { + zend_hash_exists(EG(class_table), lower_case_name, class_name_len + 1)) { #ifdef YAF_HAVE_NAMESPACE if (origin_lcname) { efree(origin_lcname); @@ -782,6 +910,8 @@ PHP_METHOD(yaf_loader, autoload) { if (file_name != class_name) { efree(file_name); } + + efree(lower_case_name); RETURN_TRUE; } #ifdef YAF_HAVE_NAMESPACE @@ -795,12 +925,13 @@ PHP_METHOD(yaf_loader, autoload) { if (file_name != class_name) { efree(file_name); } + efree(lower_case_name); RETURN_FALSE; } } /* }}} */ -/** {{{ proto public Yaf_Loader::getInstance($library = NULL, $global_library = NULL) +/** {{{ proto public Yaf_Loader::getInstance($library = NULL, $global_library = NULL) */ PHP_METHOD(yaf_loader, getInstance) { char *library = NULL; @@ -810,14 +941,13 @@ PHP_METHOD(yaf_loader, getInstance) { yaf_loader_t *loader; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &library, &library_len, &global, &global_len) == FAILURE) { - loader = yaf_loader_instance(NULL, NULL, NULL TSRMLS_CC); - } else { - loader = yaf_loader_instance(NULL, library, global TSRMLS_CC); - } + return; + } + loader = yaf_loader_instance(NULL, library, global TSRMLS_CC); if (loader) RETURN_ZVAL(loader, 1, 0); - + RETURN_FALSE; } /* }}} */ @@ -836,20 +966,22 @@ PHP_FUNCTION(yaf_override_spl_autoload) { } /* }}} */ -/** {{{ yaf_loader_methods +/** {{{ yaf_loader_methods */ zend_function_entry yaf_loader_methods[] = { - PHP_ME(yaf_loader, __construct, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR) + PHP_ME(yaf_loader, __construct, yaf_loader_void_arginfo, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR) PHP_ME(yaf_loader, __clone, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_CLONE) PHP_ME(yaf_loader, __sleep, NULL, ZEND_ACC_PRIVATE) - PHP_ME(yaf_loader, __wakeup, NULL, ZEND_ACC_PRIVATE) - PHP_ME(yaf_loader, autoload, NULL, ZEND_ACC_PUBLIC) - PHP_ME(yaf_loader, getInstance, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_ME(yaf_loader, registerLocalNamespace, NULL, ZEND_ACC_PUBLIC) - PHP_ME(yaf_loader, getLocalNamespace, NULL, ZEND_ACC_PUBLIC) - PHP_ME(yaf_loader, clearLocalNamespace, NULL, ZEND_ACC_PUBLIC) - PHP_ME(yaf_loader, isLocalName, NULL, ZEND_ACC_PUBLIC) - PHP_ME(yaf_loader, import, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(yaf_loader, __wakeup, NULL, ZEND_ACC_PRIVATE) + PHP_ME(yaf_loader, autoload, yaf_loader_autoloader_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(yaf_loader, getInstance, yaf_loader_getinstance_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(yaf_loader, registerLocalNamespace, yaf_loader_regnamespace_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(yaf_loader, getLocalNamespace, yaf_loader_void_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(yaf_loader, clearLocalNamespace, yaf_loader_void_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(yaf_loader, isLocalName, yaf_loader_islocalname_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(yaf_loader, import, yaf_loader_import_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(yaf_loader, setLibraryPath, yaf_loader_setlib_arginfo, ZEND_ACC_PUBLIC) + PHP_ME(yaf_loader, getLibraryPath, yaf_loader_getlib_arginfo, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* }}} */ diff --git a/yaf_loader.h b/yaf_loader.h index 92d55389..fe93260f 100644 --- a/yaf_loader.h +++ b/yaf_loader.h @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_loader.h 315615 2011-08-27 14:14:48Z laruence $ */ + +/* $Id: yaf_loader.h 324659 2012-03-31 09:01:41Z laruence $ */ #ifndef YAF_LOADER_H #define YAF_LOADER_H @@ -23,7 +23,7 @@ #define YAF_DEFAULT_LIBRARY_EXT YAF_DEFAULT_CONTROLLER_EXT #define YAF_LIBRARY_DIRECTORY_NAME "library" -#define YAF_CONTROLLER_DIRECTORY_NAME "controller" +#define YAF_CONTROLLER_DIRECTORY_NAME "controllers" #define YAF_PLUGIN_DIRECTORY_NAME "plugins" #define YAF_MODULE_DIRECTORY_NAME "modules" #define YAF_VIEW_DIRECTORY_NAME "views" @@ -45,7 +45,7 @@ /* {{{ This only effects internally */ #define YAF_LOADER_DAO "Dao_" -#define YAF_LOADER_LEN_DAO 4 +#define YAF_LOADER_LEN_DAO 4 #define YAF_LOADER_SERVICE "Service_" #define YAF_LOADER_LEN_SERVICE 8 /* }}} */ @@ -53,7 +53,7 @@ #define YAF_LOADER_PROPERTY_NAME_LIBRARY "_library" #define YAF_LOADER_PROPERTY_NAME_GLOBAL_LIB "_global_library" -#if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION > 2)) || (PHP_MAJOR_VERSION > 5) +#if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION > 2)) || (PHP_MAJOR_VERSION > 5) #define YAF_STORE_EG_ENVIRON() \ { \ zval ** __old_return_value_pp = EG(return_value_ptr_ptr); \ @@ -90,6 +90,7 @@ int yaf_internal_autoload(char *file_name, uint name_len, char **directory TSRML int yaf_loader_import(char *path, int len, int use_path TSRMLS_DC); int yaf_loader_compose(char *path, int len, int use_path TSRMLS_DC); int yaf_register_autoloader(yaf_loader_t *loader TSRMLS_DC); +int yaf_loader_register_namespace_single(yaf_loader_t *loader, char *prefix, uint len TSRMLS_DC); yaf_loader_t * yaf_loader_instance(yaf_loader_t *this_ptr, char *library_path, char *global_path TSRMLS_DC); extern PHPAPI int php_stream_open_for_zend_ex(const char *filename, zend_file_handle *handle, int mode TSRMLS_DC); diff --git a/yaf_logo.h b/yaf_logo.h index 72bdadcc..63464e3b 100644 --- a/yaf_logo.h +++ b/yaf_logo.h @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_logo.h 315615 2011-08-27 14:14:48Z laruence $ */ + +/* $Id: yaf_logo.h 321289 2011-12-21 02:53:29Z laruence $ */ #ifndef YAF_LOGO_H #define YAF_LOGO_H diff --git a/yaf_namespace.h b/yaf_namespace.h index f82c7781..40df2c98 100644 --- a/yaf_namespace.h +++ b/yaf_namespace.h @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_namespace.h 315615 2011-08-27 14:14:48Z laruence $ */ + +/* $Id: yaf_namespace.h 321289 2011-12-21 02:53:29Z laruence $ */ #ifndef YAF_NAMESPACE_H #define YAF_NAMESPACE_H @@ -39,7 +39,7 @@ #endif #define namespace_switch(n) (n) -#define YAF_INIT_CLASS_ENTRY(ce, name, name_ns, methods) INIT_CLASS_ENTRY(ce, name, methods) +#define YAF_INIT_CLASS_ENTRY(ce, name, name_ns, methods) INIT_CLASS_ENTRY(ce, name, methods) #define YAF_BEGIN_ARG_INFO static ZEND_BEGIN_ARG_INFO #define YAF_BEGIN_ARG_INFO_EX static ZEND_BEGIN_ARG_INFO_EX diff --git a/yaf_plugin.c b/yaf_plugin.c index 3e1c61fb..50aadabe 100644 --- a/yaf_plugin.c +++ b/yaf_plugin.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_plugin.c 318209 2011-10-19 07:04:34Z laruence $ */ + +/* $Id: yaf_plugin.c 321289 2011-12-21 02:53:29Z laruence $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -100,7 +100,7 @@ PHP_METHOD(yaf_plugin, preResponse) { } /* }}} */ -/** {{{ yaf_plugin_methods +/** {{{ yaf_plugin_methods */ zend_function_entry yaf_plugin_methods[] = { PHP_ME(yaf_plugin, routerStartup, plugin_arg, ZEND_ACC_PUBLIC) @@ -127,7 +127,7 @@ zend_function_entry yaf_plugin_methods_ns[] = { #endif /* }}} */ -/** {{{ YAF_STARTUP_FUNCTION +/** {{{ YAF_STARTUP_FUNCTION */ YAF_STARTUP_FUNCTION(plugin) { zend_class_entry ce; diff --git a/yaf_plugin.h b/yaf_plugin.h index 967fc942..f4837116 100644 --- a/yaf_plugin.h +++ b/yaf_plugin.h @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_plugin.h 315615 2011-08-27 14:14:48Z laruence $ */ + +/* $Id: yaf_plugin.h 321289 2011-12-21 02:53:29Z laruence $ */ #ifndef YAF_PLUGIN_H #define YAF_PLUGIN_H diff --git a/yaf_registry.c b/yaf_registry.c index 276f9ec6..8e0f0647 100644 --- a/yaf_registry.c +++ b/yaf_registry.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_registry.c 315957 2011-09-01 09:03:32Z laruence $ */ + +/* $Id: yaf_registry.c 321289 2011-12-21 02:53:29Z laruence $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -54,7 +54,7 @@ ZEND_END_ARG_INFO() */ yaf_registry_t *yaf_registry_instance(yaf_registry_t *this_ptr TSRMLS_DC) { yaf_registry_t *instance = zend_read_static_property(yaf_registry_ce, ZEND_STRL(YAF_REGISTRY_PROPERTY_NAME_INSTANCE), 1 TSRMLS_CC); - + if (Z_TYPE_P(instance) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(instance), yaf_registry_ce TSRMLS_CC)) { zval *regs; @@ -104,7 +104,7 @@ PHP_METHOD(yaf_registry, get) { uint len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len) == FAILURE) { return; - } else { + } else { zval **ppzval, *entrys; yaf_registry_t *registry; @@ -116,7 +116,7 @@ PHP_METHOD(yaf_registry, get) { RETURN_ZVAL(*ppzval, 1, 0); } } - } + } RETURN_NULL(); } @@ -177,7 +177,7 @@ PHP_METHOD(yaf_registry, has) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len) == FAILURE) { return; } else { - RETURN_BOOL(yaf_registry_is_set(name, len TSRMLS_CC)); + RETURN_BOOL(yaf_registry_is_set(name, len TSRMLS_CC)); } } /* }}} */ @@ -190,7 +190,7 @@ PHP_METHOD(yaf_registry, getInstance) { } /* }}} */ -/** {{{ yaf_registry_methods +/** {{{ yaf_registry_methods */ zend_function_entry yaf_registry_methods[] = { PHP_ME(yaf_registry, __construct, NULL, ZEND_ACC_CTOR|ZEND_ACC_PRIVATE) @@ -215,7 +215,7 @@ YAF_STARTUP_FUNCTION(registry) { zend_declare_property_null(yaf_registry_ce, ZEND_STRL(YAF_REGISTRY_PROPERTY_NAME_INSTANCE), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); zend_declare_property_null(yaf_registry_ce, ZEND_STRL(YAF_REGISTRY_PROPERTY_NAME_ENTRYS), ZEND_ACC_PROTECTED TSRMLS_CC); - + return SUCCESS; } /* }}} */ diff --git a/yaf_registry.h b/yaf_registry.h index 0af0e4ec..1f75ef08 100644 --- a/yaf_registry.h +++ b/yaf_registry.h @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_registry.h 315615 2011-08-27 14:14:48Z laruence $ */ + +/* $Id: yaf_registry.h 321289 2011-12-21 02:53:29Z laruence $ */ #ifndef YAF_REGISTRY_H #define YAF_REGISTRY_H diff --git a/yaf_request.c b/yaf_request.c index 834aa85c..3539a7ed 100644 --- a/yaf_request.c +++ b/yaf_request.c @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: yaf_request.c 315957 2011-09-01 09:03:32Z laruence $*/ +/* $Id: yaf_request.c 324673 2012-04-01 08:51:22Z laruence $*/ #ifdef HAVE_CONFIG_H #include "config.h" @@ -122,17 +122,19 @@ int yaf_request_set_base_uri(yaf_request_t *request, char *base_uri, char *reque char *script; size_t script_len; - php_basename(Z_STRVAL_P(script_name), Z_STRLEN_P(script_name), + php_basename(Z_STRVAL_P(script_name), Z_STRLEN_P(script_name), NULL, 0, &script, &script_len TSRMLS_CC); if (strncmp(file_name, script, file_name_len) == 0) { basename = Z_STRVAL_P(script_name); basename_len = Z_STRLEN_P(script_name); + efree(file_name); efree(script); break; } efree(script); } + efree(file_name); phpself_name = yaf_request_query(YAF_GLOBAL_VARS_SERVER, ZEND_STRL("PHP_SELF") TSRMLS_CC); if (phpself_name && IS_STRING == Z_TYPE_P(phpself_name)) { @@ -178,7 +180,7 @@ int yaf_request_set_base_uri(yaf_request_t *request, char *base_uri, char *reque dir_len = php_dirname(basename, basename_len); if (*(basename + dir_len - 1) == '/') { --dir_len; - } + } if (dir_len) { dir = estrndup(basename, dir_len); @@ -225,13 +227,13 @@ zval * yaf_request_query(uint type, char * name, uint len TSRMLS_DC) { case YAF_GLOBAL_VARS_SERVER: if (jit_initialization) { zend_is_auto_global(ZEND_STRL("_SERVER") TSRMLS_CC); - } + } (void)zend_hash_find(&EG(symbol_table), ZEND_STRS("_SERVER"), (void **)&carrier); break; case YAF_GLOBAL_VARS_ENV: if (jit_initialization) { zend_is_auto_global(ZEND_STRL("_ENV") TSRMLS_CC); - } + } carrier = &PG(http_globals)[YAF_GLOBAL_VARS_ENV]; break; case YAF_GLOBAL_VARS_FILES: @@ -240,13 +242,13 @@ zval * yaf_request_query(uint type, char * name, uint len TSRMLS_DC) { case YAF_GLOBAL_VARS_REQUEST: if (jit_initialization) { zend_is_auto_global(ZEND_STRL("_REQUEST") TSRMLS_CC); - } + } (void)zend_hash_find(&EG(symbol_table), ZEND_STRS("_REQUEST"), (void **)&carrier); break; default: break; } -#else +#else switch (type) { case YAF_GLOBAL_VARS_POST: case YAF_GLOBAL_VARS_GET: @@ -257,19 +259,19 @@ zval * yaf_request_query(uint type, char * name, uint len TSRMLS_DC) { case YAF_GLOBAL_VARS_ENV: if (jit_initialization) { zend_is_auto_global(ZEND_STRL("_ENV") TSRMLS_CC); - } + } carrier = &PG(http_globals)[type]; break; case YAF_GLOBAL_VARS_SERVER: if (jit_initialization) { zend_is_auto_global(ZEND_STRL("_SERVER") TSRMLS_CC); - } + } carrier = &PG(http_globals)[type]; break; case YAF_GLOBAL_VARS_REQUEST: if (jit_initialization) { zend_is_auto_global(ZEND_STRL("_REQUEST") TSRMLS_CC); - } + } (void)zend_hash_find(&EG(symbol_table), ZEND_STRS("_REQUEST"), (void **)&carrier); break; default: @@ -295,14 +297,14 @@ zval * yaf_request_query(uint type, char * name, uint len TSRMLS_DC) { ZVAL_NULL(empty); return empty; } - + Z_ADDREF_P(*ret); return *ret; } /* }}} */ /** {{{inline yaf_request_t * yaf_request_get_method(yaf_request_t *request TSRMLS_DC) -*/ +*/ inline yaf_request_t * yaf_request_get_method(yaf_request_t *request TSRMLS_DC) { yaf_request_t *method = zend_read_property(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_METHOD), 1 TSRMLS_CC); return method; @@ -470,7 +472,7 @@ YAF_REQUEST_IS_METHOD(Options); YAF_REQUEST_IS_METHOD(Cli); /* }}} */ -/** {{{ proto public Yaf_Request_Abstract::isXmlHttpRequest(void) +/** {{{ proto public Yaf_Request_Abstract::isXmlHttpRequest(void) */ PHP_METHOD(yaf_request, isXmlHttpRequest) { RETURN_FALSE; @@ -487,7 +489,7 @@ YAF_REQUEST_METHOD(yaf_request, Env, YAF_GLOBAL_VARS_ENV); YAF_REQUEST_METHOD(yaf_request, Server, YAF_GLOBAL_VARS_SERVER); /* }}} */ -/** {{{ proto public Yaf_Request_Abstract::getModuleName(void) +/** {{{ proto public Yaf_Request_Abstract::getModuleName(void) */ PHP_METHOD(yaf_request, getModuleName) { zval *module = zend_read_property(yaf_request_ce, getThis(), ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_MODULE), 1 TSRMLS_CC); @@ -495,7 +497,7 @@ PHP_METHOD(yaf_request, getModuleName) { } /* }}} */ -/** {{{ proto public Yaf_Request_Abstract::getControllerName(void) +/** {{{ proto public Yaf_Request_Abstract::getControllerName(void) */ PHP_METHOD(yaf_request, getControllerName) { zval *controller = zend_read_property(yaf_request_ce, getThis(), ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_CONTROLLER), 1 TSRMLS_CC); @@ -503,7 +505,7 @@ PHP_METHOD(yaf_request, getControllerName) { } /* }}} */ -/** {{{ proto public Yaf_Request_Abstract::getActionName(void) +/** {{{ proto public Yaf_Request_Abstract::getActionName(void) */ PHP_METHOD(yaf_request, getActionName) { zval *action = zend_read_property(yaf_request_ce, getThis(), ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_ACTION), 1 TSRMLS_CC); @@ -511,7 +513,7 @@ PHP_METHOD(yaf_request, getActionName) { } /* }}} */ -/** {{{ proto public Yaf_Request_Abstract::setModuleName(string $module) +/** {{{ proto public Yaf_Request_Abstract::setModuleName(string $module) */ PHP_METHOD(yaf_request, setModuleName) { zval *module; @@ -519,7 +521,7 @@ PHP_METHOD(yaf_request, setModuleName) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &module) == FAILURE) { return; - } + } if (Z_TYPE_P(module) != IS_STRING) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expect a string module name"); @@ -532,7 +534,7 @@ PHP_METHOD(yaf_request, setModuleName) { } /* }}} */ -/** {{{ proto public Yaf_Request_Abstract::setControllerName(string $controller) +/** {{{ proto public Yaf_Request_Abstract::setControllerName(string $controller) */ PHP_METHOD(yaf_request, setControllerName) { zval *controller; @@ -540,7 +542,7 @@ PHP_METHOD(yaf_request, setControllerName) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &controller) == FAILURE) { return; - } + } if (Z_TYPE_P(controller) != IS_STRING) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expect a string controller name"); @@ -553,7 +555,7 @@ PHP_METHOD(yaf_request, setControllerName) { } /* }}} */ -/** {{{ proto public Yaf_Request_Abstract::setActionName(string $action) +/** {{{ proto public Yaf_Request_Abstract::setActionName(string $action) */ PHP_METHOD(yaf_request, setActionName) { zval *action; @@ -561,7 +563,7 @@ PHP_METHOD(yaf_request, setActionName) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &action) == FAILURE) { return; - } + } if (Z_TYPE_P(action) != IS_STRING) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expect a string action name"); @@ -586,19 +588,19 @@ PHP_METHOD(yaf_request, setParam) { zval *value ; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) == FAILURE) { return; - } + } if (value && Z_TYPE_P(value) == IS_ARRAY) { if (yaf_request_set_params_multi(self, value TSRMLS_CC)) { RETURN_ZVAL(self, 1, 0); } - } + } } else if (2 == argc) { zval *value; char *name; uint len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len, &value) == FAILURE) { return; - } + } if (yaf_request_set_params_single(getThis(), name, len, value TSRMLS_CC)) { RETURN_ZVAL(self, 1, 0); @@ -639,7 +641,7 @@ PHP_METHOD(yaf_request, getParam) { PHP_METHOD(yaf_request, getException) { zval *exception = zend_read_property(yaf_request_ce, getThis(), ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_EXCEPTION), 1 TSRMLS_CC); if (IS_OBJECT == Z_TYPE_P(exception) - && instanceof_function(Z_OBJCE_P(exception), + && instanceof_function(Z_OBJCE_P(exception), #if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 2) zend_exception_get_default() #else @@ -698,7 +700,7 @@ PHP_METHOD(yaf_request, setBaseUri) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &uri) == FAILURE) { return; - } + } if (Z_TYPE_P(uri) != IS_STRING || !Z_STRLEN_P(uri)) { RETURN_FALSE; @@ -736,14 +738,14 @@ PHP_METHOD(yaf_request, setRequestUri) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &uri, &len) == FAILURE) { return; - } + } zend_update_property_stringl(yaf_request_ce, getThis(), ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_URI), uri, len TSRMLS_CC); RETURN_ZVAL(getThis(), 1, 0); } /* }}} */ -/** {{{ proto public Yaf_Request_Abstract::isRouted(void) +/** {{{ proto public Yaf_Request_Abstract::isRouted(void) */ PHP_METHOD(yaf_request, isRouted) { RETURN_BOOL(yaf_request_is_routed(getThis() TSRMLS_CC)); diff --git a/yaf_request.h b/yaf_request.h index c74e0381..8ad40905 100644 --- a/yaf_request.h +++ b/yaf_request.h @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_request.h 315620 2011-08-27 16:47:56Z laruence $ */ + +/* $Id: yaf_request.h 321289 2011-12-21 02:53:29Z laruence $ */ #ifndef YAF_REQUEST_H #define YAF_REQUEST_H diff --git a/yaf_response.c b/yaf_response.c index 375c95db..bdbe1470 100644 --- a/yaf_response.c +++ b/yaf_response.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_response.c 315957 2011-09-01 09:03:32Z laruence $ */ + +/* $Id: yaf_response.c 324384 2012-03-20 11:50:17Z laruence $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -54,7 +54,7 @@ yaf_response_t * yaf_response_instance(yaf_response_t *this_ptr, char *sapi_name MAKE_STD_ZVAL(instance); object_init_ex(instance, ce); } - + MAKE_STD_ZVAL(header); array_init(header); zend_update_property(ce, instance, ZEND_STRL(YAF_RESPONSE_PROPERTY_NAME_HEADER), header TSRMLS_CC); @@ -94,9 +94,9 @@ static int yaf_response_set_body(yaf_response_t *response, char *name, int name_ #endif /* }}} */ -/** {{{ int yaf_response_alter_body(yaf_response_t *response, char *name, int name_len, char *body, long body_len, int prepend TSRMLS_DC) +/** {{{ int yaf_response_alter_body(yaf_response_t *response, char *name, int name_len, char *body, long body_len, int flag TSRMLS_DC) */ -int yaf_response_alter_body(yaf_response_t *response, char *name, int name_len, char *body, long body_len, int prepend TSRMLS_DC) { +int yaf_response_alter_body(yaf_response_t *response, char *name, int name_len, char *body, long body_len, int flag TSRMLS_DC) { zval *zbody; char *obody; @@ -106,11 +106,18 @@ int yaf_response_alter_body(yaf_response_t *response, char *name, int name_len, zbody = zend_read_property(yaf_response_ce, response, ZEND_STRL(YAF_RESPONSE_PROPERTY_NAME_BODY), 1 TSRMLS_CC); obody = Z_STRVAL_P(zbody); - - if (prepend) { - Z_STRLEN_P(zbody) = spprintf(&Z_STRVAL_P(zbody), 0, "%s%s", body, obody); - } else { - Z_STRLEN_P(zbody) = spprintf(&Z_STRVAL_P(zbody), 0, "%s%s", obody, body); + + switch (flag) { + case YAF_RESPONSE_PREPEND: + Z_STRLEN_P(zbody) = spprintf(&Z_STRVAL_P(zbody), 0, "%s%s", body, obody); + break; + case YAF_RESPONSE_APPEND: + Z_STRLEN_P(zbody) = spprintf(&Z_STRVAL_P(zbody), 0, "%s%s", obody, body); + break; + case YAF_RESPONSE_REPLACE: + default: + ZVAL_STRINGL(zbody, body, body_len, 1); + break; } efree(obody); @@ -165,7 +172,7 @@ zval * yaf_response_get_body(yaf_response_t *response TSRMLS_DC) { } /* }}} */ -/** {{{ proto private Yaf_Response_Abstract::__construct() +/** {{{ proto private Yaf_Response_Abstract::__construct() */ PHP_METHOD(yaf_response, __construct) { (void)yaf_response_instance(getThis(), sapi_module.name TSRMLS_CC); @@ -184,14 +191,14 @@ PHP_METHOD(yaf_response, appendBody) { char *body, *name = NULL; uint body_len, name_len = 0; yaf_response_t *self; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &body, &body_len, &name, &name_len) == FAILURE) { return; } self = getThis(); - if (yaf_response_alter_body(self, name, name_len, body, body_len, 0 TSRMLS_CC)) { + if (yaf_response_alter_body(self, name, name_len, body, body_len, YAF_RESPONSE_APPEND TSRMLS_CC)) { RETURN_ZVAL(self, 1, 0); } @@ -205,14 +212,14 @@ PHP_METHOD(yaf_response, prependBody) { char *body, *name = NULL; uint body_len, name_len = 0; yaf_response_t *self; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &body, &body_len, &name, &name_len) == FAILURE) { return; } self = getThis(); - if (yaf_response_alter_body(self, name, name_len, body, body_len, 1 TSRMLS_CC)) { + if (yaf_response_alter_body(self, name, name_len, body, body_len, YAF_RESPONSE_PREPEND TSRMLS_CC)) { RETURN_ZVAL(self, 1, 0); } @@ -256,7 +263,7 @@ PHP_METHOD(yaf_response, setRedirect) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &url, &url_len) == FAILURE) { return; - } + } if (!url_len) { RETURN_FALSE; @@ -272,14 +279,14 @@ PHP_METHOD(yaf_response, setBody) { char *body, *name = NULL; uint body_len, name_len = 0; yaf_response_t *self; - + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &body, &body_len, &name, &name_len) == FAILURE) { return; } self = getThis(); - if (yaf_response_alter_body(self, name, name_len, body, body_len, 0 TSRMLS_CC)) { + if (yaf_response_alter_body(self, name, name_len, body, body_len, YAF_RESPONSE_REPLACE TSRMLS_CC)) { RETURN_ZVAL(self, 1, 0); } @@ -304,7 +311,7 @@ PHP_METHOD(yaf_response, getBody) { zval *body; body = yaf_response_get_body(getThis() TSRMLS_CC); - + RETURN_ZVAL(body, 1, 0); } /* }}} */ @@ -330,11 +337,11 @@ PHP_METHOD(yaf_response, __clone) { } /* }}} */ -/** {{{ yaf_response_methods +/** {{{ yaf_response_methods */ zend_function_entry yaf_response_methods[] = { - PHP_ME(yaf_response, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) - PHP_ME(yaf_response, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR) + PHP_ME(yaf_response, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(yaf_response, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR) PHP_ME(yaf_response, __clone, NULL, ZEND_ACC_PRIVATE) PHP_ME(yaf_response, __toString, NULL, ZEND_ACC_PRIVATE) PHP_ME(yaf_response, setBody, NULL, ZEND_ACC_PUBLIC) @@ -345,7 +352,7 @@ zend_function_entry yaf_response_methods[] = { PHP_ME(yaf_response, setHeader, NULL, ZEND_ACC_PUBLIC) PHP_ME(yaf_response, setAllHeaders, NULL, ZEND_ACC_PROTECTED) PHP_ME(yaf_response, getHeader, NULL, ZEND_ACC_PUBLIC) - PHP_ME(yaf_response, clearHeaders, NULL, ZEND_ACC_PUBLIC) + PHP_ME(yaf_response, clearHeaders, NULL, ZEND_ACC_PUBLIC) PHP_ME(yaf_response, setRedirect, NULL, ZEND_ACC_PUBLIC) PHP_ME(yaf_response, response, NULL, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} diff --git a/yaf_response.h b/yaf_response.h index 4d7231da..68d0b6c7 100644 --- a/yaf_response.h +++ b/yaf_response.h @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_response.h 315615 2011-08-27 14:14:48Z laruence $ */ + +/* $Id: yaf_response.h 324384 2012-03-20 11:50:17Z laruence $ */ #ifndef PHP_YAF_RESPONSE_H #define PHP_YAF_RESPONSE_H @@ -24,12 +24,16 @@ #define YAF_RESPONSE_PROPERTY_NAME_HEADEREXCEPTION "_sendheader" #define YAF_RESPONSE_PROPERTY_NAME_RESPONSECODE "_response_code" +#define YAF_RESPONSE_REPLACE 0 +#define YAF_RESPONSE_PREPEND 1 +#define YAF_RESPONSE_APPEND 2 + extern zend_class_entry *yaf_response_ce; extern zend_class_entry *yaf_response_http_ce; extern zend_class_entry *yaf_response_cli_ce; yaf_response_t * yaf_response_instance(yaf_response_t *this_ptr, char *sapi_name TSRMLS_DC); -int yaf_response_alter_body(yaf_response_t *response, char *name, int name_len, char *body, long body_len, int prepend TSRMLS_DC); +int yaf_response_alter_body(yaf_response_t *response, char *name, int name_len, char *body, long body_len, int flag TSRMLS_DC); int yaf_response_send(yaf_response_t *response TSRMLS_DC); int yaf_response_set_redirect(yaf_response_t *response, char *url, int len TSRMLS_DC); int yaf_response_clear_body(yaf_response_t *response TSRMLS_DC); diff --git a/yaf_router.c b/yaf_router.c index d66be9d4..acdba0bd 100644 --- a/yaf_router.c +++ b/yaf_router.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_router.c 315957 2011-09-01 09:03:32Z laruence $ */ + +/* $Id: yaf_router.c 324890 2012-04-06 05:46:43Z laruence $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -42,9 +42,9 @@ zend_class_entry *yaf_router_ce; */ yaf_router_t * yaf_router_instance(yaf_router_t *this_ptr TSRMLS_DC) { zval *routes; - yaf_router_t *instance; + yaf_router_t *instance; yaf_route_t *route; - + if (this_ptr) { instance = this_ptr; } else { @@ -55,8 +55,17 @@ yaf_router_t * yaf_router_instance(yaf_router_t *this_ptr TSRMLS_DC) { MAKE_STD_ZVAL(routes); array_init(routes); - MAKE_STD_ZVAL(route); - object_init_ex(route, yaf_route_static_ce); + if (!YAF_G(default_route)) { +static_route: + MAKE_STD_ZVAL(route); + object_init_ex(route, yaf_route_static_ce); + } else { + route = yaf_route_instance(NULL, YAF_G(default_route) TSRMLS_CC); + if (!route) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to initialize default route, use %s instead", yaf_route_static_ce->name); + goto static_route; + } + } zend_hash_update(Z_ARRVAL_P(routes), "_default", sizeof("_default"), (void **)&route, sizeof(zval *), NULL); zend_update_property(yaf_router_ce, instance, ZEND_STRL(YAF_ROUTER_PROPERTY_NAME_ROUTERS), routes TSRMLS_CC); @@ -108,7 +117,7 @@ int yaf_router_route(yaf_router_t *router, yaf_request_t *request TSRMLS_DC) { zval_ptr_dtor(&ret); return 1; } - } + } return 0; } /* }}} */ @@ -161,7 +170,7 @@ int yaf_router_add_config(yaf_router_t *router, zval *configs TSRMLS_DC) { default: continue; } - } + } return 1; } } @@ -245,7 +254,7 @@ PHP_METHOD(yaf_router, addRoute) { routes = zend_read_property(yaf_router_ce, getThis(), ZEND_STRL(YAF_ROUTER_PROPERTY_NAME_ROUTERS), 1 TSRMLS_CC); - Z_ADDREF_P(route); + Z_ADDREF_P(route); zend_hash_update(Z_ARRVAL_P(routes), name, len + 1, (void **)&route, sizeof(zval *), NULL); RETURN_ZVAL(getThis(), 1, 0); @@ -296,7 +305,7 @@ PHP_METHOD(yaf_router, getRoute) { } routes = zend_read_property(yaf_router_ce, getThis(), ZEND_STRL(YAF_ROUTER_PROPERTY_NAME_ROUTERS), 1 TSRMLS_CC); - + if (zend_hash_find(Z_ARRVAL_P(routes), name, len + 1, (void **)&route) == SUCCESS) { RETURN_ZVAL(*route, 1, 0); } @@ -309,11 +318,11 @@ PHP_METHOD(yaf_router, getRoute) { */ PHP_METHOD(yaf_router, getRoutes) { zval * routes = zend_read_property(yaf_router_ce, getThis(), ZEND_STRL(YAF_ROUTER_PROPERTY_NAME_ROUTERS), 1 TSRMLS_CC); - RETURN_ZVAL(routes, 1, 0); + RETURN_ZVAL(routes, 1, 0); } /* }}} */ -/** {{{ proto public Yaf_Router::isModuleName(string $name) +/** {{{ proto public Yaf_Router::isModuleName(string $name) */ PHP_METHOD(yaf_router, isModuleName) { char *name; @@ -331,7 +340,7 @@ PHP_METHOD(yaf_router, isModuleName) { */ PHP_METHOD(yaf_router, getCurrentRoute) { zval *route = zend_read_property(yaf_router_ce, getThis(), ZEND_STRL(YAF_ROUTER_PROPERTY_NAME_CURRENT_ROUTE), 1 TSRMLS_CC); - RETURN_ZVAL(route, 1, 0); + RETURN_ZVAL(route, 1, 0); } /* }}} */ diff --git a/yaf_router.h b/yaf_router.h index 4e0e6985..3f206351 100644 --- a/yaf_router.h +++ b/yaf_router.h @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_router.h 315615 2011-08-27 14:14:48Z laruence $ */ + +/* $Id: yaf_router.h 321289 2011-12-21 02:53:29Z laruence $ */ #ifndef YAF_ROUTER_H #define YAF_ROUTER_H diff --git a/yaf_session.c b/yaf_session.c index d540c36e..6ee89664 100644 --- a/yaf_session.c +++ b/yaf_session.c @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: yaf_session.c 315839 2011-08-31 02:46:49Z laruence $ */ +/* $Id: yaf_session.c 321289 2011-12-21 02:53:29Z laruence $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -59,7 +59,7 @@ ZEND_BEGIN_ARG_INFO_EX(yaf_session_set_arginfo, 0, 0, 2) ZEND_END_ARG_INFO() /* }}} */ -/** {{{ inline int yaf_session_start(yaf_session_t *session TSRMLS_DC) +/** {{{ inline int yaf_session_start(yaf_session_t *session TSRMLS_DC) */ inline int yaf_session_start(yaf_session_t *session TSRMLS_DC) { zval *status; @@ -80,7 +80,7 @@ inline int yaf_session_start(yaf_session_t *session TSRMLS_DC) { static yaf_session_t * yaf_session_instance(TSRMLS_D) { yaf_session_t *instance; zval **sess, *member; - zend_object *obj; + zend_object *obj; zend_property_info *property_info; MAKE_STD_ZVAL(instance); @@ -154,7 +154,7 @@ PHP_METHOD(yaf_session, __clone) { */ PHP_METHOD(yaf_session, getInstance) { yaf_session_t *instance = zend_read_static_property(yaf_session_ce, ZEND_STRL(YAF_SESSION_PROPERTY_NAME_INSTANCE), 1 TSRMLS_CC); - + if (Z_TYPE_P(instance) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(instance), yaf_session_ce TSRMLS_CC)) { if ((instance = yaf_session_instance(TSRMLS_C))) { RETURN_ZVAL(instance, 1, 1); @@ -190,7 +190,7 @@ PHP_METHOD(yaf_session, get) { int len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &len) == FAILURE) { WRONG_PARAM_COUNT; - } else { + } else { zval **ret, *sess; sess = zend_read_property(yaf_session_ce, getThis(), ZEND_STRL(YAF_SESSION_PROPERTY_NAME_SESSION), 1 TSRMLS_CC); @@ -203,7 +203,7 @@ PHP_METHOD(yaf_session, get) { } RETURN_ZVAL(*ret, 1, 0); - } + } } /* }}} */ @@ -252,7 +252,7 @@ PHP_METHOD(yaf_session, del) { */ PHP_METHOD(yaf_session, has) { char *name; - uint len; + uint len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len) == FAILURE) { return; @@ -317,7 +317,7 @@ PHP_METHOD(yaf_session, valid) { } /* }}} */ -/** {{{ yaf_session_methods +/** {{{ yaf_session_methods */ zend_function_entry yaf_session_methods[] = { PHP_ME(yaf_session, __construct, NULL, ZEND_ACC_CTOR|ZEND_ACC_PRIVATE) @@ -367,7 +367,7 @@ YAF_STARTUP_FUNCTION(session) { zend_declare_property_null(yaf_session_ce, ZEND_STRL(YAF_SESSION_PROPERTY_NAME_INSTANCE), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); zend_declare_property_null(yaf_session_ce, ZEND_STRL(YAF_SESSION_PROPERTY_NAME_SESSION), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_bool(yaf_session_ce, ZEND_STRL(YAF_SESSION_PROPERTY_NAME_STATUS), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - + return SUCCESS; } /* }}} */ diff --git a/yaf_view.c b/yaf_view.c index 73b47c3c..264e6e7f 100644 --- a/yaf_view.c +++ b/yaf_view.c @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_view.c 315615 2011-08-27 14:14:48Z laruence $ */ + +/* $Id: yaf_view.c 321289 2011-12-21 02:53:29Z laruence $ */ #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/yaf_view.h b/yaf_view.h index 16f97f9d..ea1fec36 100644 --- a/yaf_view.h +++ b/yaf_view.h @@ -13,8 +13,8 @@ | Author: Xinchen Hui | +----------------------------------------------------------------------+ */ - -/* $Id: yaf_view.h 315615 2011-08-27 14:14:48Z laruence $ */ + +/* $Id: yaf_view.h 321289 2011-12-21 02:53:29Z laruence $ */ #ifndef YAF_VIEW_H #define YAF_VIEW_H