Esempio n. 1
0
/** {{{ zend_string * yaf_route_simple_assemble(zval *info, zval *query)
 */
zend_string * yaf_route_simple_assemble(yaf_route_t *this_ptr, zval *info, zval *query) {
	smart_str tvalue = {0};
	zval *nmodule, *ncontroller, *naction;

	smart_str_appendc(&tvalue, '?');

	nmodule = zend_read_property(yaf_route_simple_ce,
			this_ptr, ZEND_STRL(YAF_ROUTE_SIMPLE_VAR_NAME_MODULE), 1, NULL);
	ncontroller = zend_read_property(yaf_route_simple_ce,
			this_ptr, ZEND_STRL(YAF_ROUTE_SIMPLE_VAR_NAME_CONTROLLER), 1, NULL);
	naction = zend_read_property(yaf_route_simple_ce,
			this_ptr, ZEND_STRL(YAF_ROUTE_SIMPLE_VAR_NAME_ACTION), 1, NULL);

	do {
		zval *tmp;

		if ((tmp = zend_hash_str_find(Z_ARRVAL_P(info), ZEND_STRL(YAF_ROUTE_ASSEMBLE_MOUDLE_FORMAT))) != NULL) {
			smart_str_appendl(&tvalue, Z_STRVAL_P(nmodule), Z_STRLEN_P(nmodule));
			smart_str_appendc(&tvalue, '=');
			smart_str_appendl(&tvalue, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
			smart_str_appendc(&tvalue, '&');
		} 

		if ((tmp = zend_hash_str_find(Z_ARRVAL_P(info), ZEND_STRL(YAF_ROUTE_ASSEMBLE_CONTROLLER_FORMAT))) == NULL) {
			yaf_trigger_error(YAF_ERR_TYPE_ERROR, "%s", "You need to specify the controller by ':c'");
			break;
		}

		smart_str_appendl(&tvalue, Z_STRVAL_P(ncontroller), Z_STRLEN_P(ncontroller));
		smart_str_appendc(&tvalue, '=');
		smart_str_appendl(&tvalue, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
		smart_str_appendc(&tvalue, '&');

		if ((tmp = zend_hash_str_find(Z_ARRVAL_P(info), ZEND_STRL(YAF_ROUTE_ASSEMBLE_ACTION_FORMAT))) == NULL) {
			yaf_trigger_error(YAF_ERR_TYPE_ERROR, "%s", "You need to specify the action by ':a'");
			break;
		}

		smart_str_appendl(&tvalue, Z_STRVAL_P(naction), Z_STRLEN_P(naction));
		smart_str_appendc(&tvalue, '=');
		smart_str_appendl(&tvalue, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));

		if (query && IS_ARRAY == Z_TYPE_P(query)) {
			zend_string *key;

            ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(query), key, tmp) {
				if (IS_STRING == Z_TYPE_P(tmp) && key) {
					smart_str_appendc(&tvalue, '&');
					smart_str_appendl(&tvalue, ZSTR_VAL(key), ZSTR_LEN(key));
					smart_str_appendc(&tvalue, '=');
					smart_str_appendl(&tvalue, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
				}
			} ZEND_HASH_FOREACH_END();
		}

		smart_str_0(&tvalue);
		return tvalue.s;
	} while (0);
Esempio n. 2
0
zend_class_entry *yaf_dispatcher_get_controller(zend_string *app_dir, zend_string *module, zend_string *controller, int def_module) /* {{{ */ {
	char *directory;
	size_t directory_len;

	if (def_module) {
		directory_len = spprintf(&directory, 0,
				"%s%c%s", ZSTR_VAL(app_dir), DEFAULT_SLASH, YAF_CONTROLLER_DIRECTORY_NAME);
	} else {
		directory_len = spprintf(&directory, 0,
				"%s%c%s%c%s%c%s", ZSTR_VAL(app_dir), DEFAULT_SLASH, YAF_MODULE_DIRECTORY_NAME,
				DEFAULT_SLASH, ZSTR_VAL(module), DEFAULT_SLASH, YAF_CONTROLLER_DIRECTORY_NAME);
	}

	if (EXPECTED(directory_len)) {
		zend_string *class;
		zend_string *class_lowercase;
		zend_class_entry *ce 	= NULL;

		if (YAF_G(name_suffix)) {
			class = strpprintf(0, "%s%s%s", ZSTR_VAL(controller), YAF_G(name_separator), "Controller");
		} else {
			class = strpprintf(0, "%s%s%s", "Controller", YAF_G(name_separator), ZSTR_VAL(controller));
		}

		class_lowercase = zend_string_tolower(class);

		if ((ce = zend_hash_find_ptr(EG(class_table), class_lowercase)) == NULL) {
			if (!yaf_internal_autoload(ZSTR_VAL(controller), ZSTR_LEN(controller), &directory)) {
				yaf_trigger_error(YAF_ERR_NOTFOUND_CONTROLLER,
						"Failed opening controller script %s: %s", directory, strerror(errno));
				zend_string_release(class);
				zend_string_release(class_lowercase);
				efree(directory);
				return NULL;
			} else if ((ce = zend_hash_find_ptr(EG(class_table), class_lowercase)) == NULL)  {
static void HHVM_METHOD(Yaf_Route_Rewrite, __construct, 
        const Variant& match, const Array& route, 
        const Variant& verify)
{
    if (!match.isString() || 
            (match.isString() && match.toString().length() == 0)) {
        yaf_trigger_error(YAF_ERR_TYPE_ERROR, "Yaf_Route_Rewrite, "\
                "Expects a valid string as the first parameter");
        return;
    }

    if (!verify.isNull() && !verify.isArray()) {
        yaf_trigger_error(YAF_ERR_TYPE_ERROR,
                "Yaf_Route_Rewrite, Expects an array as third parameter");
        return;
    }

    (void)yaf_route_rewrite_instance(this_, match, route, verify);
}
Esempio n. 4
0
yaf_config_t *yaf_config_simple_instance(yaf_config_t *this_ptr, zval *values, zval *readonly) /* {{{ */ {
	switch (Z_TYPE_P(values)) {
		case IS_ARRAY:
			if (Z_ISUNDEF_P(this_ptr)) {
				object_init_ex(this_ptr, yaf_config_simple_ce);
			}
			zend_update_property(yaf_config_simple_ce, this_ptr, ZEND_STRL(YAF_CONFIG_PROPERT_NAME), values);
			if (readonly) {
				convert_to_boolean(readonly);
				zend_update_property_bool(yaf_config_simple_ce, this_ptr, ZEND_STRL(YAF_CONFIG_PROPERT_NAME_READONLY), 
						Z_TYPE_P(readonly) == IS_TRUE ? 1 : 0);
			}
			return this_ptr;
		default:
			yaf_trigger_error(YAF_ERR_TYPE_ERROR, "Invalid parameters provided, must be an array");
			return NULL;
	}
}
Esempio n. 5
0
/** {{{ zend_string * yaf_route_map_assemble(zval *info, zval *query)
 */
zend_string * yaf_route_map_assemble(yaf_route_t *this_ptr, zval *info, zval *query) {
	char *seg, *ptrptr, *pname;
	smart_str uri = {0};
	size_t seg_len;
	zend_bool has_delim = 0;
	zval *delim, *ctl_prefer, *zv;

	ctl_prefer = zend_read_property(yaf_route_map_ce, this_ptr, ZEND_STRL(YAF_ROUTE_MAP_VAR_NAME_CTL_PREFER), 1, NULL);
	delim = zend_read_property(yaf_route_map_ce, this_ptr, ZEND_STRL(YAF_ROUTE_MAP_VAR_NAME_DELIMETER), 1, NULL);

	if (IS_STRING == Z_TYPE_P(delim) && Z_STRLEN_P(delim)) {
		has_delim = 1;
	}

	do {
		if (Z_TYPE_P(ctl_prefer) == IS_TRUE) {
			if ((zv = zend_hash_str_find(Z_ARRVAL_P(info),
					ZEND_STRL(YAF_ROUTE_ASSEMBLE_ACTION_FORMAT))) != NULL && Z_TYPE_P(zv) == IS_STRING) {
				pname = estrndup(Z_STRVAL_P(zv), Z_STRLEN_P(zv));
			} else {
				yaf_trigger_error(YAF_ERR_TYPE_ERROR, "%s",
						"Undefined the 'action' parameter for the 1st parameter");
				break;
			}
		} else {
			if ((zv = zend_hash_str_find(Z_ARRVAL_P(info),
					ZEND_STRL(YAF_ROUTE_ASSEMBLE_CONTROLLER_FORMAT))) != NULL && Z_TYPE_P(zv) == IS_STRING) {
				pname = estrndup(Z_STRVAL_P(zv), Z_STRLEN_P(zv));
			} else {
				yaf_trigger_error(YAF_ERR_TYPE_ERROR, "%s",
						"Undefined the 'controller' parameter for the 1st parameter");
				break;
			}
		}

		seg = php_strtok_r(pname, "_", &ptrptr);	
		while (seg) {
			seg_len = strlen(seg);
			if (seg_len) {
				smart_str_appendc(&uri, '/');
				smart_str_appendl(&uri, seg, seg_len);
			}
			seg = php_strtok_r(NULL, "_", &ptrptr);
		}
		efree(pname);

		if (query && IS_ARRAY == Z_TYPE_P(query)) {
			zend_bool start = 1;
			zend_string *key, *val;

			if (has_delim) {
				smart_str_appendc(&uri, '/');
				smart_str_appendl(&uri, Z_STRVAL_P(delim), Z_STRLEN_P(delim));
			}

            ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(query), key, zv) {
				if (key) {
					val = zval_get_string(zv);
					if (has_delim) {
						smart_str_appendc(&uri, '/');
						smart_str_appendl(&uri, ZSTR_VAL(key), ZSTR_LEN(key));
						smart_str_appendc(&uri, '/');
						smart_str_appendl(&uri, ZSTR_VAL(val), ZSTR_LEN(val));
					} else {
						if (start) {
							smart_str_appendc(&uri, '?');
							smart_str_appendl(&uri, ZSTR_VAL(key), ZSTR_LEN(key));
							smart_str_appendc(&uri, '=');
							smart_str_appendl(&uri, ZSTR_VAL(val), ZSTR_LEN(val));
							start = 0;
						} else {
							smart_str_appendc(&uri, '&');
							smart_str_appendl(&uri, ZSTR_VAL(key), ZSTR_LEN(key));
							smart_str_appendc(&uri, '=');
							smart_str_appendl(&uri, ZSTR_VAL(val), ZSTR_LEN(val));
						}
					}
					zend_string_release(val);
				}
			} ZEND_HASH_FOREACH_END();
		}

		smart_str_0(&uri);
		return uri.s;
	} while (0);